Chris@0: list)) { Chris@0: $field_default_value = $this->getFieldDefinition()->getDefaultValue($this->getEntity()); Chris@0: return $this->appendItem($field_default_value[0]); Chris@0: } Chris@0: return parent::get($index); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function offsetExists($offset) { Chris@0: // For consistency with what happens in get(), we force offsetExists() to Chris@0: // be TRUE for delta 0. Chris@0: if ($offset === 0) { Chris@0: return TRUE; Chris@0: } Chris@0: return parent::offsetExists($offset); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function access($operation = 'view', AccountInterface $account = NULL, $return_as_object = FALSE) { Chris@0: if ($operation === 'edit') { Chris@0: // Only users with administer comments permission can edit the comment Chris@0: // status field. Chris@0: $result = AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'administer comments'); Chris@0: return $return_as_object ? $result : $result->isAllowed(); Chris@0: } Chris@0: if ($operation === 'view') { Chris@17: // Only users with "post comments" or "access comments" permission can Chris@0: // view the field value. The formatter, Chris@0: // Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter, Chris@0: // takes care of showing the thread and form based on individual Chris@0: // permissions, so if a user only has ‘post comments’ access, only the Chris@0: // form will be shown and not the comments. Chris@0: $result = AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'access comments') Chris@0: ->orIf(AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'post comments')); Chris@0: return $return_as_object ? $result : $result->isAllowed(); Chris@0: } Chris@0: return parent::access($operation, $account, $return_as_object); Chris@0: } Chris@0: Chris@0: }