You are here

function exclude_node_title_preprocess_field in Exclude Node Title 8

Implements hook_preprocess_field().

File

./exclude_node_title.module, line 149
Primarily Drupal hooks and global API functions to exclude node titles.

Code

function exclude_node_title_preprocess_field(&$vars) {

  /** @var \Drupal\exclude_node_title\ExcludeNodeTitleManagerInterface $exclude_manager */
  $exclude_manager = \Drupal::service('exclude_node_title.manager');
  if (\Drupal::currentUser()
    ->hasPermission('use exclude node title') && $exclude_manager
    ->isSearchExcluded() && $vars['element']['#field_name'] == 'title' && $vars['element']['#object'] instanceof NodeInterface && $exclude_manager
    ->isTitleExcluded($vars['element']['#object'], 'search_result') && $vars['element']['#view_mode'] == 'search_result') {
    foreach ($vars['items'] as &$item) {
      $item['content']['#context']['value'] = '';
    }
  }
}