コード例 #1
0
 /**
  * Get the Panels display out of an the entity view display
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity.
  * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
  *   The display.
  * @param $view_mode
  *   The view mode.
  *
  * @return \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant
  *   The Panels display.
  */
 protected function getPanelsDisplay(EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 {
     // First, check if the entity has the panelizer field.
     if (isset($entity->field_panelizer)) {
         $values = [];
         foreach ($entity->field_panelizer as $item) {
             $values[$item->view_mode] = $item->panels_display;
         }
         if (isset($values[$view_mode])) {
             return $this->panelsManager->importDisplay($values[$view_mode]);
         }
     }
     // Otherwise, get the correct default off the entity view display.
     $displays = $display->getThirdPartySetting('panelizer', 'displays', []);
     if (!empty($displays['default'])) {
         $displays['default'] = $this->panelsManager->importDisplay($displays['default']);
     } else {
         $displays['default'] = $this->getPanelizerPlugin()->getDefaultDisplay($display, $entity->bundle(), $view_mode);
     }
     return $displays['default'];
 }