diff --git a/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php b/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php
index 7ede74e..5a4a0a8 100644
--- a/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php
+++ b/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php
@@ -12,8 +12,6 @@
/**
* Wrapping controller for entity forms that serve as the main page body.
- *
- * @todo Document the expected value for $_entity_form.
*/
class HtmlEntityFormController extends HtmlFormController {
@@ -28,9 +26,26 @@ public function content(Request $request, $_entity_form) {
/**
* Overrides \Drupal\Core\HtmlFormController::getFormArg().
+ *
+ * Instead of a class name or service ID, $arg will be a string representing
+ * the entity and operation being performed.
+ * Consider the following route:
+ * @code
+ * pattern: '/foo/{node}/bar'
+ * defaults:
+ * _entity_form: 'node.edit'
+ * @endcode
+ * This would mean the edit form controller for the node entity should be use.
+ * If the entity type has a default form controller, only the name of the
+ * entity {param} needs to be passed:
+ * @code
+ * pattern: '/foo/{node}/baz'
+ * defaults:
+ * _entity_form: 'node'
+ * @endcode
*/
protected function getFormArg(Request $request, $arg) {
- $manager = \Drupal::service('plugin.manager.entity');
+ $manager = $this->container->get('plugin.manager.entity');
// If no operation is provided, use 'default'.
$arg .= '.default';
diff --git a/core/lib/Drupal/Core/HtmlFormController.php b/core/lib/Drupal/Core/HtmlFormController.php
index deb2ac6..a589396 100644
--- a/core/lib/Drupal/Core/HtmlFormController.php
+++ b/core/lib/Drupal/Core/HtmlFormController.php
@@ -46,12 +46,12 @@ public function setContainer(ContainerInterface $container = NULL) {
* A response object.
*/
public function content(Request $request, $_form) {
- $form_arg = $this->getFormArg($request, $_form);
+ $form_object = $this->getFormObject($request, $_form);
// 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_arg, 'buildForm');
+ $reflection = new \ReflectionMethod($form_object, 'buildForm');
$params = $reflection->getParameters();
$args = array();
foreach (array_splice($params, 2) as $param) {
@@ -61,15 +61,23 @@ public function content(Request $request, $_form) {
}
$form_state['build_info']['args'] = $args;
- $form_id = _drupal_form_id($form_arg, $form_state);
+ $form_id = _drupal_form_id($form_object, $form_state);
$form = drupal_build_form($form_id, $form_state);
return new Response(drupal_render_page($form));
}
/**
- * @todo.
+ * Returns the object used to build the form.
+ *
+ * @param \Symfony\Component\HttpFoundation\Request $request
+ * The request using this form.
+ * @param string $arg
+ * Either a class name or a service ID.
+ *
+ * @return \Drupal\Core\Form\FormInterface
+ * The form object to use.
*/
- protected function getFormArg(Request $request, $arg) {
+ protected function getFormObject(Request $request, $arg) {
// If this is a class, instantiate it.
if (class_exists($arg)) {
if (in_array('Drupal\Core\ControllerInterface', class_implements($arg))) {
@@ -78,6 +86,7 @@ protected function getFormArg(Request $request, $arg) {
return new $arg();
}
+
// Otherwise, it is a service.
return $this->container->get($arg);
}
diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php
index 2d38197..ca9d605 100644
--- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php
+++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php
@@ -61,11 +61,11 @@ function setUp() {
* Test that allowed values can be updated.
*/
function testUpdateAllowedValues() {
- $manager = $this->container->get('plugin.manager.entity');
$langcode = LANGUAGE_NOT_SPECIFIED;
// All three options appear.
- $form = $manager->getForm('entity_test');
+ $entity = entity_create('entity_test', array());
+ $form = entity_get_form($entity);
$this->assertTrue(!empty($form[$this->field_name][$langcode][1]), 'Option 1 exists');
$this->assertTrue(!empty($form[$this->field_name][$langcode][2]), 'Option 2 exists');
$this->assertTrue(!empty($form[$this->field_name][$langcode][3]), 'Option 3 exists');
@@ -90,7 +90,8 @@ function testUpdateAllowedValues() {
// Removed options do not appear.
$this->field['settings']['allowed_values'] = array(2 => 'Two');
field_update_field($this->field);
- $form = $manager->getForm('entity_test');
+ $entity = entity_create('entity_test', array());
+ $form = entity_get_form($entity);
$this->assertTrue(empty($form[$this->field_name][$langcode][1]), 'Option 1 does not exist');
$this->assertTrue(!empty($form[$this->field_name][$langcode][2]), 'Option 2 exists');
$this->assertTrue(empty($form[$this->field_name][$langcode][3]), 'Option 3 does not exist');
@@ -98,7 +99,7 @@ function testUpdateAllowedValues() {
// Completely new options appear.
$this->field['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty');
field_update_field($this->field);
- $form = $manager->getForm($entity);
+ $form = entity_get_form($entity);
$this->assertTrue(empty($form[$this->field_name][$langcode][1]), 'Option 1 does not exist');
$this->assertTrue(empty($form[$this->field_name][$langcode][2]), 'Option 2 does not exist');
$this->assertTrue(empty($form[$this->field_name][$langcode][3]), 'Option 3 does not exist');
@@ -119,7 +120,8 @@ function testUpdateAllowedValues() {
),
);
$this->instance = field_create_instance($this->instance);
- $form = $manager->getForm('entity_test');
+ $entity = entity_create('entity_test', array());
+ $form = entity_get_form($entity);
$this->assertTrue(!empty($form[$this->field_name][$langcode][1]), 'Option 1 exists');
$this->assertTrue(!empty($form[$this->field_name][$langcode][2]), 'Option 2 exists');
$this->assertTrue(!empty($form[$this->field_name][$langcode][3]), 'Option 3 exists');