You are here

public function BlockIdFormatter::viewElements in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  2. 8 modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  3. 8.2 modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  4. 8.3 modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  5. 8.4 modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  6. 8.5 modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  7. 8.7 modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  8. 8.8 modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  9. 10.3.x modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  10. 10.0.x modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  11. 10.1.x modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()
  12. 10.2.x modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php \Drupal\social_landing_page\Plugin\Field\FieldFormatter\BlockIdFormatter::viewElements()

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

modules/social_features/social_landing_page/src/Plugin/Field/FieldFormatter/BlockIdFormatter.php, line 92

Class

BlockIdFormatter
Plugin implementation of the 'block_field' formatter.

Namespace

Drupal\social_landing_page\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  foreach ($items as $delta => $item) {

    /** @var \Drupal\block_field\BlockFieldItemInterface $item */
    $block_instance = $item
      ->getBlock();

    // Make sure the block exists and is accessible.
    if (!$block_instance || !$block_instance
      ->access($this->currentUser)) {
      continue;
    }
    $elements[$delta] = [
      '#plain_text' => $block_instance
        ->label() . ' (' . $block_instance
        ->getPluginId() . ')',
    ];

    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $this->renderer
      ->addCacheableDependency($elements[$delta], $block_instance);
  }
  return $elements;
}