Update to Drupal 8.1.10. For more information, see https://www.drupal.org/project/drupal/releases/8.1.10
This commit is contained in:
parent
09b113657a
commit
2f563ab520
7 changed files with 151 additions and 12 deletions
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace Drupal\comment;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Field\FieldItemList;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* Defines a item list class for comment fields.
|
||||
|
|
@ -37,4 +39,28 @@ class CommentFieldItemList extends FieldItemList {
|
|||
return parent::offsetExists($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access($operation = 'view', AccountInterface $account = NULL, $return_as_object = FALSE) {
|
||||
if ($operation === 'edit') {
|
||||
// Only users with administer comments permission can edit the comment
|
||||
// status field.
|
||||
$result = AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'administer comments');
|
||||
return $return_as_object ? $result : $result->isAllowed();
|
||||
}
|
||||
if ($operation === 'view') {
|
||||
// Only users with either post comments or access comments permisison can
|
||||
// view the field value. The formatter,
|
||||
// Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter,
|
||||
// takes care of showing the thread and form based on individual
|
||||
// permissions, so if a user only has ‘post comments’ access, only the
|
||||
// form will be shown and not the comments.
|
||||
$result = AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'access comments')
|
||||
->orIf(AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'post comments'));
|
||||
return $return_as_object ? $result : $result->isAllowed();
|
||||
}
|
||||
return parent::access($operation, $account, $return_as_object);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -384,6 +384,7 @@ class CommentNonNodeTest extends WebTestBase {
|
|||
'administer entity_test fields',
|
||||
'view test entity',
|
||||
'administer entity_test content',
|
||||
'administer comments',
|
||||
));
|
||||
$this->drupalLogin($limited_user);
|
||||
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
|
||||
|
|
|
|||
Reference in a new issue