You are here

public function ExcludeNodeTitleManager::getNodeInfo in Exclude Node Title 8

Helper function to that extracts node information from $param.

Parameters

mixed $param: Can be a NodeInterface object or integer value (nid).

Return value

mixed Returns an array with node id and node type, or FALSE if errors exist.

Overrides ExcludeNodeTitleManagerInterface::getNodeInfo

2 calls to ExcludeNodeTitleManager::getNodeInfo()
ExcludeNodeTitleManager::isTitleExcluded in src/ExcludeNodeTitleManager.php
Tells if node should get hidden or not.
ExcludeNodeTitleManager::preprocessTitle in src/ExcludeNodeTitleManager.php
Remove the title from the variables array.

File

src/ExcludeNodeTitleManager.php, line 99

Class

ExcludeNodeTitleManager
Service class for Exclude Node Title module settings management.

Namespace

Drupal\exclude_node_title

Code

public function getNodeInfo($param) {
  $node_type = NULL;

  // We accept only integer and object.
  if (!is_object($param) && !is_numeric($param)) {
    return FALSE;
  }

  // If numeric, load the node with nid.
  if (is_numeric($param)) {
    $node = $this->entityTypeManager
      ->getStorage('node')
      ->load($param);
  }
  elseif (is_object($param) && $param instanceof NodeInterface) {
    $node = $param;
  }
  if (isset($node) && $node instanceof NodeInterface) {
    $node_type = $node
      ->getType();
  }
  if (!isset($node) || !isset($node_type)) {
    return FALSE;
  }
  return [
    'nid' => $node
      ->id(),
    'node_type' => $node_type,
  ];
}