Same filename and directory in other branches
- 8.9.x core/modules/comment/src/CommentFieldItemList.php
- 9 core/modules/comment/src/CommentFieldItemList.php
Namespace
Drupal\comment
File
core/modules/comment/src/CommentFieldItemList.php
View source
<?php
namespace Drupal\comment;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\Session\AccountInterface;
class CommentFieldItemList extends FieldItemList {
public function get($index) {
if ($index == 0 && empty($this->list)) {
$field_default_value = $this
->getFieldDefinition()
->getDefaultValue($this
->getEntity());
return $this
->appendItem($field_default_value[0]);
}
return parent::get($index);
}
public function offsetExists($offset) {
if ($offset === 0) {
return TRUE;
}
return parent::offsetExists($offset);
}
public function access($operation = 'view', AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($operation === 'edit') {
$result = AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'administer comments');
return $return_as_object ? $result : $result
->isAllowed();
}
if ($operation === 'view') {
$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);
}
}
Classes