Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
ce17b237
Commit
ce17b237
authored
Aug 15, 2016
by
catch
Browse files
Issue
#2779939
by alexpott: Cleanup the ModerationInformationInterface
parent
1bd3a04d
Changes
17
Hide whitespace changes
Inline
Side-by-side
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
abl
eEntity
(
$node
)
&&
$node
->
moderation_state
&&
$node
->
moderation_state
->
target_id
)
{
elseif
(
$operation
===
'update'
&&
$moderation_info
->
isModerate
d
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
abl
e content entities preSave().
* Operates on moderate
d
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
abl
e.
* Operates on the bundle definition that has been marked as moderate
d
.
*
* 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
abl
eEntity
(
$entity
))
{
if
(
!
$this
->
moderationInfo
->
isModerate
d
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
abl
eEntity
(
$entity
))
{
if
(
!
$this
->
moderationInfo
->
isModerate
d
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
->
is
Moderat
able
EntityType
(
$entity_type
))
{
if
(
!
$this
->
moderationInfo
->
can
Moderat
eEntitiesOf
EntityType
(
$entity_type
))
{
return
[];
}
...
...
@@ -289,7 +299,7 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
}
/**
* Adds
the
ModerationState constraint to bundles
that
are moderat
abl
e.
* Adds ModerationState constraint to bundles
whose entities
are moderate
d
.
*
* @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
->
i
sModerat
able
Bundle
(
$entity_type
,
$bundle
))
{
if
(
!
empty
(
$fields
[
'moderation_state'
])
&&
$this
->
moderationInfo
->
s
hould
Moderat
eEntitiesOf
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
abl
eEntity
(
EntityInterface
$entity
)
{
public
function
isModerate
d
Entity
(
EntityInterface
$entity
)
{
if
(
!
$entity
instanceof
ContentEntityInterface
)
{
return
FALSE
;
}
return
$this
->
i
sModerat
able
Bundle
(
$entity
->
getEntityType
(),
$entity
->
bundle
());
return
$this
->
s
hould
Moderat
eEntitiesOf
Bundle
(
$entity
->
getEntityType
(),
$entity
->
bundle
());
}
/**
* {@inheritdoc}
*/
public
function
is
Moderat
able
EntityType
(
EntityTypeInterface
$entity_type
)
{
public
function
can
Moderat
eEntitiesOf
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
i
sModerat
able
Bundle
(
EntityTypeInterface
$entity_type
,
$bundle
)
{
public
function
s
hould
Moderat
eEntitiesOf
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
abl
eEntity
(
$form_object
->
getEntity
());
&&
$this
->
isModerate
d
Entity
(
$form_object
->
getEntity
());
}
/**
...
...
@@ -191,7 +145,7 @@ public function isLatestRevision(ContentEntityInterface $entity) {
* {@inheritdoc}
*/
public
function
hasForwardRevision
(
ContentEntityInterface
$entity
)
{
return
$this
->
isModerat
abl
eEntity
(
$entity
)
return
$this
->
isModerate
d
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
moderat
ing
.
* Determines if an entity is moderat
ed
.
*
* @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
abl
eEntity
(
EntityInterface
$entity
);
public
function
isModerate
d
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
is
Moderat
able
EntityType
(
EntityTypeInterface
$entity_type
);
public
function
can
Moderat
eEntitiesOf
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
isBundleFor
Moderat
abl
eEntit
y
(
EntityInterface
$entity
);
public
function
should
ModerateEntit
iesOfBundle
(
Entity
Type
Interface
$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
abl
eEntity
(
$entity
)
&&
!
$this
->
moderationInformation
->
isLatestRevision
(
$entity
))
{
if
(
$entity
&&
$this
->
moderationInformation
->
isModerate
d
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
abl
eEntity
(
$entity
))
{
if
(
$entity
&&
$this
->
moderationInfo
->
isModerate
d
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
abl
eEntity
(
$object
))
->
addCacheableDependency
(
$object
));
->
andif
(
AccessResult
::
forbiddenIf
(
$this
->
moderationInfo
->
isModerate
d
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
abl
eEntity
(
$entity
))
{
if
(
$entity
&&
$this
->
moderationInfo
->
isModerate
d
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
abl
eEntity
(
$object
))
->
addCacheableDependency
(
$object
));
->
andif
(
AccessResult
::
forbiddenIf
(
$this
->
moderationInfo
->
isModerate
d
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
$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
());
}
}
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
abl
eEntity
(
$entity
))
{
if
(
!
$this
->
moderationInformation
->
isModerate
d
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
abl
eEntity
(
$this
->
entity
))
{
if
(
!
$this
->
moderationInfo
->
isModerate
d
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
abl
eEntity
(
$entity
))
{
if
(
!
$this
->
moderationInformation
->
isModerate
d
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