You are here

public static function TypeSettingsStorage::load in Node Accessibility 8

Loads the node accessibility node type settings for a specific type.

If nodeType does not exist or there is an error, then nodeType array key will be set to NULL.

Parameters

string $nodeType: The node type machine name.

Return value

bool TRUE on success, FALSE otherwise.

4 calls to TypeSettingsStorage::load()
node_accessibility_form_node_type_form_alter in ./node_accessibility.module
Implements hook_form_FORM_ID_alter() for the node type form.
TypeSettingsStorage::loadAsArray in src/TypeSettingsStorage.php
Convenience function to return settings as an array.
TypeSettingsStorage::loadByNode in src/TypeSettingsStorage.php
Loads the node accessibility node type settings for a specific node.
TypeSettingsStorage::merge in src/TypeSettingsStorage.php
Insert or Update an entry to the database.

File

src/TypeSettingsStorage.php, line 115

Class

TypeSettingsStorage
Class TypeSettingsStorage.

Namespace

Drupal\node_accessibility

Code

public static function load($nodeType) {
  if (!is_string($nodeType) || empty($nodeType)) {
    return $results;
  }
  $result = new static();
  try {
    $query = \Drupal::database()
      ->select('node_accessibility_type_settings', 'nats');
    $query
      ->fields('nats');
    $query
      ->condition('node_type', $nodeType);
    $existing = $query
      ->execute()
      ->fetchObject();
    if ($existing) {
      if (!empty($existing->node_type)) {
        $result
          ->setNodeType($existing->node_type);
      }
      if (!empty($existing->enabled)) {
        $result
          ->setEnabled($existing->enabled);
      }
      else {
        $result
          ->setEnabled(static::DEFAULT_ENABLED);
      }
      if (!empty($existing->method)) {
        $result
          ->setMethod($existing->method);
      }
      else {
        $result
          ->setMethod(static::DEFAULT_METHOD);
      }
      if (!empty($existing->format_content)) {
        $result
          ->setFormatContent($existing->format_content);
      }
      if (!empty($existing->format_results)) {
        $result
          ->setFormatResults($existing->format_results);
      }
      if (!empty($existing->title_block)) {
        $result
          ->setTitleBlock($existing->title_block);
      }
      if (!empty($existing->standards)) {
        $result
          ->setStandards(json_decode($existing->standards, TRUE));
      }
    }
  } catch (Exception $e) {
    \Drupal::logger('node_accessibility')
      ->error("Failed to select from {node_accessibility_type_settings} table, exception: @exception.", [
      '@exception' => $e
        ->getMessage(),
    ]);
  } catch (Error $e) {
    \Drupal::logger('node_accessibility')
      ->error("Failed to select from {node_accessibility_type_settings} table, exception: @exception.", [
      '@exception' => $e
        ->getMessage(),
    ]);
  }
  return $result;
}