You are here

public function ExampleNodeLabel::view in Extra Field Settings Provider 8

Same name and namespace in other branches
  1. 8.2 modules/extra_field_plus_example/src/Plugin/ExtraField/Display/ExampleNodeLabel.php \Drupal\extra_field_plus_example\Plugin\ExtraField\Display\ExampleNodeLabel::view()

File

modules/extra_field_plus_example/src/Plugin/ExtraField/Display/ExampleNodeLabel.php, line 25

Class

ExampleNodeLabel
Example Extra field Display.

Namespace

Drupal\extra_field_plus_example\Plugin\ExtraField\Display

Code

public function view(ContentEntityInterface $entity) {
  $settings = $this
    ->getSettings();
  $link_to_entity = $settings['link_to_entity'];
  $wrapper = $settings['wrapper'];
  $label = $entity
    ->label();
  $url = NULL;
  if ($link_to_entity) {
    $url = $entity
      ->toUrl()
      ->setAbsolute();
  }
  if ($url) {
    $element = [
      '#type' => 'html_tag',
      '#tag' => $wrapper,
      [
        '#type' => 'link',
        '#title' => $label,
        '#url' => $url,
      ],
    ];
  }
  else {
    $element = [
      '#type' => 'html_tag',
      '#tag' => $wrapper,
      '#value' => $label,
    ];
  }
  return $element;
}