You are here

function show_title_node_view in Show title 2.0.x

Same name and namespace in other branches
  1. 8 show_title.module \show_title_node_view()

Implements hook_ENTITY_TYPE_view().

File

./show_title.module, line 73
Module Show Title.

Code

function show_title_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
  $langcode = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  if ($display
    ->getComponent('show_title')) {

    // Add attributes for quickedit.
    $attributes = [
      'data-quickedit-field-id' => 'node/' . $node
        ->id() . '/title/' . $langcode . '/' . $view_mode,
      'class' => 'field field--name-title-text field--type-string quickedit-field quickedit-candidate quickedit-editable',
    ];
    $build['show_title'] = [
      '#type' => 'markup',
      '#markup' => '<div' . new Attribute($attributes) . '>' . $node
        ->getTitle() . '</div>',
    ];
  }
}