PanelizerNode.php in Panelizer 8.5
File
src/Plugin/PanelizerEntity/PanelizerNode.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;
class PanelizerNode extends PanelizerEntityBase {
public function getDefaultDisplay(EntityViewDisplayInterface $display, $bundle, $view_mode) {
$panels_display = parent::getDefaultDisplay($display, $bundle, $view_mode)
->setPageTitle('[node:title]');
foreach ($panels_display
->getRegionAssignments() as $region => $blocks) {
foreach ($blocks as $block_id => $block) {
if ($block
->getPluginId() == 'entity_field:node:title') {
$panels_display
->removeBlock($block_id);
}
}
}
if ($display
->getComponent('links')) {
}
if ($display
->getComponent('langcode')) {
}
return $panels_display;
}
public function alterBuild(array &$build, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
parent::alterBuild($build, $entity, $panels_display, $view_mode);
if ($entity
->id()) {
$build['#contextual_links']['node'] = [
'route_parameters' => [
'node' => $entity
->id(),
],
'metadata' => [
'changed' => $entity
->getChangedTime(),
],
];
}
}
public function preprocessViewMode(array &$variables, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
parent::preprocessViewMode($variables, $entity, $panels_display, $view_mode);
$node = $entity;
if ($node
->isPromoted()) {
$variables['attributes']['class'][] = 'node--promoted';
}
if ($node
->isSticky()) {
$variables['attributes']['class'][] = 'node--sticky';
}
if (!$node
->isPublished()) {
$variables['attributes']['class'][] = 'node--unpublished';
}
}
}