diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 44c3040..8f34416 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -450,8 +450,7 @@ function entity_form_id(EntityInterface $entity, $operation = 'default') { */ function entity_form_state_defaults(EntityInterface $entity, $operation = 'default', $langcode = NULL) { $form_state = array(); - $controller = drupal_container()->get('plugin.manager.entity')->getFormController($entity->entityType(), $operation); - $form_state['build_info']['callback'] = array($controller, 'build'); + $form_state['build_info']['callback_object'] = drupal_container()->get('plugin.manager.entity')->getFormController($entity->entityType(), $operation); $form_state['build_info']['base_form_id'] = $entity->entityType() . '_form'; $form_state['build_info']['args'] = array($entity); $form_state['langcode'] = $langcode; diff --git a/core/includes/form.inc b/core/includes/form.inc index 725bcaf..6b97b45 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -767,7 +767,7 @@ function drupal_retrieve_form($form_id, &$form_state) { $callback = $form_state['build_info']['callback']; } elseif (!empty($form_state['build_info']['callback_object'])) { - $callback = array($form_state['build_info']['callback_object'], 'form'); + $callback = array($form_state['build_info']['callback_object'], 'build'); } // We first check to see if there is a valid form builder callback defined. diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 4a03975..45215a7 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -33,10 +33,17 @@ public function __construct($operation) { } /** - * Implements \Drupal\Core\Entity\EntityFormControllerInterface::build(). + * Implements \Drupal\Core\Form\FormInterface::getFormID(). */ - public function build(array $form, array &$form_state, EntityInterface $entity) { + public function getFormID() { + // Handled by entity_form_id(). + return ''; + } + /** + * Implements \Drupal\Core\Entity\EntityFormControllerInterface::build(). + */ + public function build(array $form, array &$form_state, EntityInterface $entity = NULL) { // During the initial form build, add the entity to the form state for use // during form building and processing. During a rebuild, use what is in the // form state. diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php index 09a06bf..6029e86 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php @@ -7,30 +7,12 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Form\FormInterface; + /** * Defines a common interface for entity form controller classes. */ -interface EntityFormControllerInterface { - - /** - * Builds an entity form. - * - * This is the entity form builder which is invoked via drupal_build_form() - * to retrieve the form. - * - * @param array $form - * A nested array form elements comprising the form. - * @param array $form_state - * An associative array containing the current state of the form. - * @param string $entity_type - * The type of the entity being edited. - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity being edited. - * - * @return array - * The array containing the complete form. - */ - public function build(array $form, array &$form_state, EntityInterface $entity); +interface EntityFormControllerInterface extends FormInterface { /** * Returns the code identifying the active form language. @@ -110,28 +92,4 @@ public function setEntity(EntityInterface $entity, array &$form_state); */ public function buildEntity(array $form, array &$form_state); - /** - * Validates the submitted form values of the entity form. - * - * @param array $form - * A nested array form elements comprising the form. - * @param array $form_state - * An associative array containing the current state of the form. - */ - public function validate(array $form, array &$form_state); - - /** - * Updates the form's entity by processing this submission's values. - * - * Note: Before this can be safely invoked the entity form must have passed - * validation, i.e. only add this as form #submit handler if validation is - * added as well. - * - * @param array $form - * A nested array form elements comprising the form. - * @param array $form_state - * An associative array containing the current state of the form. - */ - public function submit(array $form, array &$form_state); - } diff --git a/core/lib/Drupal/Core/Form/FormInterface.php b/core/lib/Drupal/Core/Form/FormInterface.php index fbcd719..5789dd7 100644 --- a/core/lib/Drupal/Core/Form/FormInterface.php +++ b/core/lib/Drupal/Core/Form/FormInterface.php @@ -31,7 +31,7 @@ public function getFormID(); * @return array * The form structure. */ - public function form(array $form, array &$form_state); + public function build(array $form, array &$form_state); /** * Form validation handler. diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index fe7f934..fb7b868 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -100,11 +100,11 @@ public function getFormID() { } /** - * Implements \Drupal\Core\Form\FormInterface::form(). + * Implements \Drupal\Core\Form\FormInterface::build(). * * Form constructor for the main block administration form. */ - public function form(array $form, array &$form_state) { + public function build(array $form, array &$form_state) { $entities = $this->load(); $form['#attached']['css'][] = drupal_get_path('module', 'block') . '/block.admin.css'; $form['#attached']['library'][] = array('system', 'drupal.tableheader'); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index b4dad56..f3666bc 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -39,9 +39,9 @@ public function getFormID() { } /** - * Overrides \Drupal\field_ui\OverviewBase::form(). + * Implements \Drupal\Core\Form\FormInterface::build(). */ - public function form(array $form, array &$form_state) { + public function build(array $form, array &$form_state) { // Gather type information. $instances = field_info_instances($this->entity_type, $this->bundle); $field_types = field_info_field_types(); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index 5de1a6f..426010e 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -50,9 +50,9 @@ public function getFormID() { } /** - * Overrides \Drupal\field_ui\OverviewBase::form(). + * Implements \Drupal\Core\Form\FormInterface::build(). */ - public function form(array $form, array &$form_state) { + public function build(array $form, array &$form_state) { // When displaying the form, make sure the list of fields is up-to-date. if (empty($form_state['post'])) { field_info_cache_clear(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php index 64c00c4..d3aa385 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php @@ -34,7 +34,7 @@ public static function getInfo() { */ function testFoo() { $this->drupalGet('form-test/object-builder'); - $this->assertText('The FormTestObject::form() method was used for this form.'); + $this->assertText('The FormTestObject::build() method was used for this form.'); $elements = $this->xpath('//form[@id="form-test-form-test-object"]'); $this->assertTrue(!empty($elements), 'The correct form ID was used.'); $this->drupalPost('form-test/object-builder', NULL, t('Save')); diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php index 4a4269c..c57081f 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php @@ -22,10 +22,10 @@ public function getFormID() { } /** - * Implements \Drupal\Core\Form\FormInterface::form(). + * Implements \Drupal\Core\Form\FormInterface::build(). */ - public function form(array $form, array &$form_state) { - $form['element'] = array('#markup' => 'The FormTestObject::form() method was used for this form.'); + public function build(array $form, array &$form_state) { + $form['element'] = array('#markup' => 'The FormTestObject::build() method was used for this form.'); $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array(