diff --git a/core/lib/Drupal/Core/Field/FieldItemList.php b/core/lib/Drupal/Core/Field/FieldItemList.php index 4a034a8..249b59a 100644 --- a/core/lib/Drupal/Core/Field/FieldItemList.php +++ b/core/lib/Drupal/Core/Field/FieldItemList.php @@ -43,11 +43,16 @@ class FieldItemList extends ItemList implements FieldItemListInterface { */ public function __construct(DataDefinitionInterface $definition, $name = NULL, TypedDataInterface $parent = NULL) { parent::__construct($definition, $name, $parent); - // Always initialize one empty item as most times a value for at least one - // item will be present. That way prototypes created by - // \Drupal\Core\TypedData\TypedDataManager::getPropertyInstance() will - // already have this field item ready for use after cloning. - $this->list[0] = $this->createItem(0); + + // Let computed feilds run. + // @todo There's probably an issue with computed fields - there's no way + // isEmpty() / filterEmptyItems() can work reliably on those ? + if ($definition->isComputed() || $definition->getItemDefinition()->isComputed()) { + // @todo be smarter with appendItem() ? + // Should appendItem() check that the item is not empty ? + $item = $this->createItem(0); + $this->list[0] = $item; + } } /** @@ -222,7 +227,7 @@ public function applyDefaultValue($notify = TRUE) { // are valid default values. if (!isset($value) || (is_array($value) && empty($value))) { // Create one field item and apply defaults. - $this->offsetGet(0)->applyDefaultValue(FALSE); +// $this->offsetGet(0)->applyDefaultValue(FALSE); } else { $this->setValue($value, $notify); diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index 3f88b51..73970cd 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -218,7 +218,10 @@ public function form(array $form, array &$form_state) { // Add internal comment properties. $original = $comment->getUntranslated(); foreach (array('cid', 'pid', 'entity_id', 'entity_type', 'field_id', 'uid', 'langcode') as $key) { - $key_name = key($comment->$key->offsetGet(0)->getPropertyDefinitions()); + // @todo No need for an item to get the propertyDefinition after + // https://drupal.org/node/2002134 + $item = $comment->$key->offsetExists(0) ? $comment->$key->offsetGet(0) : $comment->$key->appendItem(); + $key_name = key($item->getPropertyDefinitions()); $form[$key] = array('#type' => 'value', '#value' => $original->$key->{$key_name}); }