diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerBC.php b/core/lib/Drupal/Core/Entity/EntityFormControllerBC.php new file mode 100644 index 0000000..efad954 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerBC.php @@ -0,0 +1,65 @@ +getBCEntity() : $entity; + } + + /** + * Overrides EntityFormControllerNG::buildEntity(). + */ + public function buildEntity(array $form, array &$form_state) { + $entity = clone $this->getEntity($form_state); + $entity_type = $entity->entityType(); + $info = entity_get_info($entity_type); + // @todo Exploit the Field API to process the submitted entity fields. + + // Copy top-level form values that are entity fields but not handled by + // field API without changing existing entity fields that are not being + // edited by this form. Values of fields handled by field API are copied + // by field_attach_extract_form_values() below. + $values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $entity->bundle())) : $form_state['values']; + $translation = $entity->getTranslation($this->getFormLangcode($form_state), FALSE); + $definitions = $translation->getPropertyDefinitions(); + foreach ($values_excluding_fields as $key => $value) { + if (isset($definitions[$key])) { + $translation->$key = $value; + } + elseif ($entity instanceof EntityBCDecorator) { + // Handle yet undefined properties. + // @todo Remove once EntityBCDecorator is removed. + $entity->$key = $value; + } + } + + // Invoke all specified builders for copying form values to entity fields. + if (isset($form['#entity_builders'])) { + foreach ($form['#entity_builders'] as $function) { + call_user_func_array($function, array($entity_type, $entity, &$form, &$form_state)); + } + } + + // Invoke field API for copying field values. + if ($info['fieldable']) { + field_attach_extract_form_values($entity->getBCEntity(), $form, $form_state); + } + return $entity->getBCEntity(); + } +} diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index b964d85..ef9bc89 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -81,11 +81,6 @@ public function buildEntity(array $form, array &$form_state) { if (isset($definitions[$key])) { $translation->$key = $value; } - elseif ($entity instanceof EntityBCDecorator) { - // Handle yet undefined properties. - // @todo Remove once EntityBCDecorator is removed. - $entity->$key = $value; - } } // Invoke all specified builders for copying form values to entity fields. diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 8e39c72..85be9f5 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -10,12 +10,12 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityFormControllerNG; +use Drupal\Core\Entity\EntityFormControllerBC; /** * Form controller for the node edit forms. */ -class NodeFormController extends EntityFormControllerNG { +class NodeFormController extends EntityFormControllerBC { /** * Prepares the node object. @@ -470,20 +470,4 @@ public function delete(array $form, array &$form_state) { $node = $this->getEntity($form_state); $form_state['redirect'] = array('node/' . $node->nid . '/delete', array('query' => $destination)); } - - /** - * Implements \Drupal\Core\Entity\EntityFormControllerInterface::buildEntity(). - */ - public function buildEntity(array $form, array &$form_state) { - return parent::buildEntity($form, $form_state)->getBCEntity(); - } - - /** - * Implements \Drupal\Core\Entity\EntityFormControllerInterface::getEntity(). - */ - public function getEntity(array $form_state) { - $entity = parent::getEntity($form_state); - return isset($entity) ? $entity->getBCEntity() : $entity; - } - } diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityBCDecoratorTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityBCDecoratorTest.php index 0d10dea..b8b596c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityBCDecoratorTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityBCDecoratorTest.php @@ -12,7 +12,7 @@ * * @todo: Remove once the EntityBCDecorator is removed. */ -class EntityBCDecoratorTest extends EntityUnitBaseTest { +class EntityBCDecoratorTest extends EntityUnitTestBase { /** * Modules to enable.