public function CommentFieldItemList::get in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/comment/src/CommentFieldItemList.php \Drupal\comment\CommentFieldItemList::get()
Returns the item at the specified position in this list.
Parameters
int $index: Index of the item to return.
Return value
\Drupal\Core\TypedData\TypedDataInterface|null The item at the specified position in this list, or NULL if no item exists at that position.
Throws
\Drupal\Core\TypedData\Exception\MissingDataException If the complex data structure is unset and no item can be created.
Overrides ItemList::get
File
- core/
modules/ comment/ src/ CommentFieldItemList.php, line 20 - Contains \Drupal\comment\CommentFieldItemList.
Class
- CommentFieldItemList
- Defines a item list class for comment fields.
Namespace
Drupal\commentCode
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);
}