You are here

protected function SubscriptionViewBuilder::alterBuild in Mailing List 8

Specific per-entity building.

Parameters

array $build: The render array that is being created.

\Drupal\Core\Entity\EntityInterface $entity: The entity to be prepared.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.

string $view_mode: The view mode that should be used to prepare the entity.

Overrides EntityViewBuilder::alterBuild

File

src/SubscriptionViewBuilder.php, line 17

Class

SubscriptionViewBuilder
View builder handler for subscriptions.

Namespace

Drupal\mailing_list

Code

protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {

  /** @var \Drupal\mailing_list\SubscriptionInterface $entity */
  parent::alterBuild($build, $entity, $display, $view_mode);
  if ($entity
    ->id()) {
    $build['#contextual_links']['subscription'] = [
      'route_parameters' => [
        'subscription' => $entity
          ->id(),
      ],
      'metadata' => [
        'changed' => $entity
          ->getChangedTime(),
      ],
    ];
  }

  // Prevent search engines from indexing subscriptions pages.
  $build['#attached']['html_head'][] = [
    [
      '#tag' => 'meta',
      '#attributes' => [
        'name' => 'robots',
        'content' => 'noindex',
      ],
    ],
    'mailing_list',
  ];
}