diff --git a/core/lib/Drupal/Core/Entity/ContentEntityFormController.php b/core/lib/Drupal/Core/Entity/ContentEntityFormController.php index 15bc8e8..e3a4d7e 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityFormController.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityFormController.php @@ -65,6 +65,9 @@ public function processForm($element, $form_state, $form) { $form_display = $this->getFormDisplay($form_state); // Assign the weights configured in the form display. + // @todo: Once https://drupal.org/node/1875974 provides the missing API, + // only do it for 'extra fields', since other components have been taken + // care of in EntityViewDisplay::buildMultiple(). foreach ($form_display->getComponents() as $name => $options) { if (isset($element[$name])) { $element[$name]['#weight'] = $options['weight']; diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php index 1e03c13..f2138bb 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -62,7 +62,6 @@ public function form(FieldItemListInterface $items, array &$form, array &$form_s $field_state = array( 'items_count' => count($items), 'array_parents' => array(), - 'constraint_violations' => array(), ); field_form_set_state($parents, $field_name, $form_state, $field_state); } @@ -317,7 +316,6 @@ public function extractFormValues(FieldItemListInterface $items, array $form, ar * {@inheritdoc} */ public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, array &$form_state) { - /** @var \Symfony\Component\Validator\ConstraintViolationListInterface|\Symfony\Component\Validator\ConstraintViolationInterface[] $violations */ $field_name = $this->fieldDefinition->getName(); $field_state = field_form_get_state($form['#parents'], $field_name, $form_state); @@ -358,7 +356,7 @@ public function flagErrors(FieldItemListInterface $items, ConstraintViolationLis $violation->arrayPropertyPath = $property_path; } - /** @var \Symfony\Component\Validator\ConstraintViolationListInterface|\Symfony\Component\Validator\ConstraintViolationInterface[] $delta_violations */ + /** @var \Symfony\Component\Validator\ConstraintViolationInterface[] $delta_violations */ foreach ($violations_by_delta as $delta => $delta_violations) { // Pass violations to the main element: // - if this is a multiple-value widget, @@ -379,9 +377,6 @@ public function flagErrors(FieldItemListInterface $items, ConstraintViolationLis } } } - // Reinitialize the errors list for the next submit. - $field_state['constraint_violations'] = array(); - field_form_set_state($form['#parents'], $field_name, $form_state, $field_state); } } } diff --git a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php index fa0ef53..658c0b2 100644 --- a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php +++ b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php @@ -127,6 +127,8 @@ protected function init(array &$form_state, EntityInterface $entity, $field_name $form_state['entity'] = $entity; $form_state['field_name'] = $field_name; + // Fetch the display used by the form. It is the display for the 'default' + // form mode, with only the current field visible. $display = EntityFormDisplay::collectRenderDisplay($entity, 'default'); foreach ($display->getComponents() as $name => $optipns) { if ($name != $field_name) { @@ -134,7 +136,6 @@ protected function init(array &$form_state, EntityInterface $entity, $field_name } } $form_state['form_display'] = $display; - // @todo Revisit what really needs to be in $form_state... } /** diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php index 2380087..0ed4b1e 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php @@ -51,7 +51,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn * party code to alter the display options held in the display before they are * used to generate render arrays. * - * @param \Drupal\Core\Entity\EntityInterface $entity + * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity for which the form is being built. * @param string $form_mode * The form mode. @@ -62,7 +62,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn * @see entity_get_form_display() * @see hook_entity_form_display_alter() */ - public static function collectRenderDisplay($entity, $form_mode) { + public static function collectRenderDisplay(ContentEntityInterface $entity, $form_mode) { $entity_type = $entity->getEntityTypeId(); $bundle = $entity->bundle(); diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc deleted file mode 100644 index b443b23..0000000 --- a/core/modules/field/field.attach.inc +++ /dev/null @@ -1,155 +0,0 @@ -type. This property can be omitted if the entity type only - * exposes a single bundle (all entities of this type have the same collection - * of fields). This is the case for the 'user' entity type. - * - * @link field_language Field language API @endlink provides information about - * the structure of field objects. - * - * See @link field Field API @endlink for information about the other parts of - * the Field API. - */ - -/** - * Invokes a method on all the fields of a given entity. - * - * @param string $method - * The name of the method to invoke. - * @param callable $target_function - * A function that receives a FieldDefinitionInterface object and returns the - * object on which the method should be invoked. - * @param \Drupal\Core\Entity\EntityInterface $entity - * The fully formed $entity_type entity. - * @param mixed $a - * (optional) A parameter for the invoked method. Defaults to NULL. - * @param mixed $b - * (optional) A parameter for the invoked method. Defaults to NULL. - * @param array $options - * (optional) An associative array of additional options, with the following - * keys: - * - field_name: The name of the field whose operation should be invoked. By - * default, the operation is invoked on all the fields in the entity's - * bundle. - * - * @return array - * An array of returned values. - */ -function field_invoke_method($method, $target_function, EntityInterface $entity, &$a = NULL, &$b = NULL, array $options = array()) { - $entity_type = $entity->getEntityTypeId(); - - // Determine the list of fields to iterate on. - $field_definitions = _field_invoke_get_field_definitions($entity_type, $entity->bundle(), $options); - - // Iterate through the fields and collect results. - $return = array(); - foreach ($field_definitions as $field_definition) { - // Let the function determine the target object on which the method should be - // called. - $target = call_user_func($target_function, $field_definition); - - if (method_exists($target, $method)) { - $items = $entity->get($field_definition->getName()); - $items->filterEmptyItems(); - - $result = $target->$method($items, $a, $b); - - if (isset($result)) { - // For methods with array results, we merge results together. - // For methods with scalar results, we collect results in an array. - if (is_array($result)) { - $return = array_merge($return, $result); - } - else { - $return[] = $result; - } - } - } - } - - return $return; -} - -/** - * Retrieves a list of field definitions to operate on. - * - * Helper for field_invoke_method(). - * - * @param $entity_type - * The entity type. - * @param $bundle - * The bundle name. - * @param $options - * An associative array of options, as provided to field_invoke_method(). Only - * the following keys are considered: - * - deleted - * - field_name - * - field_id - * See field_invoke_method() for details. - * - * @return - * The array of selected field definitions. - */ -function _field_invoke_get_field_definitions($entity_type, $bundle, $options) { - // @todo Replace with \Drupal::entityManager()->getFieldDefinition() after - // [#2047229] lands. - $entity = _field_create_entity_from_ids((object) array('entity_type' => $entity_type, 'bundle' => $bundle, 'entity_id' => NULL)); - $field_definitions = array(); - if (isset($options['field_name'])) { - if ($entity->hasField($options['field_name'])) { - $field_definitions[] = $entity->get($options['field_name'])->getFieldDefinition(); - } - } - else { - foreach ($entity as $items) { - $field_definitions[] = $items->getFieldDefinition(); - } - } - - return $field_definitions; -} - -/** - * @} End of "defgroup field_attach". - */ diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 0c775c8..4cb581c 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -16,7 +16,6 @@ * every page request. */ require_once __DIR__ . '/field.info.inc'; -require_once __DIR__ . '/field.attach.inc'; require_once __DIR__ . '/field.form.inc'; require_once __DIR__ . '/field.purge.inc'; require_once __DIR__ . '/field.deprecated.inc'; diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 0a08e84..9f23dda 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -89,6 +89,7 @@ * existing node, it will already be loaded; see the Loading section above): * - hook_node_prepare_form() (all) * - hook_entity_prepare_form() (all) + * - @todo hook for EntityFormDisplay::buildForm() * - Validating a node during editing form submit (calling * node_form_validate()): * - hook_node_validate() (all)