summaryrefslogtreecommitdiffstats
path: root/core/modules/content_moderation/src/Entity
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-08-23 11:15:46 (GMT)
committerNathaniel Catchpole2017-08-23 11:15:46 (GMT)
commit22b8c335219d6cb6c16bcad38a06cbdf564f98ae (patch)
tree3422bccbb7ad853048a6ba911a9a1c30c1aad2fa /core/modules/content_moderation/src/Entity
parent98c5df894160db255e8490d7b9dfef19e303e13e (diff)
Issue #2900421 by timmillwood, tim.plunkett, catch, Sam152: Architectural review of the Content Moderation module
Diffstat (limited to 'core/modules/content_moderation/src/Entity')
-rw-r--r--core/modules/content_moderation/src/Entity/ContentModerationState.php5
-rw-r--r--core/modules/content_moderation/src/Entity/ContentModerationStateInterface.php18
-rw-r--r--core/modules/content_moderation/src/Entity/Handler/BlockContentModerationHandler.php2
-rw-r--r--core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php2
-rw-r--r--core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php2
-rw-r--r--core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php2
-rw-r--r--core/modules/content_moderation/src/Entity/Routing/EntityModerationRouteProvider.php123
7 files changed, 151 insertions, 3 deletions
diff --git a/core/modules/content_moderation/src/Entity/ContentModerationState.php b/core/modules/content_moderation/src/Entity/ContentModerationState.php
index 849a5cb..e54fbbe 100644
--- a/core/modules/content_moderation/src/Entity/ContentModerationState.php
+++ b/core/modules/content_moderation/src/Entity/ContentModerationState.php
@@ -2,7 +2,6 @@
namespace Drupal\content_moderation\Entity;
-use Drupal\content_moderation\ContentModerationStateInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
@@ -148,7 +147,7 @@ class ContentModerationState extends ContentEntityBase implements ContentModerat
* @param \Drupal\Core\Entity\EntityInterface $entity
* A moderated entity object.
*
- * @return \Drupal\content_moderation\ContentModerationStateInterface|null
+ * @return \Drupal\content_moderation\Entity\ContentModerationStateInterface|null
* The related content moderation state or NULL if none could be found.
*
* @internal
@@ -172,7 +171,7 @@ class ContentModerationState extends ContentEntityBase implements ContentModerat
->execute();
if ($ids) {
- /** @var \Drupal\content_moderation\ContentModerationStateInterface $content_moderation_state */
+ /** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface $content_moderation_state */
$content_moderation_state = $storage->loadRevision(key($ids));
}
}
diff --git a/core/modules/content_moderation/src/Entity/ContentModerationStateInterface.php b/core/modules/content_moderation/src/Entity/ContentModerationStateInterface.php
new file mode 100644
index 0000000..bd31360
--- /dev/null
+++ b/core/modules/content_moderation/src/Entity/ContentModerationStateInterface.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Drupal\content_moderation\Entity;
+
+use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\user\EntityOwnerInterface;
+
+/**
+ * An interface for Content moderation state entity.
+ *
+ * Content moderation state entities track the moderation state of other content
+ * entities.
+ *
+ * @internal
+ */
+interface ContentModerationStateInterface extends ContentEntityInterface, EntityOwnerInterface {
+
+}
diff --git a/core/modules/content_moderation/src/Entity/Handler/BlockContentModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/BlockContentModerationHandler.php
index b88b415..10c3fc7 100644
--- a/core/modules/content_moderation/src/Entity/Handler/BlockContentModerationHandler.php
+++ b/core/modules/content_moderation/src/Entity/Handler/BlockContentModerationHandler.php
@@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Customizations for block content entities.
+ *
+ * @internal
*/
class BlockContentModerationHandler extends ModerationHandler {
diff --git a/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
index 203022d..f2c6917 100644
--- a/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
+++ b/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
@@ -14,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* Common customizations for most/all entities.
*
* This class is intended primarily as a base class.
+ *
+ * @internal
*/
class ModerationHandler implements ModerationHandlerInterface, EntityHandlerInterface {
diff --git a/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php b/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php
index 976fbb2..7e6f109 100644
--- a/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php
+++ b/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php
@@ -11,6 +11,8 @@ use Drupal\Core\Form\FormStateInterface;
* Much of the logic contained in this handler is an indication of flaws
* in the Entity API that are insufficiently standardized between entity types.
* Hopefully over time functionality can be removed from this interface.
+ *
+ * @internal
*/
interface ModerationHandlerInterface {
diff --git a/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
index 1e1c6f6..7e9aca3 100644
--- a/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
+++ b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
@@ -9,6 +9,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Customizations for node entities.
+ *
+ * @internal
*/
class NodeModerationHandler extends ModerationHandler {
diff --git a/core/modules/content_moderation/src/Entity/Routing/EntityModerationRouteProvider.php b/core/modules/content_moderation/src/Entity/Routing/EntityModerationRouteProvider.php
new file mode 100644
index 0000000..f72a47e
--- /dev/null
+++ b/core/modules/content_moderation/src/Entity/Routing/EntityModerationRouteProvider.php
@@ -0,0 +1,123 @@
+<?php
+
+namespace Drupal\content_moderation\Entity\Routing;
+
+use Drupal\Core\Entity\EntityFieldManagerInterface;
+use Drupal\Core\Entity\EntityHandlerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Entity\FieldableEntityInterface;
+use Drupal\Core\Entity\Routing\EntityRouteProviderInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\Routing\Route;
+use Symfony\Component\Routing\RouteCollection;
+
+/**
+ * Dynamic route provider for the Content moderation module.
+ *
+ * Provides the following routes:
+ * - The latest version tab, showing the latest revision of an entity, not the
+ * default one.
+ *
+ * @internal
+ */
+class EntityModerationRouteProvider implements EntityRouteProviderInterface, EntityHandlerInterface {
+
+ /**
+ * The entity manager.
+ *
+ * @var \Drupal\Core\Entity\EntityFieldManagerInterface
+ */
+ protected $entityFieldManager;
+
+ /**
+ * Constructs a new DefaultHtmlRouteProvider.
+ *
+ * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_manager
+ * The entity manager.
+ */
+ public function __construct(EntityFieldManagerInterface $entity_manager) {
+ $this->entityFieldManager = $entity_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
+ return new static(
+ $container->get('entity_field.manager')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRoutes(EntityTypeInterface $entity_type) {
+ $collection = new RouteCollection();
+
+ if ($moderation_route = $this->getLatestVersionRoute($entity_type)) {
+ $entity_type_id = $entity_type->id();
+ $collection->add("entity.{$entity_type_id}.latest_version", $moderation_route);
+ }
+
+ return $collection;
+ }
+
+ /**
+ * Gets the moderation-form route.
+ *
+ * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
+ * The entity type.
+ *
+ * @return \Symfony\Component\Routing\Route|null
+ * The generated route, if available.
+ */
+ protected function getLatestVersionRoute(EntityTypeInterface $entity_type) {
+ if ($entity_type->hasLinkTemplate('latest-version') && $entity_type->hasViewBuilderClass()) {
+ $entity_type_id = $entity_type->id();
+ $route = new Route($entity_type->getLinkTemplate('latest-version'));
+ $route
+ ->addDefaults([
+ '_entity_view' => "{$entity_type_id}.full",
+ '_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title',
+ ])
+ // If the entity type is a node, unpublished content will be visible
+ // if the user has the "view all unpublished content" permission.
+ ->setRequirement('_entity_access', "{$entity_type_id}.view")
+ ->setRequirement('_content_moderation_latest_version', 'TRUE')
+ ->setOption('_content_moderation_entity_type', $entity_type_id)
+ ->setOption('parameters', [
+ $entity_type_id => [
+ 'type' => 'entity:' . $entity_type_id,
+ 'load_pending_revision' => 1,
+ ],
+ ]);
+
+ // Entity types with serial IDs can specify this in their route
+ // requirements, improving the matching process.
+ if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') {
+ $route->setRequirement($entity_type_id, '\d+');
+ }
+ return $route;
+ }
+ }
+
+ /**
+ * Gets the type of the ID key for a given entity type.
+ *
+ * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
+ * An entity type.
+ *
+ * @return string|null
+ * The type of the ID key for a given entity type, or NULL if the entity
+ * type does not support fields.
+ */
+ protected function getEntityTypeIdKeyType(EntityTypeInterface $entity_type) {
+ if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
+ return NULL;
+ }
+
+ $field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type->id());
+ return $field_storage_definitions[$entity_type->getKey('id')]->getType();
+ }
+
+}