function CommentFieldItemList::get

Same name in other branches
  1. 8.9.x core/modules/comment/src/CommentFieldItemList.php \Drupal\comment\CommentFieldItemList::get()
  2. 10 core/modules/comment/src/CommentFieldItemList.php \Drupal\comment\CommentFieldItemList::get()
  3. 11.x core/modules/comment/src/CommentFieldItemList.php \Drupal\comment\CommentFieldItemList::get()

Overrides ItemList::get

File

core/modules/comment/src/CommentFieldItemList.php, line 17

Class

CommentFieldItemList
Defines an item list class for comment fields.

Namespace

Drupal\comment

Code

public function get($index) {
    // The Field API only applies the "field default value" to newly created
    // entities. In the specific case of the "comment status", though, we need
    // this default value to be also applied for existing entities created
    // before the comment field was added, which have no value stored for the
    // field.
    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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.