diff --git a/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php b/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php index e9aaab2..8b18244 100644 --- a/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php +++ b/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php @@ -20,37 +20,13 @@ class HtmlEntityFormController extends HtmlFormController { /** * Overrides \Drupal\Core\HtmlFormController::content(). * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - * @param callable $_form - * The name of the form class for this request. - * @param string $_values - * (optional) The class and method that provides default values for creating - * an entity when one does not exist. - * - * @return \Symfony\Component\HttpFoundation\Response - * A response object. + * Due to reflection, the argument must be named $_entity_form. The parent + * method has $request and $_form, but the parameter must match the route. */ public function content(Request $request, $_entity_form, $_values = FALSE) { - $form_object = $this->getFormObject($request, $_entity_form, $_values); - - // Using reflection, find all of the parameters needed by the form in the - // request attributes, skipping $form and $form_state. - $attributes = $request->attributes->all(); - $reflection = new \ReflectionMethod($form_object, 'buildForm'); - $params = $reflection->getParameters(); - $args = array(); - foreach (array_splice($params, 2) as $param) { - if (array_key_exists($param->name, $attributes)) { - $args[] = $attributes[$param->name]; - } - } - $form_state['build_info']['args'] = $args; - - $form_id = _drupal_form_id($form_object, $form_state); - $form = drupal_build_form($form_id, $form_state); - return new Response(drupal_render_page($form)); + return parent::content($request, $_entity_form); } + /** * Overrides \Drupal\Core\HtmlFormController::getFormObject(). * @@ -71,7 +47,7 @@ public function content(Request $request, $_entity_form, $_values = FALSE) { * _entity_form: 'node' * @endcode */ - protected function getFormObject(Request $request, $form_arg, $_values = FALSE) { + protected function getFormObject(Request $request, $form_arg) { $manager = $this->container->get('plugin.manager.entity'); // If no operation is provided, use 'default'. @@ -84,7 +60,10 @@ protected function getFormObject(Request $request, $form_arg, $_values = FALSE) else { $values = array(); // A default values callback has been provided. - if ($_values && strpos($_values, '::') !== FALSE) { + if (($_values = $request->attributes->get('_values')) && + // Callable is in format class::method. + strpos($_values, '::') !== FALSE) { + // Extract the class and method from the given string. list($class, $method) = explode('::', $_values); // The default values callback is in a ControllerInterface object. if (in_array('Drupal\Core\ControllerInterface', class_implements($class))) { @@ -94,6 +73,7 @@ protected function getFormObject(Request $request, $form_arg, $_values = FALSE) $defaults_class = new $class(); } + // Use _values callable to build default values for the entity. $values = call_user_func(array($defaults_class, $method), $request); }