Chris@0: moderationInformation = $moderation_info; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function applies($definition, $name, Route $route) { Chris@0: return $this->hasPendingRevisionFlag($definition) || $this->isEditFormPage($route); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Determines if the route definition includes a pending revision flag. Chris@0: * Chris@0: * This is a custom flag defined by the Content Moderation module to load Chris@0: * pending revisions rather than the default revision on a given route. Chris@0: * Chris@0: * @param array $definition Chris@0: * The parameter definition provided in the route options. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the pending revision flag is set, FALSE otherwise. Chris@0: */ Chris@0: protected function hasPendingRevisionFlag(array $definition) { Chris@0: return (isset($definition['load_pending_revision']) && $definition['load_pending_revision']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Determines if a given route is the edit-form for an entity. Chris@0: * Chris@0: * @param \Symfony\Component\Routing\Route $route Chris@0: * The route definition. Chris@0: * Chris@0: * @return bool Chris@0: * Returns TRUE if the route is the edit form of an entity, FALSE otherwise. Chris@0: */ Chris@0: protected function isEditFormPage(Route $route) { Chris@0: if ($default = $route->getDefault('_entity_form')) { Chris@0: // If no operation is provided, use 'default'. Chris@0: $default .= '.default'; Chris@0: list($entity_type_id, $operation) = explode('.', $default); Chris@0: if (!$this->entityManager->hasDefinition($entity_type_id)) { Chris@0: return FALSE; Chris@0: } Chris@0: $entity_type = $this->entityManager->getDefinition($entity_type_id); Chris@0: return $operation == 'edit' && $entity_type && $entity_type->isRevisionable(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function convert($value, $definition, $name, array $defaults) { Chris@0: $entity = parent::convert($value, $definition, $name, $defaults); Chris@0: Chris@0: if ($entity && $this->moderationInformation->isModeratedEntity($entity) && !$this->moderationInformation->isLatestRevision($entity)) { Chris@0: $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); Chris@0: $latest_revision = $this->moderationInformation->getLatestRevision($entity_type_id, $value); Chris@0: Chris@0: if ($latest_revision instanceof EntityInterface) { Chris@0: // If the entity type is translatable, ensure we return the proper Chris@0: // translation object for the current context. Chris@0: if ($entity instanceof TranslatableInterface) { Chris@0: $latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, ['operation' => 'entity_upcast']); Chris@0: } Chris@0: $entity = $latest_revision; Chris@0: } Chris@0: } Chris@0: Chris@0: return $entity; Chris@0: } Chris@0: Chris@0: }