Commit ce17b237 authored by catch's avatar catch

Issue #2779939 by alexpott: Cleanup the ModerationInformationInterface

parent 1bd3a04d
......@@ -45,7 +45,8 @@ function _content_moderation_create_entity_type_info() {
return new EntityTypeInfo(
\Drupal::service('string_translation'),
\Drupal::service('content_moderation.moderation_information'),
\Drupal::service('entity_type.manager')
\Drupal::service('entity_type.manager'),
\Drupal::service('current_user')
);
}
......@@ -179,7 +180,7 @@ function content_moderation_node_access(NodeInterface $node, $operation, Account
$access_result->addCacheableDependency($node);
}
elseif ($operation === 'update' && $moderation_info->isModeratableEntity($node) && $node->moderation_state && $node->moderation_state->target_id) {
elseif ($operation === 'update' && $moderation_info->isModeratedEntity($node) && $node->moderation_state && $node->moderation_state->target_id) {
/** @var \Drupal\content_moderation\StateTransitionValidation $transition_validation */
$transition_validation = \Drupal::service('content_moderation.state_transition_validation');
......
......@@ -9,7 +9,7 @@ services:
arguments: ['@entity_type.manager', '@entity.query']
content_moderation.moderation_information:
class: Drupal\content_moderation\ModerationInformation
arguments: ['@entity_type.manager', '@current_user']
arguments: ['@entity_type.manager']
access_check.latest_revision:
class: Drupal\content_moderation\Access\LatestRevisionCheck
arguments: ['@content_moderation.moderation_information']
......
......@@ -16,7 +16,7 @@
interface ModerationHandlerInterface {
/**
* Operates on moderatable content entities preSave().
* Operates on moderated content entities preSave().
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity to modify.
......@@ -28,7 +28,7 @@ interface ModerationHandlerInterface {
public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state);
/**
* Operates on the bundle definition that has been marked as moderatable.
* Operates on the bundle definition that has been marked as moderated.
*
* Note: The values on the EntityModerationForm itself are already saved
* so do not need to be saved here. If any changes are made to the bundle
......
......@@ -96,7 +96,7 @@ protected function getDefaultLoadStateId(ContentEntityInterface $entity) {
* The entity being saved.
*/
public function entityPresave(EntityInterface $entity) {
if (!$this->moderationInfo->isModeratableEntity($entity)) {
if (!$this->moderationInfo->isModeratedEntity($entity)) {
return;
}
if ($entity->moderation_state->target_id) {
......@@ -125,11 +125,10 @@ public function entityPresave(EntityInterface $entity) {
* @see hook_entity_insert()
*/
public function entityInsert(EntityInterface $entity) {
if (!$this->moderationInfo->isModeratableEntity($entity)) {
return;
if ($this->moderationInfo->isModeratedEntity($entity)) {
$this->updateOrCreateFromEntity($entity);
$this->setLatestRevision($entity);
}
$this->updateOrCreateFromEntity($entity);
$this->setLatestRevision($entity);
}
/**
......@@ -141,11 +140,10 @@ public function entityInsert(EntityInterface $entity) {
* @see hook_entity_update()
*/
public function entityUpdate(EntityInterface $entity) {
if (!$this->moderationInfo->isModeratableEntity($entity)) {
return;
if ($this->moderationInfo->isModeratedEntity($entity)) {
$this->updateOrCreateFromEntity($entity);
$this->setLatestRevision($entity);
}
$this->updateOrCreateFromEntity($entity);
$this->setLatestRevision($entity);
}
/**
......@@ -227,7 +225,7 @@ protected function setLatestRevision(EntityInterface $entity) {
* @see EntityFieldManagerInterface::getExtraFields()
*/
public function entityView(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
if (!$this->moderationInfo->isModeratableEntity($entity)) {
if (!$this->moderationInfo->isModeratedEntity($entity)) {
return;
}
if (!$this->moderationInfo->isLatestRevision($entity)) {
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
......@@ -44,6 +45,13 @@ class EntityTypeInfo {
*/
protected $entityTypeManager;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* A keyed array of custom moderation handlers for given entity types.
*
......@@ -66,10 +74,11 @@ class EntityTypeInfo {
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
*/
public function __construct(TranslationInterface $translation, ModerationInformationInterface $moderation_information, EntityTypeManagerInterface $entity_type_manager) {
public function __construct(TranslationInterface $translation, ModerationInformationInterface $moderation_information, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user) {
$this->stringTranslation = $translation;
$this->moderationInfo = $moderation_information;
$this->entityTypeManager = $entity_type_manager;
$this->currentUser = $current_user;
}
/**
......@@ -83,7 +92,7 @@ public function __construct(TranslationInterface $translation, ModerationInforma
* @see hook_entity_type_alter()
*/
public function entityTypeAlter(array &$entity_types) {
foreach ($this->moderationInfo->selectRevisionableEntityTypes($entity_types) as $type_name => $type) {
foreach ($this->filterNonRevisionableEntityTypes($entity_types) as $type_name => $type) {
$entity_types[$type_name] = $this->addModerationToEntityType($type);
$entity_types[$type->get('bundle_of')] = $this->addModerationToEntity($entity_types[$type->get('bundle_of')]);
}
......@@ -169,8 +178,10 @@ protected function addModerationToEntityType(ConfigEntityTypeInterface $type) {
public function entityOperation(EntityInterface $entity) {
$operations = [];
$type = $entity->getEntityType();
if ($this->moderationInfo->isBundleForModeratableEntity($entity)) {
$bundle_of = $type->getBundleOf();
if ($this->currentUser->hasPermission('administer moderation states') && $bundle_of &&
$this->moderationInfo->canModerateEntitiesOfEntityType($this->entityTypeManager->getDefinition($bundle_of))
) {
$operations['manage-moderation'] = [
'title' => t('Manage moderation'),
'weight' => 27,
......@@ -234,9 +245,8 @@ public function entityExtraFieldInfo() {
* - bundle: The machine name of a bundle, such as "page" or "article".
*/
protected function getModeratedBundles() {
$revisionable_types = $this->moderationInfo->selectRevisionableEntityTypes($this->entityTypeManager->getDefinitions());
/** @var ConfigEntityTypeInterface $type */
foreach ($revisionable_types as $type_name => $type) {
foreach ($this->filterNonRevisionableEntityTypes($this->entityTypeManager->getDefinitions()) as $type_name => $type) {
$result = $this->entityTypeManager
->getStorage($type_name)
->getQuery()
......@@ -259,7 +269,7 @@ protected function getModeratedBundles() {
* New fields added by moderation state.
*/
public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
if (!$this->moderationInfo->isModeratableEntityType($entity_type)) {
if (!$this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) {
return [];
}
......@@ -289,7 +299,7 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
}
/**
* Adds the ModerationState constraint to bundles that are moderatable.
* Adds ModerationState constraint to bundles whose entities are moderated.
*
* @param \Drupal\Core\Field\FieldDefinitionInterface[] $fields
* The array of bundle field definitions.
......@@ -301,7 +311,7 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
* @see hook_entity_bundle_field_info_alter();
*/
public function entityBundleFieldInfoAlter(&$fields, EntityTypeInterface $entity_type, $bundle) {
if (!empty($fields['moderation_state']) && $this->moderationInfo->isModeratableBundle($entity_type, $bundle)) {
if (!empty($fields['moderation_state']) && $this->moderationInfo->shouldModerateEntitiesOfBundle($entity_type, $bundle)) {
$fields['moderation_state']->addConstraint('ModerationState', []);
}
}
......@@ -358,4 +368,21 @@ public static function bundleFormRedirect(array &$form, FormStateInterface $form
}
}
/**
* Filters entity type lists to return only revisionable entity types.
*
* @param EntityTypeInterface[] $entity_types
* The master entity type list filter.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityTypeInterface[]
* An array of revisionable entity types which are configuration entities.
*/
protected function filterNonRevisionableEntityTypes(array $entity_types) {
return array_filter($entity_types, function (EntityTypeInterface $type) use ($entity_types) {
return ($type instanceof ConfigEntityTypeInterface)
&& ($bundle_of = $type->get('bundle_of'))
&& $entity_types[$bundle_of]->isRevisionable();
});
}
}
......@@ -2,16 +2,13 @@
namespace Drupal\content_moderation;
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
use Drupal\Core\Entity\BundleEntityFormBase;
use Drupal\Core\Entity\ContentEntityFormInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Session\AccountInterface;
/**
* General service for moderation-related questions about Entity API.
......@@ -25,13 +22,6 @@ class ModerationInformation implements ModerationInformationInterface {
*/
protected $entityTypeManager;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Creates a new ModerationInformation instance.
*
......@@ -40,26 +30,25 @@ class ModerationInformation implements ModerationInformationInterface {
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user) {
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public function isModeratableEntity(EntityInterface $entity) {
public function isModeratedEntity(EntityInterface $entity) {
if (!$entity instanceof ContentEntityInterface) {
return FALSE;
}
return $this->isModeratableBundle($entity->getEntityType(), $entity->bundle());
return $this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle());
}
/**
* {@inheritdoc}
*/
public function isModeratableEntityType(EntityTypeInterface $entity_type) {
public function canModerateEntitiesOfEntityType(EntityTypeInterface $entity_type) {
return $entity_type->hasHandlerClass('moderation');
}
......@@ -75,54 +64,19 @@ public function loadBundleEntity($bundle_entity_type_id, $bundle_id) {
/**
* {@inheritdoc}
*/
public function isModeratableBundle(EntityTypeInterface $entity_type, $bundle) {
public function shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type, $bundle) {
if ($bundle_entity = $this->loadBundleEntity($entity_type->getBundleEntityType(), $bundle)) {
return $bundle_entity->getThirdPartySetting('content_moderation', 'enabled', FALSE);
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function selectRevisionableEntityTypes(array $entity_types) {
return array_filter($entity_types, function (EntityTypeInterface $type) use ($entity_types) {
return ($type instanceof ConfigEntityTypeInterface)
&& ($bundle_of = $type->get('bundle_of'))
&& $entity_types[$bundle_of]->isRevisionable();
});
}
/**
* {@inheritdoc}
*/
public function selectRevisionableEntities(array $entity_types) {
return array_filter($entity_types, function (EntityTypeInterface $type) use ($entity_types) {
return ($type instanceof ContentEntityTypeInterface)
&& $type->isRevisionable()
&& $type->getBundleEntityType();
});
}
/**
* {@inheritdoc}
*/
public function isBundleForModeratableEntity(EntityInterface $entity) {
$type = $entity->getEntityType();
return
$type instanceof ConfigEntityTypeInterface
&& ($bundle_of = $type->get('bundle_of'))
&& $this->entityTypeManager->getDefinition($bundle_of)->isRevisionable()
&& $this->currentUser->hasPermission('administer moderation states');
}
/**
* {@inheritdoc}
*/
public function isModeratedEntityForm(FormInterface $form_object) {
return $form_object instanceof ContentEntityFormInterface
&& $this->isModeratableEntity($form_object->getEntity());
&& $this->isModeratedEntity($form_object->getEntity());
}
/**
......@@ -191,7 +145,7 @@ public function isLatestRevision(ContentEntityInterface $entity) {
* {@inheritdoc}
*/
public function hasForwardRevision(ContentEntityInterface $entity) {
return $this->isModeratableEntity($entity)
return $this->isModeratedEntity($entity)
&& !($this->getLatestRevisionId($entity->getEntityTypeId(), $entity->id()) == $this->getDefaultRevisionId($entity->getEntityTypeId(), $entity->id()));
}
......
......@@ -26,29 +26,29 @@ interface ModerationInformationInterface {
public function loadBundleEntity($bundle_entity_type_id, $bundle_id);
/**
* Determines if an entity is one we should be moderating.
* Determines if an entity is moderated.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity we may be moderating.
*
* @return bool
* TRUE if this is an entity that we should act upon, FALSE otherwise.
* TRUE if this entity is moderated, FALSE otherwise.
*/
public function isModeratableEntity(EntityInterface $entity);
public function isModeratedEntity(EntityInterface $entity);
/**
* Determines if an entity type has been marked as moderatable.
* Determines if an entity type can have moderated entities.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* An entity type object.
*
* @return bool
* TRUE if this entity type has been marked as moderatable, FALSE otherwise.
* TRUE if this entity type can have moderated entities, FALSE otherwise.
*/
public function isModeratableEntityType(EntityTypeInterface $entity_type);
public function canModerateEntitiesOfEntityType(EntityTypeInterface $entity_type);
/**
* Determines if an entity type/bundle is one that will be moderated.
* Determines if an entity type/bundle entities should be moderated.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition to check.
......@@ -56,52 +56,10 @@ public function isModeratableEntityType(EntityTypeInterface $entity_type);
* The bundle to check.
*
* @return bool
* TRUE if this is a bundle we want to moderate, FALSE otherwise.
*/
public function isModeratableBundle(EntityTypeInterface $entity_type, $bundle);
/**
* Filters entity lists to just bundle definitions for revisionable entities.
*
* @param EntityTypeInterface[] $entity_types
* The master entity type list filter.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityTypeInterface[]
* An array of only the config entities we want to modify.
*/
public function selectRevisionableEntityTypes(array $entity_types);
/**
* Filters entity lists to just the definitions for moderatable entities.
*
* An entity type is moderatable only if it is both revisionable and
* bundleable.
*
* @param EntityTypeInterface[] $entity_types
* The master entity type list filter.
*
* @return \Drupal\Core\Entity\ContentEntityTypeInterface[]
* An array of only the content entity definitions we want to modify.
*/
public function selectRevisionableEntities(array $entity_types);
/**
* Determines if config entity is a bundle for entities that may be moderated.
*
* This is the same check as exists in selectRevisionableEntityTypes(), but
* that one cannot use the entity manager due to recursion and this one
* doesn't have the entity list otherwise so must use the entity manager. The
* alternative would be to call getDefinitions() on entityTypeManager and use
* that in a sub-call, but that would be unnecessarily memory intensive.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to check.
*
* @return bool
* TRUE if we want to add a Moderation operation to this entity, FALSE
* TRUE if an entity type/bundle entities should be moderated, FALSE
* otherwise.
*/
public function isBundleForModeratableEntity(EntityInterface $entity);
public function shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type, $bundle);
/**
* Determines if this form is for a moderated entity.
......
......@@ -88,7 +88,7 @@ protected function isEditFormPage(Route $route) {
public function convert($value, $definition, $name, array $defaults) {
$entity = parent::convert($value, $definition, $name, $defaults);
if ($entity && $this->moderationInformation->isModeratableEntity($entity) && !$this->moderationInformation->isLatestRevision($entity)) {
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);
......
......@@ -54,7 +54,7 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public function execute($entity = NULL) {
if ($entity && $this->moderationInfo->isModeratableEntity($entity)) {
if ($entity && $this->moderationInfo->isModeratedEntity($entity)) {
drupal_set_message($this->t('One or more entities were skipped as they are under moderation and may not be directly published or unpublished.'));
return;
}
......@@ -67,7 +67,7 @@ public function execute($entity = NULL) {
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = parent::access($object, $account, TRUE)
->andif(AccessResult::forbiddenIf($this->moderationInfo->isModeratableEntity($object))->addCacheableDependency($object));
->andif(AccessResult::forbiddenIf($this->moderationInfo->isModeratedEntity($object))->addCacheableDependency($object));
return $return_as_object ? $result : $result->isAllowed();
}
......
......@@ -54,7 +54,7 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public function execute($entity = NULL) {
if ($entity && $this->moderationInfo->isModeratableEntity($entity)) {
if ($entity && $this->moderationInfo->isModeratedEntity($entity)) {
drupal_set_message($this->t('One or more entities were skipped as they are under moderation and may not be directly published or unpublished.'));
return;
}
......@@ -67,7 +67,7 @@ public function execute($entity = NULL) {
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = parent::access($object, $account, TRUE)
->andif(AccessResult::forbiddenIf($this->moderationInfo->isModeratableEntity($object))->addCacheableDependency($object));
->andif(AccessResult::forbiddenIf($this->moderationInfo->isModeratedEntity($object))->addCacheableDependency($object));
return $return_as_object ? $result : $result->isAllowed();
}
......
......@@ -76,18 +76,20 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this->moderatableEntityTypeDefinitions() as $entity_type_id => $entity_type) {
$this->derivatives["$entity_type_id.moderation_tab"] = [
'route_name' => "entity.$entity_type_id.moderation",
'title' => $this->t('Manage moderation'),
// @todo - are we sure they all have an edit_form?
'base_route' => "entity.$entity_type_id.edit_form",
'weight' => 30,
] + $base_plugin_definition;
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) {
$this->derivatives["$entity_type_id.moderation_tab"] = [
'route_name' => "entity.$entity_type_id.moderation",
'title' => $this->t('Manage moderation'),
// @todo - are we sure they all have an edit_form?
'base_route' => "entity.$entity_type_id.edit_form",
'weight' => 30,
] + $base_plugin_definition;
}
}
$latest_version_entities = array_filter($this->moderatableEntityDefinitions(), function (EntityTypeInterface $type) {
return $type->hasLinkTemplate('latest-version');
$latest_version_entities = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) {
return $this->moderationInfo->canModerateEntitiesOfEntityType($type) && $type->hasLinkTemplate('latest-version');
});
foreach ($latest_version_entities as $entity_type_id => $entity_type) {
......@@ -102,24 +104,4 @@ public function getDerivativeDefinitions($base_plugin_definition) {
return $this->derivatives;
}
/**
* Returns an array of content entities that are potentially moderatable.
*
* @return EntityTypeInterface[]
* An array of just those entities we care about.
*/
protected function moderatableEntityDefinitions() {
return $this->moderationInfo->selectRevisionableEntities($this->entityTypeManager->getDefinitions());
}
/**
* Returns entity types that represent bundles that can be moderated.
*
* @return EntityTypeInterface[]
* An array of entity types that represent bundles that can be moderated.
*/
protected function moderatableEntityTypeDefinitions() {
return $this->moderationInfo->selectRevisionableEntityTypes($this->entityTypeManager->getDefinitions());
}
}
......@@ -146,7 +146,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
/* @var \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle_entity */
$bundle_entity = $this->entityTypeManager->getStorage($entity->getEntityType()->getBundleEntityType())->load($entity->bundle());
if (!$this->moderationInformation->isModeratableEntity($entity)) {
if (!$this->moderationInformation->isModeratedEntity($entity)) {
// @todo https://www.drupal.org/node/2779933 write a test for this.
return $element + ['#access' => FALSE];
}
......
......@@ -78,7 +78,7 @@ public function getRouteParameters(RouteMatchInterface $route_match) {
* {@inheritdoc}
*/
public function getTitle() {
if (!$this->moderationInfo->isModeratableEntity($this->entity)) {
if (!$this->moderationInfo->isModeratedEntity($this->entity)) {
// Moderation isn't enabled.
return parent::getTitle();
}
......
......@@ -73,7 +73,7 @@ public function validate($value, Constraint $constraint) {
$entity = $value->getEntity();
// Ignore entities that are not subject to moderation anyway.
if (!$this->moderationInformation->isModeratableEntity($entity)) {
if (!$this->moderationInformation->isModeratedEntity($entity)) {
return;
}
......
......@@ -115,8 +115,12 @@ public function getViewsData() {
],
];
$entity_types_with_moderation = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) {
return $this->moderationInformation->canModerateEntitiesOfEntityType($type);
});
// Add a join for each entity type to the content_revision_tracker table.
foreach ($this->moderationInformation->selectRevisionableEntities($this->entityTypeManager->getDefinitions()) as $entity_type_id => $entity_type) {
foreach ($entity_types_with_moderation as $entity_type_id => $entity_type) {
/** @var \Drupal\views\EntityViewsDataInterface $views_data */
// We need the views_data handler in order to get the table name later.
if ($this->entityTypeManager->hasHandler($entity_type_id, 'views_data') && $views_data = $this->entityTypeManager->getHandler($entity_type_id, 'views_data')) {
......@@ -178,7 +182,7 @@ public function getViewsData() {
$content_moderation_state_entity_type = \Drupal::entityTypeManager()->getDefinition('content_moderation_state');
$content_moderation_state_entity_base_table = $content_moderation_state_entity_type->getDataTable() ?: $content_moderation_state_entity_type->getBaseTable();
$content_moderation_state_entity_revision_base_table = $content_moderation_state_entity_type->getRevisionDataTable() ?: $content_moderation_state_entity_type->getRevisionTable();
foreach ($this->moderationInformation->selectRevisionableEntities($this->entityTypeManager->getDefinitions()) as $entity_type_id => $entity_type) {
foreach ($entity_types_with_moderation as $entity_type_id => $entity_type) {
$table = $entity_type->getDataTable() ?: $entity_type->getBaseTable();
$data[$table]['moderation_state'] = [
......@@ -234,8 +238,10 @@ public function getViewsData() {
* @see hook_views_data()
*/
public function alterViewsData(array &$data) {
$revisionable_types = $this->moderationInformation->selectRevisionableEntities($this->entityTypeManager->getDefinitions());
foreach ($revisionable_types as $type) {
$entity_types_with_moderation = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) {
return $this->moderationInformation->canModerateEntitiesOfEntityType($type);
});
foreach ($entity_types_with_moderation as $type) {
$data[$type->getRevisionTable()]['latest_revision'] = [
'title' => t('Is Latest Revision'),
'help' => t('Restrict the view to only revisions that are the latest revision of their entity.'),
......
......@@ -40,7 +40,7 @@ protected function setUp() {
}
/**
* Creates a page node type to test with, ensuring that it's moderatable.
* Creates a page node type to test with, ensuring that it's moderated.
*/
protected function createNodeType() {
$node_type = NodeType::create([
......
......@@ -64,9 +64,9 @@ public function setupModerationEntityManager($status) {
/**
* @dataProvider providerBoolean
* @covers ::isModeratableEntity
* @covers ::isModeratedEntity
*/
public function testIsModeratableEntity($status) {
public function testIsModeratedEntity($status) {
$moderation_information = new ModerationInformation($this->setupModerationEntityManager($status), $this->getUser());
$entity_type = new ContentEntityType([
......@@ -77,13 +77,13 @@ public function testIsModeratableEntity($status) {
$entity->getEntityType()->willReturn($entity_type);
$entity->bundle()->willReturn('test_bundle');
$this->assertEquals($status, $moderation_information->isModeratableEntity($entity->reveal()));
$this->assertEquals($status, $moderation_information->isModeratedEntity($entity->reveal()));
}
/**
* @covers ::isModeratableEntity
* @covers ::isModeratedEntity
*/
public function testIsModeratableEntityForNonBundleEntityType() {
public function testIsModeratedEntityForNonBundleEntityType() {
$entity_type = new ContentEntityType([
'id' => 'test_entity_type',
]);
......@@ -95,14 +95,14 @@ public function testIsModeratableEntityForNonBundleEntityType() {
$entity_type_manager = $this->getEntityTypeManager($entity_storage->reveal());
$moderation_information = new ModerationInformation($entity_type_manager, $this->getUser());
$this->assertEquals(FALSE, $moderation_information->isModeratableEntity($entity->reveal()));
$this->assertEquals(FALSE, $moderation_information->isModeratedEntity($entity->reveal()));
}
/**
* @dataProvider providerBoolean
* @covers ::isModeratableBundle
* @covers ::shouldModerateEntitiesOfBundle
*/
public function testIsModeratableBundle($status) {
public function testShouldModerateEntities($status) {
$entity_type = new ContentEntityType([
'id' => 'test_entity_type',
'bundle_entity_type' => 'entity_test_bundle',
......@@ -110,7 +110,7 @@ public function testIsModeratableBundle($status) {
$moderation_information = new ModerationInformation($this->setupModerationEntityManager($status), $this->getUser());
$this->assertEquals($status, $moderation_information->isModeratableBundle($entity_type, 'test_bundle'));
$this->assertEquals($status, $moderation_information->shouldModerateEntitiesOfBundle($entity_type, 'test_bundle'));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment