CustomBlockViewBuilder.php 840 Bytes
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\custom_block\CustomBlockViewBuilder.
6 7 8 9 10
 */

namespace Drupal\custom_block;

use Drupal\Core\Entity\EntityInterface;
11
use Drupal\Core\Entity\EntityViewBuilder;
12
use Drupal\entity\Entity\EntityDisplay;
13 14 15 16

/**
 * Render controller for custom blocks.
 */
17
class CustomBlockViewBuilder extends EntityViewBuilder {
18 19

  /**
20
   * {@inheritdoc}
21 22 23 24 25
   */
  protected function alterBuild(array &$build, EntityInterface $entity, EntityDisplay $display, $view_mode, $langcode = NULL) {
    parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
    // Add contextual links for this custom block.
    if (!empty($entity->id->value) && $view_mode == 'full') {
26 27 28
      $build['#contextual_links']['custom_block'] = array(
        'route_parameters' => array('custom_block' => $entity->id()),
      );
29 30 31 32
    }
  }

}