diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index 3581cbe..6339c18 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -153,16 +153,16 @@ public function buildForm(ContentEntityInterface $entity, array &$form, FormStat $form += array('#parents' => array()); // Let each widget generate the form elements. - foreach ($entity->getFields() as $field_name => $items) { - if ($widget = $this->getRenderer($field_name)) { + foreach ($entity as $name => $items) { + if ($widget = $this->getRenderer($name)) { $items->filterEmptyItems(); - $form[$field_name] = $widget->form($items, $form, $form_state); - $form[$field_name]['#access'] = $items->access('edit'); + $form[$name] = $widget->form($items, $form, $form_state); + $form[$name]['#access'] = $items->access('edit'); // Assign the correct weight. This duplicates the reordering done in // processForm(), but is needed for other forms calling this method // directly. - $form[$field_name]['#weight'] = $this->getComponent($field_name)['weight']; + $form[$name]['#weight'] = $this->getComponent($name)['weight']; } } diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php index 562b9cc..7e413b0 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php @@ -179,7 +179,6 @@ public function applyDefaultValue($notify = TRUE) { * {@inheritdoc} */ public function getIterator() { - return new \ArrayIterator($this->getProperties()); return isset($this->entity) ? $this->entity->getIterator() : new \ArrayIterator([]); } diff --git a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php index 746eb95..c6743c8 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php @@ -19,15 +19,22 @@ class BundleConstraintValidator extends ConstraintValidator { /** * {@inheritdoc} */ - public function validate($entity, Constraint $constraint) { - if (!isset($entity)) { + public function validate($entity_adapter, Constraint $constraint) { + if (!isset($entity_adapter)) { return; } - // The constraint is used on both entity references and typed data entity - // adapters. For the latter, we need to unwrap the actual entity. - if ($entity instanceof TypedDataInterface) { - $entity = $entity->getValue(); + + // @todo The $entity_adapter parameter passed to this function should always + // be a typed data object, but due to a bug, the unwrapped entity is + // passed for the computed entity property of entity reference fields. + // Remove this after fixing that in https://www.drupal.org/node/2346373. + if (!$entity_adapter instanceof TypedDataInterface) { + $entity = $entity_adapter; + } + else { + $entity = $entity_adapter->getValue(); } + if (!in_array($entity->bundle(), $constraint->getBundleOption())) { $this->context->addViolation($constraint->message, array('%bundle' => implode(', ', $constraint->getBundleOption()))); } diff --git a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php index a74f20d..5138856 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php @@ -19,15 +19,22 @@ class EntityTypeConstraintValidator extends ConstraintValidator { /** * Implements \Symfony\Component\Validator\ConstraintValidatorInterface::validate(). */ - public function validate($entity, Constraint $constraint) { - if (!isset($entity)) { + public function validate($entity_adapter, Constraint $constraint) { + if (!isset($entity_adapter)) { return; } - // The constraint is used on both entity references and typed data entity - // adapters. For the latter, we need to unwrap the actual entity. - if ($entity instanceof TypedDataInterface) { - $entity = $entity->getValue(); + + // @todo The $entity_adapter parameter passed to this function should always + // be a typed data object, but due to a bug, the unwrapped entity is + // passed for the computed entity property of entity reference fields. + // Remove this after fixing that in https://www.drupal.org/node/2346373. + if (!$entity_adapter instanceof TypedDataInterface) { + $entity = $entity_adapter; + } + else { + $entity = $entity_adapter->getValue(); } + /** @var $entity \Drupal\Core\Entity\EntityInterface */ if ($entity->getEntityTypeId() != $constraint->type) { $this->context->addViolation($constraint->message, array('%type' => $constraint->type));