You are here

PanelizerTerm.php in Panelizer 8.4

File

src/Plugin/PanelizerEntity/PanelizerTerm.php
View source
<?php

namespace Drupal\panelizer\Plugin\PanelizerEntity;

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\panelizer\Plugin\PanelizerEntityBase;
use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;

/**
 * Panelizer entity plugin for integrating with taxonomy terms.
 *
 * @PanelizerEntity("taxonomy_term")
 */
class PanelizerTerm extends PanelizerEntityBase {

  /**
   * {@inheritdoc}
   */
  public function getDefaultDisplay(EntityViewDisplayInterface $display, $bundle, $view_mode) {
    $panels_display = parent::getDefaultDisplay($display, $bundle, $view_mode)
      ->setPageTitle('[term:name]');

    // Remove the 'name' block because it's covered already.
    foreach ($panels_display
      ->getRegionAssignments() as $region => $blocks) {

      /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
      foreach ($blocks as $block_id => $block) {
        if ($block
          ->getPluginId() == 'entity_field:taxonomy_term:name') {
          $panels_display
            ->removeBlock($block_id);
        }
      }
    }
    return $panels_display;
  }

  /**
   * {@inheritdoc}
   */
  public function alterBuild(array &$build, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {

    /** @var $entity \Drupal\taxonomy\Entity\Term */
    parent::alterBuild($build, $entity, $panels_display, $view_mode);
    if ($entity
      ->id()) {
      $build['#contextual_links']['taxonomy_term'] = [
        'route_parameters' => [
          'taxonomy_term' => $entity
            ->id(),
        ],
        'metadata' => [
          'changed' => $entity
            ->getChangedTime(),
        ],
      ];
    }
  }

}

Classes

Namesort descending Description
PanelizerTerm Panelizer entity plugin for integrating with taxonomy terms.