Mercurial > hg > isophonics-drupal-site
diff core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php Mon Apr 23 09:46:53 2018 +0100 @@ -2,104 +2,29 @@ namespace Drupal\content_moderation\ParamConverter; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\ParamConverter\EntityConverter; -use Drupal\Core\TypedData\TranslatableInterface; -use Drupal\content_moderation\ModerationInformationInterface; -use Symfony\Component\Routing\Route; /** * Defines a class for making sure the edit-route loads the current draft. + * + * @internal + * This class only exists to provide backwards compatibility with the + * load_pending_revision flag, the predecessor to load_latest_revision. The + * core entity converter now natively loads the latest revision of an entity + * when the load_latest_revision flag is present. This flag is also added + * automatically to all entity forms. */ class EntityRevisionConverter extends EntityConverter { /** - * Moderation information service. - * - * @var \Drupal\content_moderation\ModerationInformationInterface - */ - protected $moderationInformation; - - /** - * EntityRevisionConverter constructor. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager, needed by the parent class. - * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_info - * The moderation info utility service. - */ - public function __construct(EntityManagerInterface $entity_manager, ModerationInformationInterface $moderation_info) { - parent::__construct($entity_manager); - $this->moderationInformation = $moderation_info; - } - - /** - * {@inheritdoc} - */ - public function applies($definition, $name, Route $route) { - return $this->hasPendingRevisionFlag($definition) || $this->isEditFormPage($route); - } - - /** - * Determines if the route definition includes a pending revision flag. - * - * This is a custom flag defined by the Content Moderation module to load - * pending revisions rather than the default revision on a given route. - * - * @param array $definition - * The parameter definition provided in the route options. - * - * @return bool - * TRUE if the pending revision flag is set, FALSE otherwise. - */ - protected function hasPendingRevisionFlag(array $definition) { - return (isset($definition['load_pending_revision']) && $definition['load_pending_revision']); - } - - /** - * Determines if a given route is the edit-form for an entity. - * - * @param \Symfony\Component\Routing\Route $route - * The route definition. - * - * @return bool - * Returns TRUE if the route is the edit form of an entity, FALSE otherwise. - */ - protected function isEditFormPage(Route $route) { - if ($default = $route->getDefault('_entity_form')) { - // If no operation is provided, use 'default'. - $default .= '.default'; - list($entity_type_id, $operation) = explode('.', $default); - if (!$this->entityManager->hasDefinition($entity_type_id)) { - return FALSE; - } - $entity_type = $this->entityManager->getDefinition($entity_type_id); - return $operation == 'edit' && $entity_type && $entity_type->isRevisionable(); - } - } - - /** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { - $entity = parent::convert($value, $definition, $name, $defaults); - - if ($entity && $this->moderationInformation->isModeratedEntity($entity) && !$this->moderationInformation->isLatestRevision($entity)) { - $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); - $latest_revision = $this->moderationInformation->getLatestRevision($entity_type_id, $value); - - if ($latest_revision instanceof EntityInterface) { - // If the entity type is translatable, ensure we return the proper - // translation object for the current context. - if ($entity instanceof TranslatableInterface) { - $latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, ['operation' => 'entity_upcast']); - } - $entity = $latest_revision; - } + if (!empty($definition['load_pending_revision'])) { + @trigger_error('The load_pending_revision flag has been deprecated. You should use load_latest_revision instead.', E_USER_DEPRECATED); + $definition['load_latest_revision'] = TRUE; } - - return $entity; + return parent::convert($value, $definition, $name, $defaults); } }