You are here

public static function TypeSettingsStorage::loadByNodeAsArray in Node Accessibility 8

Convenience function to load settings by node as an array.

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

@see: self::loadByNode()

Parameters

int $nid: The numeric node id.

Return value

array An array of node type settings. This always returns a populated array. On error or invalid data, the default settings are returned.

4 calls to TypeSettingsStorage::loadByNodeAsArray()
ValidateFormBase::buildForm in src/Form/ValidateFormBase.php
Form constructor.
ValidateNode::execute in src/Plugin/Action/ValidateNode.php
Executes the plugin.
ViewAccessCheck::access in src/Access/ViewAccessCheck.php
A custom access check.
ViewAccessCheck::check_node_access in src/Access/ViewAccessCheck.php
A custom access check.

File

src/TypeSettingsStorage.php, line 246

Class

TypeSettingsStorage
Class TypeSettingsStorage.

Namespace

Drupal\node_accessibility

Code

public static function loadByNodeAsArray($nid) {
  $node_type = NULL;
  try {
    $query = \Drupal::database()
      ->select('node', 'n');
    $query
      ->addField('n', 'type', 'node_type');
    $query
      ->condition('n.nid', $nid);
    $existing = $query
      ->execute()
      ->fetchObject();
    if ($existing) {
      $node_type = $existing->node_type;
    }
  } catch (Exception $e) {
    \Drupal::logger('node_accessibility')
      ->error("Failed to select from {node} table, exception: @exception.", [
      '@exception' => $e
        ->getMessage(),
    ]);
  } catch (Error $e) {
    \Drupal::logger('node_accessibility')
      ->error("Failed to select from {node} table, exception: @exception.", [
      '@exception' => $e
        ->getMessage(),
    ]);
  }
  return static::loadAsArray($node_type);
}