diff --git a/core/includes/form.inc b/core/includes/form.inc index c94bc62..dc744c7 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -763,7 +763,14 @@ function drupal_retrieve_form($form_id, &$form_state) { } if (isset($form_definition['callback'])) { $callback = $form_definition['callback']; - $form_state['build_info']['base_form_id'] = $callback; + if (empty($form_definition['base_form_ids'])) { + $form_definition['base_form_ids'] = array($callback); + } + // The most specific base form id will be used as the main one. + $form_state['build_info']['base_form_id'] = end($form_definition['base_form_ids']); + // Store the additional base form ids to allow for more generic or + // granular form altering. + $form_state['build_info']['base_form_ids'] = $form_definition['base_form_ids']; } // In case $form_state['wrapper_callback'] is not defined already, we also // allow hook_forms() to define one. @@ -1082,8 +1089,10 @@ function drupal_prepare_form($form_id, &$form, &$form_state) { // Invoke hook_form_alter(), hook_form_BASE_FORM_ID_alter(), and // hook_form_FORM_ID_alter() implementations. $hooks = array('form'); - if (isset($form_state['build_info']['base_form_id'])) { - $hooks[] = 'form_' . $form_state['build_info']['base_form_id']; + if (isset($form_state['build_info']['base_form_ids'])) { + foreach ($form_state['build_info']['base_form_ids'] as $base_form_id) { + $hooks[] = 'form_' . $base_form_id; + } } $hooks[] = 'form_' . $form_id; drupal_alter($hooks, $form, $form_state, $form_id); @@ -1462,7 +1471,7 @@ function form_execute_handlers($type, &$form, &$form_state) { $batch['has_form_submits'] = TRUE; } else { - $function($form, $form_state); + call_user_func_array($function, array($form, &$form_state)); } $return = TRUE; } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 58ea4a6..1e953b0 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -102,8 +102,11 @@ function comment_entity_info() { 'base table' => 'comment', 'uri callback' => 'comment_uri', 'fieldable' => TRUE, - 'controller class' => 'Drupal\comment\CommentStorageController', 'entity class' => 'Drupal\comment\Comment', + 'controller class' => 'Drupal\comment\CommentStorageController', + 'form controller class' => array( + 'default' => 'Drupal\comment\CommentFormController', + ), 'entity keys' => array( 'id' => 'cid', 'bundle' => 'node_type', @@ -764,8 +767,7 @@ function comment_node_page_additions(Node $node) { // Append comment form if needed. if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) { - $comment = entity_create('comment', array('nid' => $node->nid)); - $additions['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", $comment); + $additions['comment_form'] = comment_edit($node); } if ($additions) { @@ -781,6 +783,14 @@ function comment_node_page_additions(Node $node) { } /** + * Returns a rendered form to comment the given node. + */ +function comment_edit($node, $pid = NULL) { + $values = array('nid' => $node->nid, 'pid' => $pid, 'node_type' => 'comment_node_' . $node->type); + return entity_create('comment', $values)->edit(); +} + +/** * Retrieves comments for a thread. * * @param Drupal\node\Node $node @@ -1649,19 +1659,7 @@ function comment_get_display_page($cid, $node_type) { */ function comment_edit_page(Comment $comment) { drupal_set_title(t('Edit comment %comment', array('%comment' => $comment->subject)), PASS_THROUGH); - $node = node_load($comment->nid); - return drupal_get_form("comment_node_{$node->type}_form", $comment); -} - -/** - * Implements hook_forms(). - */ -function comment_forms() { - $forms = array(); - foreach (node_type_get_types() as $type) { - $forms["comment_node_{$type->type}_form"]['callback'] = 'comment_form'; - } - return $forms; + return $comment->edit(); } /** @@ -1862,7 +1860,6 @@ function comment_form($form, &$form_state, Comment $comment) { // Attach fields. $comment->node_type = 'comment_node_' . $node->type; - field_attach_form('comment', $comment, $form, $form_state); return $form; } @@ -1945,8 +1942,6 @@ function comment_preview(Comment $comment) { function comment_form_validate($form, &$form_state) { global $user; - entity_form_field_validate('comment', $form, $form_state); - if (!empty($form_state['values']['cid'])) { // Verify the name in case it is being changed from being anonymous. $account = user_load_by_name($form_state['values']['name']); diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index 0832eff..9387e1a 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -37,8 +37,7 @@ function comment_reply(Node $node, $pid = NULL) { // The user is previewing a comment prior to submitting it. if ($op == t('Preview')) { if (user_access('post comments')) { - $comment = entity_create('comment', array('nid' => $node->nid, 'pid' => $pid)); - $build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", $comment); + $build['comment_form'] = comment_edit($node, $pid); } else { drupal_set_message(t('You are not authorized to post comments.'), 'error'); @@ -86,8 +85,7 @@ function comment_reply(Node $node, $pid = NULL) { drupal_goto("node/$node->nid"); } elseif (user_access('post comments')) { - $comment = entity_create('comment', array('nid' => $node->nid, 'pid' => $pid)); - $build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", $comment); + $build['comment_form'] = comment_edit($node, $pid); } else { drupal_set_message(t('You are not authorized to post comments.'), 'error'); diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php new file mode 100644 index 0000000..b6d1692 --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -0,0 +1,42 @@ + array( 'label' => t('Node'), 'controller class' => 'NodeController', + 'form controller' => array( + 'default' => '\\Drupal\\Module\\Node\\FormController', + ), 'base table' => 'node', 'revision table' => 'node_revision', 'uri callback' => 'node_uri', diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index c167bd4..6741642 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -5,6 +5,7 @@ * Entity API for handling entities like nodes or users. */ +use Drupal\entity\EntityInterface; use Drupal\entity\EntityMalformedException; /** @@ -453,6 +454,109 @@ function entity_form_field_validate($entity_type, $form, &$form_state) { } /** + * Returns a form controller for the given context. + * + * Since there might be different contexts in which an entity or parts of it are + * edited, multiple form controllers suitable to the different contexts may be + * defined. If no valid controller is found for the given context the default + * one will be used. + * + * @param $entity_type + * The type of the entity. + * @param $context + * (optional) The name of the context identifying the form controller. + * + * @return Drupal\entity\EntityFormController + * An instance of the Drupal\Core\Entity\FormController class. + */ +function entity_get_form_controller($entity_type, $context = 'default') { + $info = entity_get_info($entity_type); + + // If no controller is specified default to the base implementation. + if (!empty($info) && empty($info['form controller class'])) { + $class = 'Drupal\entity\EntityFormController'; + } + // If a non-existing context has been specified stop. + elseif (empty($info['form controller class'][$context])) { + // @todo Here we should throw an exception. + return FALSE; + } + else { + $class = $info['form controller class'][$context]; + } + + return new $class($context); +} + +/** + * Helper function. Returns the form id for the given entity. + */ +function _entity_form_id(EntityInterface $entity) { + $entity_type = $entity->entityType(); + $bundle = $entity->bundle(); + $form_id = $entity_type . '_form'; + if ($bundle != $entity_type) { + $form_id = $bundle . '_' . $form_id; + } + return $form_id; +} + +/** + * Returns a rendered edit form for the given entity and context. + * + * @param EntityInterface|string $entity + * The entity being edited or the entity type to be created. + * @param $context + * (optional) The context for the form to be returned. + * + * @return + * A rendered edit form for the given entity. + */ +function entity_edit($entity, $context = 'default') { + if (is_string($entity)) { + $entity = entity_create($entity, array()); + } + $form_id = _entity_form_id($entity); + return drupal_get_form($form_id, $entity, $context); +} + +/** + * Implements hook_forms(). + * + * Returns the generic 'entity_form' callback and defines the additional + * ENTITY_TYPE_form base id to allow for both generic and entity-specific form + * alterations. This we have three levels of granularity: bundle, entity type, + * all. + */ +function entity_forms($form_id, $args) { + $forms = array(); + + if (!empty($args) && $args[0] instanceof EntityInterface) { + try { + $entity = $args[0]; + if ($form_id == _entity_form_id($entity)) { + $callback = 'entity_form'; + $forms[$form_id]['callback'] = $callback; + $forms[$form_id]['base_form_ids'] = array($callback, $entity->entityType() . '_form'); + } + } + catch (EntityMalformedException $e) { + // Not an entity form, exit silently. + } + } + + return $forms; +} + +/** + * Form builder for any edit form. + */ +function entity_form($form, &$form_state, EntityInterface $entity, $context) { + $controller = entity_get_form_controller($entity->entityType(), $context); + return $controller->build($form, $form_state, $entity); +} + +/** * Copies submitted values to entity properties for simple entity forms. * * During the submission handling of an entity form's "Save", "Preview", and diff --git a/core/modules/entity/lib/Drupal/entity/Entity.php b/core/modules/entity/lib/Drupal/entity/Entity.php index f0f5a76..6b6a7f0 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity.php +++ b/core/modules/entity/lib/Drupal/entity/Entity.php @@ -249,4 +249,14 @@ class Entity implements EntityInterface { public function entityInfo() { return entity_get_info($this->entityType); } + + /** + * Implements EntityInterface::edit(). + * + * @param $context + * (optional) The context for the form to be returned. + */ + public function edit($context = 'default') { + return entity_edit($this, $context); + } } diff --git a/core/modules/entity/lib/Drupal/entity/EntityFormController.php b/core/modules/entity/lib/Drupal/entity/EntityFormController.php new file mode 100644 index 0000000..8f7b906 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/EntityFormController.php @@ -0,0 +1,169 @@ +context = $context; + } + + /** + * Builds an entity edit form. + * + * @param $form + * An associative array containing the structure of the form. + * @param $form_state + * A reference to a keyed array containing the current state of the form. + * @param $entity_type + * The type of the entity being edited. + * @param $entity + * The entity being edited. + * + * @return + * The array containing the complete form. + */ + public final function build(array $form, array &$form_state, EntityInterface $entity) { + EntityFormController::setEntity($form_state, $entity); + EntityFormController::setFormInstance($form_state, $this); + + $form = $this->form($form, $form_state, $entity); + + $form['#validate'][] = array($this, 'validate'); + $form['#submit'][] = array($this, 'submit'); + + return $form; + } + + /** + * Returns the actual form array to be built. + * + * @see FormController::build(). + */ + protected function form(array $form, array &$form_state, EntityInterface $entity) { + // @todo Exploit the Property API to generate the default widgets for the + // entity properties. + $info = $entity->entityInfo(); + if (!empty($info['fieldable'])) { + field_attach_form($entity->entityType(), $entity, $form, $form_state, $this->getFormLangcode($form_state)); + } + return $form; + } + + /** + * Validates the submitted form values. + * + * @param $form + * An associative array containing the structure of the form. + * @param $form_state + * A reference to a keyed array containing the current state of the form. + */ + public function validate(array $form, array &$form_state) { + // @todo Exploit the Property API to validate the values submitted for the + // entity properties. + $entity = EntityFormController::getEntity($form_state); + $info = $entity->entityInfo(); + if (!empty($info['fieldable'])) { + entity_form_field_validate($entity->entityType(), $form, $form_state); + } + } + + /** + * Processes the submitted form values. + * + * @param $form + * An associative array containing the structure of the form. + * @param $form_state + * A reference to a keyed array containing the current state of the form. + */ + public function submit(array $form, array &$form_state) { + // @todo Exploit the Property API to process the values submitted for the + // entity properties. + $entity = EntityFormController::getEntity($form_state); + entity_form_submit_build_entity($entity->entityType(), $entity, $form, $form_state); + EntityFormController::setEntity($form_state, $entity); + } + + /** + * Returns the code identifying the active form language. + */ + public function getFormLangcode($form_state) { + // @todo Introduce a new language type to use as the default language. + $language = EntityFormController::getEntity($form_state)->language(); + return !empty($language->langcode) ? $language->langcode : NULL; + } + + /** + * Returns the entity being edited. + * + * @param $form_state + * The current form state. + * + * @return Drupal\entity\Entity + * The entity being edited in the current form. + */ + public static final function getEntity($form_state) { + return isset($form_state['entity']) ? $form_state['entity'] : FALSE; + } + + /** + * Stores the entity being edited. + * + * @param $form_state + * The current form state. + * @param EntityInterface $entity + * The entity being edited in the current form. + */ + protected static final function setEntity(&$form_state, EntityInterface $entity) { + return $form_state['entity'] = $entity; + } + + /** + * Returns an instance of the entity form controller. + * + * @param $form_state + * The current form state. + * @return Drupal\entity\EntityFormController + * An instance of the entity form controller associated with the current + * form. + */ + protected static final function getFormInstance($form_state) { + return isset($form_state['entity_form_controller']) ? $form_state['entity_form_controller'] : FALSE; + } + + /** + * Associates the current form controller to the form being edited. + * + * @param $form_state + * The current form state. + * @param EntityFormController $controller + * The current entity form controller. + */ + protected static final function setFormInstance(&$form_state, EntityFormController $controller) { + $form_state['entity_form_controller'] = $controller; + } +} diff --git a/core/modules/entity/lib/Drupal/entity/EntityInterface.php b/core/modules/entity/lib/Drupal/entity/EntityInterface.php index c4c44c2..619e331 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityInterface.php +++ b/core/modules/entity/lib/Drupal/entity/EntityInterface.php @@ -182,4 +182,11 @@ interface EntityInterface { * @see entity_get_info() */ public function entityInfo(); + + /** + * Returns a rendered entity edit form. + * + * @param $context + */ + public function edit($context = 'default'); } diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php new file mode 100644 index 0000000..ffdf8e0 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -0,0 +1,42 @@ + array( 'label' => t('Node'), - 'controller class' => 'Drupal\node\NodeStorageController', 'entity class' => 'Drupal\node\Node', + 'controller class' => 'Drupal\node\NodeStorageController', + 'form controller class' => array( + 'default' => 'Drupal\node\NodeFormController', + ), 'base table' => 'node', 'revision table' => 'node_revision', 'uri callback' => 'node_uri', @@ -3532,21 +3535,6 @@ function node_content_form(Node $node, $form_state) { */ /** - * Implements hook_forms(). - * - * All node forms share the same form handler. - */ -function node_forms() { - $forms = array(); - if ($types = node_type_get_types()) { - foreach (array_keys($types) as $type) { - $forms[$type . '_node_form']['callback'] = 'node_form'; - } - } - return $forms; -} - -/** * Implements hook_action_info(). */ function node_action_info() { diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index a43ff62..8068cab 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -19,7 +19,7 @@ use Drupal\node\Node; function node_page_edit($node) { $type_name = node_type_get_name($node); drupal_set_title(t('Edit @type @title', array('@type' => $type_name, '@title' => $node->title)), PASS_THROUGH); - return drupal_get_form($node->type . '_node_form', $node); + return $node->edit(); } /** @@ -94,7 +94,7 @@ function node_add($type) { 'langcode' => LANGUAGE_NOT_SPECIFIED, )); drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)), PASS_THROUGH); - $output = drupal_get_form($type . '_node_form', $node); + $output = $node->edit(); return $output; } @@ -116,7 +116,6 @@ function node_form_validate($form, &$form_state) { $node->{$key} = $value; } node_validate($node, $form, $form_state); - entity_form_field_validate('node', $form, $form_state); } /** @@ -334,7 +333,8 @@ function node_form($form, &$form_state, Node $node) { '#access' => variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['node_preview'])), '#value' => t('Save'), '#weight' => 5, - '#submit' => array('node_form_submit'), +// TODO +// '#submit' => array('node_form_submit'), ); $form['actions']['preview'] = array( '#access' => variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED, @@ -357,13 +357,13 @@ function node_form($form, &$form_state, Node $node) { // node_form_submit() as submit handler, but that is the button-level #submit // handler for the 'Save' action. To maintain backwards compatibility, a // #submit handler is auto-suggested for custom node type modules. - $form['#validate'][] = 'node_form_validate'; +// TODO +// $form['#validate'][] = 'node_form_validate'; if (!isset($form['#submit']) && function_exists($node->type . '_node_form_submit')) { $form['#submit'][] = $node->type . '_node_form_submit'; } $form += array('#submit' => array()); - field_attach_form('node', $node, $form, $form_state, $node->langcode); return $form; } @@ -547,6 +547,7 @@ function node_form_submit_build_node($form, &$form_state) { // handlers during button-level submit processing is worth supporting // properly, and if so, add a Form API function for doing so. unset($form_state['submit_handlers']); + unset($form['#submit']); form_execute_handlers('submit', $form, $form_state); $node = $form_state['node']; diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 2fb21c7..0f766a2 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1354,9 +1354,10 @@ function hook_form_BASE_FORM_ID_alter(&$form, &$form_state, $form_id) { * @return * An associative array whose keys define form_ids and whose values are an * associative array defining the following keys: - * - callback: The name of the form builder function to invoke. This will be - * used for the base form ID, for example, to target a base form using - * hook_form_BASE_FORM_ID_alter(). + * - base form ids: An array containing a list of base form ids to be used to + * alter the form using hook_form_BASE_FORM_ID_alter(). If no value is + * provided the callback function name will be used. + * - callback: The name of the form builder function to invoke. * - callback arguments: (optional) Additional arguments to pass to the * function defined in 'callback', which are prepended to $args. * - wrapper_callback: (optional) The name of a form builder function to diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php new file mode 100644 index 0000000..d205b19 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -0,0 +1,42 @@ +name = trim($vocabulary->name); @@ -643,6 +643,14 @@ function theme_taxonomy_overview_terms($variables) { } /** + * Returns a rendered edit form to create a new term associated to the given vocabulary. + */ +function taxonomy_term_add($vocabulary) { + $term = entity_create('taxonomy_term', array('vid' => $vocabulary->vid, 'vocabulary_machine_name' => $vocabulary->machine_name)); + return $term->edit(); +} + +/** * Form function for the term edit form. * * @param Drupal\taxonomy\Term|null $term @@ -710,8 +718,6 @@ function taxonomy_form_term($form, &$form_state, Term $term = NULL, Vocabulary $ '#value' => isset($term->vocabulary_machine_name) ? $term->vocabulary_machine_name : $vocabulary->name, ); - field_attach_form('taxonomy_term', $term, $form, $form_state); - $form['relations'] = array( '#type' => 'fieldset', '#title' => t('Relations'), @@ -799,8 +805,6 @@ function taxonomy_form_term($form, &$form_state, Term $term = NULL, Vocabulary $ * @see taxonomy_form_term() */ function taxonomy_form_term_validate($form, &$form_state) { - entity_form_field_validate('taxonomy_term', $form, $form_state); - // Ensure numeric values. if (isset($form_state['values']['weight']) && !is_numeric($form_state['values']['weight'])) { form_set_error('weight', t('Weight value must be numeric.')); diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index b536b08..3f95979 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -113,6 +113,9 @@ function taxonomy_entity_info() { 'label' => t('Taxonomy term'), 'entity class' => 'Drupal\taxonomy\Term', 'controller class' => 'Drupal\taxonomy\TermStorageController', + 'form controller class' => array( + 'default' => 'Drupal\taxonomy\TermFormController', + ), 'base table' => 'taxonomy_term_data', 'uri callback' => 'taxonomy_term_uri', 'fieldable' => TRUE, @@ -149,6 +152,9 @@ function taxonomy_entity_info() { 'label' => t('Taxonomy vocabulary'), 'entity class' => 'Drupal\taxonomy\Vocabulary', 'controller class' => 'Drupal\taxonomy\VocabularyStorageController', + 'form controller class' => array( + 'default' => 'Drupal\taxonomy\VocabularyFormController', + ), 'base table' => 'taxonomy_vocabulary', 'entity keys' => array( 'id' => 'vid', @@ -293,8 +299,8 @@ function taxonomy_menu() { ); $items['admin/structure/taxonomy/add'] = array( 'title' => 'Add vocabulary', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('taxonomy_form_vocabulary'), + 'page callback' => 'entity_edit', + 'page arguments' => array('taxonomy_vocabulary'), 'access arguments' => array('administer taxonomy'), 'type' => MENU_LOCAL_ACTION, 'file' => 'taxonomy.admin.inc', @@ -315,10 +321,10 @@ function taxonomy_menu() { ); $items['taxonomy/term/%taxonomy_term/edit'] = array( 'title' => 'Edit', - 'page callback' => 'drupal_get_form', + 'page callback' => 'entity_edit', // Pass a NULL argument to ensure that additional path components are not // passed to taxonomy_form_term() as the vocabulary machine name argument. - 'page arguments' => array('taxonomy_form_term', 2, NULL), + 'page arguments' => array(2), 'access callback' => 'taxonomy_term_access', 'access arguments' => array('edit', 2), 'type' => MENU_LOCAL_TASK, @@ -368,8 +374,8 @@ function taxonomy_menu() { ); $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/edit'] = array( 'title' => 'Edit', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('taxonomy_form_vocabulary', 3), + 'page callback' => 'entity_edit', + 'page arguments' => array(3), 'access arguments' => array('administer taxonomy'), 'type' => MENU_LOCAL_TASK, 'weight' => -10, @@ -378,8 +384,8 @@ function taxonomy_menu() { $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/add'] = array( 'title' => 'Add term', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('taxonomy_form_term', NULL, 3), + 'page callback' => 'taxonomy_term_add', + 'page arguments' => array(3), 'access arguments' => array('administer taxonomy'), 'type' => MENU_LOCAL_ACTION, 'file' => 'taxonomy.admin.inc', diff --git a/core/modules/user/lib/Drupal/user/ProfileFormController.php b/core/modules/user/lib/Drupal/user/ProfileFormController.php new file mode 100644 index 0000000..486b38d --- /dev/null +++ b/core/modules/user/lib/Drupal/user/ProfileFormController.php @@ -0,0 +1,40 @@ + array( 'label' => t('User'), + 'entity class' => 'Drupal\user\User', 'controller class' => 'Drupal\user\UserStorageController', + 'form controller class' => array( + 'default' => 'Drupal\user\ProfileFormController', + 'register' => 'Drupal\user\RegisterFormController', + ), 'base table' => 'users', 'uri callback' => 'user_uri', 'label callback' => 'user_label', 'fieldable' => TRUE, - 'entity class' => 'Drupal\user\User', 'entity keys' => array( 'id' => 'uid', ), @@ -1485,8 +1489,8 @@ function user_menu() { $items['user/register'] = array( 'title' => 'Create new account', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('user_register_form'), + 'page callback' => 'entity_edit', + 'page arguments' => array('user', 'register'), 'access callback' => 'user_register_access', 'type' => MENU_LOCAL_TASK, ); @@ -1653,8 +1657,8 @@ function user_menu() { $items['user/%user/edit'] = array( 'title' => 'Edit', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('user_profile_form', 1), + 'page callback' => 'entity_edit', + 'page arguments' => array(1), 'access callback' => 'user_edit_access', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, @@ -3569,21 +3573,10 @@ function user_register_form($form, &$form_state) { '#value' => t('Create new account'), ); - $form['#validate'][] = 'user_register_validate'; - // Add the final user registration form submit handler. - $form['#submit'][] = 'user_register_submit'; - return $form; } /** - * Validation function for the user registration form. - */ -function user_register_validate($form, &$form_state) { - entity_form_field_validate('user', $form, $form_state); -} - -/** * Submit handler for the user registration form. * * This function is shared by the installation form and the normal registration form, diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 300bbc1..3515fd4 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -225,10 +225,7 @@ function user_profile_form($form, &$form_state, $account) { // $form_state. Remove in Drupal 8. $form['#user'] = $account; - user_account_form($form, $form_state); - // Attach field widgets. - field_attach_form('user', $account, $form, $form_state); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( @@ -242,10 +239,6 @@ function user_profile_form($form, &$form_state, $account) { '#access' => $account->uid > 1 && (($account->uid == $user->uid && user_access('cancel account')) || user_access('administer users')), ); - $form['#validate'][] = 'user_profile_form_validate'; - // Add the final user profile form submit handler. - $form['#submit'][] = 'user_profile_form_submit'; - return $form; }