You are here

class PanelizerNode in Panelizer 8.5

Same name and namespace in other branches
  1. 8.3 src/Plugin/PanelizerEntity/PanelizerNode.php \Drupal\panelizer\Plugin\PanelizerEntity\PanelizerNode
  2. 8.4 src/Plugin/PanelizerEntity/PanelizerNode.php \Drupal\panelizer\Plugin\PanelizerEntity\PanelizerNode

Panelizer entity plugin for integrating with nodes.

Plugin annotation

@PanelizerEntity("node");

Hierarchy

Expanded class hierarchy of PanelizerNode

File

src/Plugin/PanelizerEntity/PanelizerNode.php, line 15

Namespace

Drupal\panelizer\Plugin\PanelizerEntity
View source
class PanelizerNode extends PanelizerEntityBase {

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

    // Remove the 'title' 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:node:title') {
          $panels_display
            ->removeBlock($block_id);
        }
      }
    }
    if ($display
      ->getComponent('links')) {

      // @todo: add block for node links.
    }
    if ($display
      ->getComponent('langcode')) {

      // @todo: add block for node language.
    }
    return $panels_display;
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function preprocessViewMode(array &$variables, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
    parent::preprocessViewMode($variables, $entity, $panels_display, $view_mode);

    /** @var \Drupal\node\NodeInterface $node */
    $node = $entity;

    // Add node specific CSS classes.
    if ($node
      ->isPromoted()) {
      $variables['attributes']['class'][] = 'node--promoted';
    }
    if ($node
      ->isSticky()) {
      $variables['attributes']['class'][] = 'node--sticky';
    }
    if (!$node
      ->isPublished()) {
      $variables['attributes']['class'][] = 'node--unpublished';
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PanelizerEntityBase::$entityFieldManager protected property
PanelizerEntityBase::$panelsManager protected property
PanelizerEntityBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
PanelizerEntityBase::__construct public function Overrides PluginBase::__construct
PanelizerNode::alterBuild public function Alter the built entity view in an entity specific way before rendering. Overrides PanelizerEntityBase::alterBuild
PanelizerNode::getDefaultDisplay public function Creates a default Panels display from the core Entity display. Overrides PanelizerEntityBase::getDefaultDisplay
PanelizerNode::preprocessViewMode public function Preprocess the variables for the view mode template. Overrides PanelizerEntityBase::preprocessViewMode
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.