class PanelizerIPEController in Lightning Workflow 8.3
Same name and namespace in other branches
- 8 src/Controller/PanelizerIPEController.php \Drupal\lightning_workflow\Controller\PanelizerIPEController
- 8.2 src/Controller/PanelizerIPEController.php \Drupal\lightning_workflow\Controller\PanelizerIPEController
Controller for Panels IPE routes that are specific to Panelizer.
@internal This is an internal part of Lightning Workflow's integration with Panelizer and may be changed or removed at any time. External code should not use or extend this class in any way!
Hierarchy
- class \Drupal\lightning_workflow\Controller\PanelizerIPEController extends \Drupal\panelizer\Controller\PanelizerPanelsIPEController
Expanded class hierarchy of PanelizerIPEController
1 file declares its use of PanelizerIPEController
- RouteSubscriber.php in src/
Routing/ RouteSubscriber.php
File
- src/
Controller/ PanelizerIPEController.php, line 21
Namespace
Drupal\lightning_workflow\ControllerView source
class PanelizerIPEController extends PanelizerPanelsIPEController {
/**
* The moderation information service.
*
* @var \Drupal\content_moderation\ModerationInformationInterface
*/
protected $modInfo;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* PanelizerIPEController constructor.
*
* @param \Drupal\panelizer\PanelizerInterface $panelizer
* The Panelizer service.
* @param \Drupal\content_moderation\ModerationInformationInterface $mod_info
* The moderation information service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(PanelizerInterface $panelizer, ModerationInformationInterface $mod_info, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($panelizer);
$this->modInfo = $mod_info;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('panelizer'), $container
->get('content_moderation.moderation_information'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function revertToDefault(FieldableEntityInterface $entity, $view_mode) {
if ($this->modInfo
->isModeratedEntity($entity)) {
$entity = $this
->getLatestRevision($entity
->getEntityTypeId(), $entity
->id());
}
return parent::revertToDefault($entity, $view_mode);
}
/**
* Loads the latest revision of an entity.
*
* This is a shim around ModerationInformationInterface::getLatestRevision(),
* which was replaced by calling methods on the entity storage handler in
* Drupal 8.8.
*
* @param string $entity_type_id
* The entity type ID.
* @param mixed $entity_id
* The entity ID.
*
* @return \Drupal\Core\Entity\EntityInterface
* The latest revision of the entity. If one could not be found, the default
* revision is returned instead.
*/
private function getLatestRevision($entity_type_id, $entity_id) {
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
if ($storage instanceof RevisionableStorageInterface && method_exists($storage, 'getLatestRevisionId')) {
$revision_id = $storage
->getLatestRevisionId($entity_id);
return isset($revision_id) ? $storage
->loadRevision($revision_id) : $storage
->load($entity_id);
}
else {
// Use call_user_func() here because our deprecation testing tools are not
// smart enough to recognize the actual code path that leads here.
return call_user_func([
$this->modInfo,
'getLatestRevision',
], $entity_type_id, $entity_id);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PanelizerIPEController:: |
protected | property | The entity type manager. | |
PanelizerIPEController:: |
protected | property | The moderation information service. | |
PanelizerIPEController:: |
public static | function | ||
PanelizerIPEController:: |
private | function | Loads the latest revision of an entity. | |
PanelizerIPEController:: |
public | function | ||
PanelizerIPEController:: |
public | function | PanelizerIPEController constructor. |