Commit 2dad9ec0 authored by alexpott's avatar alexpott
Browse files

Issue #2821716 by flocondetoile, anish.a, amateescu, Thew: Fatal error when...

Issue #2821716 by flocondetoile, anish.a, amateescu, Thew: Fatal error when viewing node with content moderation enabled if a module which implements hook_node_grants() is enabled
parent 11b40d7d
......@@ -98,7 +98,7 @@ public function convert($value, $definition, $name, array $defaults) {
$latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, ['operation' => 'entity_upcast']);
}
if ($latest_revision->isRevisionTranslationAffected()) {
if ($latest_revision instanceof EntityInterface && $latest_revision->isRevisionTranslationAffected()) {
$entity = $latest_revision;
}
}
......
......@@ -117,7 +117,9 @@ public function validate($value, Constraint $constraint) {
protected function isFirstTimeModeration(EntityInterface $entity) {
$original_entity = $this->moderationInformation->getLatestRevision($entity->getEntityTypeId(), $entity->id());
$original_id = $original_entity->moderation_state;
if ($original_entity) {
$original_id = $original_entity->moderation_state;
}
return !($entity->moderation_state && $original_entity && $original_id);
}
......
......@@ -9,6 +9,37 @@
*/
class NodeAccessTest extends ModerationStateTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'content_moderation',
'block',
'block_content',
'node',
'node_access_test_empty',
];
/**
* Permissions to grant admin user.
*
* @var array
*/
protected $permissions = [
'administer content moderation',
'access administration pages',
'administer content types',
'administer nodes',
'view latest version',
'view any unpublished content',
'access content overview',
'use editorial transition create_new_draft',
'use editorial transition publish',
'bypass node access',
];
/**
* {@inheritdoc}
*/
......@@ -17,6 +48,10 @@ protected function setUp() {
$this->drupalLogin($this->adminUser);
$this->createContentTypeFromUi('Moderated content', 'moderated_content', TRUE);
$this->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content');
// Rebuild permissions because hook_node_grants() is implemented by the
// node_access_test_empty module.
node_access_rebuild();
}
/**
......@@ -38,7 +73,24 @@ public function testPageAccess() {
$edit_path = 'node/' . $node->id() . '/edit';
$latest_path = 'node/' . $node->id() . '/latest';
// Now make a new user and verify that the new user's access is correct.
$user = $this->createUser([
'use editorial transition create_new_draft',
'view latest version',
'view any unpublished content',
]);
$this->drupalLogin($user);
$this->drupalGet($edit_path);
$this->assertResponse(403);
$this->drupalGet($latest_path);
$this->assertResponse(403);
$this->drupalGet($view_path);
$this->assertResponse(200);
// Publish the node.
$this->drupalLogin($this->adminUser);
$this->drupalPostForm($edit_path, [], t('Save and Publish'));
// Ensure access works correctly for anonymous users.
......@@ -58,12 +110,6 @@ public function testPageAccess() {
'title[0][value]' => 'moderated content revised',
], t('Save and Create New Draft'));
// Now make a new user and verify that the new user's access is correct.
$user = $this->createUser([
'use editorial transition create_new_draft',
'view latest version',
'view any unpublished content',
]);
$this->drupalLogin($user);
$this->drupalGet($edit_path);
......
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