Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
222
Merge Requests
222
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
ce17b237
Commit
ce17b237
authored
Aug 15, 2016
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2779939
by alexpott: Cleanup the ModerationInformationInterface
parent
1bd3a04d
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
106 additions
and
180 deletions
+106
-180
core/modules/content_moderation/content_moderation.module
core/modules/content_moderation/content_moderation.module
+3
-2
core/modules/content_moderation/content_moderation.services.yml
...odules/content_moderation/content_moderation.services.yml
+1
-1
core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php
...eration/src/Entity/Handler/ModerationHandlerInterface.php
+2
-2
core/modules/content_moderation/src/EntityOperations.php
core/modules/content_moderation/src/EntityOperations.php
+8
-10
core/modules/content_moderation/src/EntityTypeInfo.php
core/modules/content_moderation/src/EntityTypeInfo.php
+36
-9
core/modules/content_moderation/src/ModerationInformation.php
.../modules/content_moderation/src/ModerationInformation.php
+7
-53
core/modules/content_moderation/src/ModerationInformationInterface.php
...content_moderation/src/ModerationInformationInterface.php
+9
-51
core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php
...moderation/src/ParamConverter/EntityRevisionConverter.php
+1
-1
core/modules/content_moderation/src/Plugin/Action/ModerationOptOutPublishNode.php
...eration/src/Plugin/Action/ModerationOptOutPublishNode.php
+2
-2
core/modules/content_moderation/src/Plugin/Action/ModerationOptOutUnpublishNode.php
...ation/src/Plugin/Action/ModerationOptOutUnpublishNode.php
+2
-2
core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php
...nt_moderation/src/Plugin/Derivative/DynamicLocalTasks.php
+12
-30
core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php
...on/src/Plugin/Field/FieldWidget/ModerationStateWidget.php
+1
-1
core/modules/content_moderation/src/Plugin/Menu/EditTab.php
core/modules/content_moderation/src/Plugin/Menu/EditTab.php
+1
-1
core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php
...idation/Constraint/ModerationStateConstraintValidator.php
+1
-1
core/modules/content_moderation/src/ViewsData.php
core/modules/content_moderation/src/ViewsData.php
+10
-4
core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php
...tent_moderation/tests/src/Kernel/EntityOperationsTest.php
+1
-1
core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php
...t_moderation/tests/src/Unit/ModerationInformationTest.php
+9
-9
No files found.
core/modules/content_moderation/content_moderation.module
View file @
ce17b237
...
...
@@ -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
->
isModerat
able
Entity
(
$node
)
&&
$node
->
moderation_state
&&
$node
->
moderation_state
->
target_id
)
{
elseif
(
$operation
===
'update'
&&
$moderation_info
->
isModerat
ed
Entity
(
$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'
);
...
...
core/modules/content_moderation/content_moderation.services.yml
View file @
ce17b237
...
...
@@ -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'
]
...
...
core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php
View file @
ce17b237
...
...
@@ -16,7 +16,7 @@
interface
ModerationHandlerInterface
{
/**
* Operates on moderat
able
content entities preSave().
* Operates on moderat
ed
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 moderat
able
.
* Operates on the bundle definition that has been marked as moderat
ed
.
*
* 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
...
...
core/modules/content_moderation/src/EntityOperations.php
View file @
ce17b237
...
...
@@ -96,7 +96,7 @@ protected function getDefaultLoadStateId(ContentEntityInterface $entity) {
* The entity being saved.
*/
public
function
entityPresave
(
EntityInterface
$entity
)
{
if
(
!
$this
->
moderationInfo
->
isModerat
able
Entity
(
$entity
))
{
if
(
!
$this
->
moderationInfo
->
isModerat
ed
Entity
(
$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
->
isModerat
able
Entity
(
$entity
))
{
if
(
!
$this
->
moderationInfo
->
isModerat
ed
Entity
(
$entity
))
{
return
;
}
if
(
!
$this
->
moderationInfo
->
isLatestRevision
(
$entity
))
{
...
...
core/modules/content_moderation/src/EntityTypeInfo.php
View file @
ce17b237
...
...
@@ -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
->
select
RevisionableEntityTypes
(
$entity_types
)
as
$type_name
=>
$type
)
{
foreach
(
$this
->
filterNon
RevisionableEntityTypes
(
$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
->
isModeratable
EntityType
(
$entity_type
))
{
if
(
!
$this
->
moderationInfo
->
canModerateEntitiesOf
EntityType
(
$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
->
isModeratable
Bundle
(
$entity_type
,
$bundle
))
{
if
(
!
empty
(
$fields
[
'moderation_state'
])
&&
$this
->
moderationInfo
->
shouldModerateEntitiesOf
Bundle
(
$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
();
});
}
}
core/modules/content_moderation/src/ModerationInformation.php
View file @
ce17b237
...
...
@@ -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
isModerat
able
Entity
(
EntityInterface
$entity
)
{
public
function
isModerat
ed
Entity
(
EntityInterface
$entity
)
{
if
(
!
$entity
instanceof
ContentEntityInterface
)
{
return
FALSE
;
}
return
$this
->
isModeratable
Bundle
(
$entity
->
getEntityType
(),
$entity
->
bundle
());
return
$this
->
shouldModerateEntitiesOf
Bundle
(
$entity
->
getEntityType
(),
$entity
->
bundle
());
}
/**
* {@inheritdoc}
*/
public
function
isModeratable
EntityType
(
EntityTypeInterface
$entity_type
)
{
public
function
canModerateEntitiesOf
EntityType
(
EntityTypeInterface
$entity_type
)
{
return
$entity_type
->
hasHandlerClass
(
'moderation'
);
}
...
...
@@ -75,54 +64,19 @@ public function loadBundleEntity($bundle_entity_type_id, $bundle_id) {
/**
* {@inheritdoc}
*/
public
function
isModeratable
Bundle
(
EntityTypeInterface
$entity_type
,
$bundle
)
{
public
function
shouldModerateEntitiesOf
Bundle
(
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
->
isModerat
able
Entity
(
$form_object
->
getEntity
());
&&
$this
->
isModerat
ed
Entity
(
$form_object
->
getEntity
());
}
/**
...
...
@@ -191,7 +145,7 @@ public function isLatestRevision(ContentEntityInterface $entity) {
* {@inheritdoc}
*/
public
function
hasForwardRevision
(
ContentEntityInterface
$entity
)
{
return
$this
->
isModerat
able
Entity
(
$entity
)
return
$this
->
isModerat
ed
Entity
(
$entity
)
&&
!
(
$this
->
getLatestRevisionId
(
$entity
->
getEntityTypeId
(),
$entity
->
id
())
==
$this
->
getDefaultRevisionId
(
$entity
->
getEntityTypeId
(),
$entity
->
id
()));
}
...
...
core/modules/content_moderation/src/ModerationInformationInterface.php
View file @
ce17b237
...
...
@@ -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
isModerat
able
Entity
(
EntityInterface
$entity
);
public
function
isModerat
ed
Entity
(
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
isModeratable
EntityType
(
EntityTypeInterface
$entity_type
);
public
function
canModerateEntitiesOf
EntityType
(
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.
...
...
core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php
View file @
ce17b237
...
...
@@ -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
->
isModerat
able
Entity
(
$entity
)
&&
!
$this
->
moderationInformation
->
isLatestRevision
(
$entity
))
{
if
(
$entity
&&
$this
->
moderationInformation
->
isModerat
ed
Entity
(
$entity
)
&&
!
$this
->
moderationInformation
->
isLatestRevision
(
$entity
))
{
$entity_type_id
=
$this
->
getEntityTypeFromDefaults
(
$definition
,
$name
,
$defaults
);
$latest_revision
=
$this
->
moderationInformation
->
getLatestRevision
(
$entity_type_id
,
$value
);
...
...
core/modules/content_moderation/src/Plugin/Action/ModerationOptOutPublishNode.php
View file @
ce17b237
...
...
@@ -54,7 +54,7 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public
function
execute
(
$entity
=
NULL
)
{
if
(
$entity
&&
$this
->
moderationInfo
->
isModerat
able
Entity
(
$entity
))
{
if
(
$entity
&&
$this
->
moderationInfo
->
isModerat
ed
Entity
(
$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
->
isModerat
able
Entity
(
$object
))
->
addCacheableDependency
(
$object
));
->
andif
(
AccessResult
::
forbiddenIf
(
$this
->
moderationInfo
->
isModerat
ed
Entity
(
$object
))
->
addCacheableDependency
(
$object
));
return
$return_as_object
?
$result
:
$result
->
isAllowed
();
}
...
...
core/modules/content_moderation/src/Plugin/Action/ModerationOptOutUnpublishNode.php
View file @
ce17b237
...
...
@@ -54,7 +54,7 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public
function
execute
(
$entity
=
NULL
)
{
if
(
$entity
&&
$this
->
moderationInfo
->
isModerat
able
Entity
(
$entity
))
{
if
(
$entity
&&
$this
->
moderationInfo
->
isModerat
ed
Entity
(
$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
->
isModerat
able
Entity
(
$object
))
->
addCacheableDependency
(
$object
));
->
andif
(
AccessResult
::
forbiddenIf
(
$this
->
moderationInfo
->
isModerat
ed
Entity
(
$object
))
->
addCacheableDependency
(
$object
));
return
$return_as_object
?
$result
:
$result
->
isAllowed
();
}
...
...
core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php
View file @
ce17b237
...
...
@@ -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
->
moderatableEntity
Definitions
(),
function
(
EntityTypeInterface
$type
)
{
return
$type
->
hasLinkTemplate
(
'latest-version'
);
$latest_version_entities
=
array_filter
(
$this
->
entityTypeManager
->
get
Definitions
(),
function
(
EntityTypeInterface
$type
)
{
return
$t
his
->
moderationInfo
->
canModerateEntitiesOfEntityType
(
$type
)
&&
$t
ype
->
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
());
}
}
core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php
View file @
ce17b237
...
...
@@ -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
->
isModerat
able
Entity
(
$entity
))
{
if
(
!
$this
->
moderationInformation
->
isModerat
ed
Entity
(
$entity
))
{
// @todo https://www.drupal.org/node/2779933 write a test for this.
return
$element
+
[
'#access'
=>
FALSE
];
}
...
...
core/modules/content_moderation/src/Plugin/Menu/EditTab.php
View file @
ce17b237
...
...
@@ -78,7 +78,7 @@ public function getRouteParameters(RouteMatchInterface $route_match) {
* {@inheritdoc}
*/
public
function
getTitle
()
{
if
(
!
$this
->
moderationInfo
->
isModerat
able
Entity
(
$this
->
entity
))
{
if
(
!
$this
->
moderationInfo
->
isModerat
ed
Entity
(
$this
->
entity
))
{
// Moderation isn't enabled.
return
parent
::
getTitle
();
}
...
...
core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php
View file @
ce17b237
...
...
@@ -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
->
isModerat
able
Entity
(
$entity
))
{
if
(
!
$this
->
moderationInformation
->
isModerat
ed
Entity
(
$entity
))
{
return
;
}
...
...
core/modules/content_moderation/src/ViewsData.php
View file @
ce17b237
...
...
@@ -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.'
),
...
...
core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php
View file @
ce17b237
...
...
@@ -40,7 +40,7 @@ protected function setUp() {
}
/**
* Creates a page node type to test with, ensuring that it's moderat
able
.
* Creates a page node type to test with, ensuring that it's moderat
ed
.
*/
protected
function
createNodeType
()
{
$node_type
=
NodeType
::
create
([
...
...
core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php
View file @
ce17b237
...
...
@@ -64,9 +64,9 @@ public function setupModerationEntityManager($status) {