You are here

public function ExcludeNodeTitleManager::preprocessTitle in Exclude Node Title 8

Remove the title from the variables array.

Parameters

mixed $vars: Theme function variables.

mixed $node: Can be NodeInterface object or integer id.

string $view_mode: View mode name.

Overrides ExcludeNodeTitleManagerInterface::preprocessTitle

File

src/ExcludeNodeTitleManager.php, line 216

Class

ExcludeNodeTitleManager
Service class for Exclude Node Title module settings management.

Namespace

Drupal\exclude_node_title

Code

public function preprocessTitle(&$vars, $node, $view_mode) {
  if ($this
    ->isTitleExcluded($node, $view_mode)) {
    $node_info = $this
      ->getNodeInfo($node);
    $node_type = $node_info['node_type'];
    switch ($view_mode) {
      case 'nodeform':
        $node_types = $this->bundleInfo
          ->getBundleInfo('node');
        if (!empty($vars['head_title'])) {
          $vars['head_title']['title'] = new TranslatableMarkup('Edit @nodetype', [
            '@nodetype' => $node_types[$node_type]['label'],
          ]);
        }
        elseif (!empty($vars['title'])) {
          $vars['title'] = new TranslatableMarkup('Edit @nodetype', [
            '@nodetype' => $node_types[$node_type]['label'],
          ]);
        }
        break;
      default:
        if (!empty($vars['title'])) {
          if ($this
            ->isRenderHidden()) {
            $vars['title_attributes']['class'][] = 'hidden';
          }
          elseif ($this
            ->isRenderRemove()) {
            $vars['title'] = new HtmlEscapedText('');
          }
        }
        if (!empty($vars['page']) && is_array($vars['page'])) {
          if ($this
            ->isRenderHidden()) {
            $vars['page']['#attributes']['class'][] = 'hidden';
          }
          elseif ($this
            ->isRenderRemove()) {
            $vars['page']['#title'] = new HtmlEscapedText('');
          }
        }
        if (!empty($vars['elements']) && is_array($vars['elements'])) {
          if ($this
            ->isRenderHidden()) {
            $vars['elements']['#attributes']['class'][] = 'hidden';
          }
          elseif ($this
            ->isRenderRemove()) {
            $vars['elements']['#title'] = new HtmlEscapedText('');
          }
        }
        if (!empty($vars['label']) && is_array($vars['elements'])) {
          if ($this
            ->isRenderHidden()) {
            $vars['label']['#attributes']['class'][] = 'hidden';
          }
          elseif ($this
            ->isRenderRemove()) {
            $vars['label']['#title'] = new HtmlEscapedText('');
            $vars['label']['#markup'] = new HtmlEscapedText('');
            $vars['label'][0]['#context']['value'] = '';
          }
        }
        break;
    }
  }
  return $this;
}