public function ContributorName::appendItem in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x modules/bibcite_entity/src/ContributorName.php \Drupal\bibcite_entity\ContributorName::appendItem()
Appends a new item to the list.
Parameters
mixed $value: The value of the new item.
Return value
\Drupal\Core\TypedData\TypedDataInterface The item that was appended.
Overrides ComputedItemListTrait::appendItem
File
- modules/
bibcite_entity/ src/ ContributorName.php, line 75
Class
- ContributorName
- Contributor name computed field.
Namespace
Drupal\bibcite_entityCode
public function appendItem($value = NULL) {
// Without this, the name field cannot be set via REST, it fails with
// "Unprocessable Entity: validation failed. name: Name: this field cannot
// hold more than 1 values." error.
// There was similar issue with content moderation state computed field in
// Drupal core, though the way it was fixed doesn't seem to be applicable
// in our case.
// We also do not care about handling offset other than 0 here, because it's
// a single-value field.
/* @see https://www.drupal.org/node/2943899 */
/* @see \Drupal\serialization\Normalizer\FieldNormalizer::denormalize */
/* @see \Drupal\Core\TypedData\ComputedItemListTrait::appendItem */
/* @see \Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList */
$item = $this
->createItem(0, $value);
$this->list[0] = $item;
return $item;
}