diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 702a56e..58ff1db 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -485,11 +485,12 @@ function entity_form_submit(EntityInterface $entity, $operation = 'default', &$f * * @return * The processed form for the given entity and operation. + * + * @deprecated Use Drupal::entityManager()->getForm() or _entity_form from a + * routing.yml file instead of a page callback. */ function entity_get_form(EntityInterface $entity, $operation = 'default', array $form_state = array()) { - $form_state += entity_form_state_defaults($entity, $operation); - $form_id = $form_state['build_info']['callback_object']->getFormID(); - return drupal_build_form($form_id, $form_state); + return Drupal::entityManager()->getForm($entity, $operation, $form_state); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 7cb4bc2..ce19982 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -236,6 +236,33 @@ protected function getController($entity_type, $controller_type) { } /** + * Returns the built and processed entity form for the given entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity to be created or edited. + * @param string $operation + * (optional) The operation identifying the form variation to be returned. + * Defaults to 'default'. + * @param array $form_state + * (optional) An associative array containing the current state of the form. + * Use this to pass additional information to the form, such as the + * langcode. Defaults to an empty array. + * @code + * $form_state['langcode'] = $langcode; + * $manager = Drupal::entityManager(); + * $form = $manager->getForm($entity, 'default', $form_state); + * @endcode + * + * @return array + * The processed form for the given entity and operation. + */ + public function getForm(EntityInterface $entity, $operation = 'default', array $form_state = array()) { + $form_state += entity_form_state_defaults($entity, $operation); + $form_id = $form_state['build_info']['callback_object']->getFormID(); + return drupal_build_form($form_id, $form_state); + } + + /** * Returns the administration path for an entity type's bundle. * * @param string $entity_type diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php index 663651f..eac277c 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php @@ -97,7 +97,7 @@ public function feedAdd() { 'refresh' => 3600, 'block' => 5, )); - return entity_get_form($feed); + return $this->entityManager->getForm($feed); } /** diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc index 953e462..82706c4 100644 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@ -54,7 +54,7 @@ function block_admin_add($plugin_id, $theme) { 'plugin' => $plugin_id, 'theme' => $theme, )); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } /** @@ -84,5 +84,5 @@ function block_admin_edit(Block $entity) { // Get the block label for the page title. drupal_set_title(t("Configure %label block in %theme", array('%label' => $entity->label(), '%theme' => $theme_title)), PASS_THROUGH); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } diff --git a/core/modules/block/custom_block/custom_block.admin.inc b/core/modules/block/custom_block/custom_block.admin.inc index 6c74edc..02a0767 100644 --- a/core/modules/block/custom_block/custom_block.admin.inc +++ b/core/modules/block/custom_block/custom_block.admin.inc @@ -17,7 +17,7 @@ */ function custom_block_type_add() { $block_type = entity_create('custom_block_type', array()); - return entity_get_form($block_type); + return Drupal::entityManager()->getForm($block_type); } /** @@ -32,7 +32,7 @@ function custom_block_type_add() { * @see custom_block_menu() */ function custom_block_type_edit(CustomBlockType $block_type) { - return entity_get_form($block_type); + return Drupal::entityManager()->getForm($block_type); } /** diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index a18c9f0..1fd7b5f 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -42,7 +42,7 @@ function template_preprocess_custom_block_add_list(&$variables) { */ function custom_block_edit(CustomBlock $block) { drupal_set_title(t('Edit custom block %label', array('%label' => $block->label())), PASS_THROUGH); - return entity_get_form($block); + return Drupal::entityManager()->getForm($block); } /** diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php index 92b5e0c..4f139f3 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php @@ -7,6 +7,7 @@ namespace Drupal\custom_block\Controller; +use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\custom_block\CustomBlockTypeInterface; @@ -16,11 +17,11 @@ class CustomBlockController implements ControllerInterface { /** - * Current request object. + * The entity manager. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Drupal\Component\Plugin\PluginManagerInterface */ - protected $request; + protected $entityManager; /** * The custom block storage controller. @@ -42,7 +43,7 @@ class CustomBlockController implements ControllerInterface { public static function create(ContainerInterface $container) { $entity_manager = $container->get('plugin.manager.entity'); return new static( - $container->get('request'), + $entity_manager, $entity_manager->getStorageController('custom_block'), $entity_manager->getStorageController('custom_block_type') ); @@ -51,17 +52,17 @@ public static function create(ContainerInterface $container) { /** * Constructs a CustomBlock object. * - * @param \Symfony\Component\HttpFoundation\Request $request - * Current request. + * @param \Drupal\Component\Plugin\PluginManagerInterface $entity_manager + * The entity manager. * @param \Drupal\Core\Entity\EntityStorageControllerInterface $custom_block_storage * The custom block storage controller. * @param \Drupal\Core\Entity\EntityStorageControllerInterface $custom_block_type_storage * The custom block type storage controller. */ - public function __construct(Request $request, EntityStorageControllerInterface $custom_block_storage, EntityStorageControllerInterface $custom_block_type_storage) { - $this->request = $request; + public function __construct(PluginManagerInterface $entity_manager, EntityStorageControllerInterface $custom_block_storage, EntityStorageControllerInterface $custom_block_type_storage) { $this->customBlockStorage = $custom_block_storage; $this->customBlockTypeStorage = $custom_block_type_storage; + $this->entityManager = $entity_manager; } /** @@ -87,11 +88,13 @@ public function add() { * * @param \Drupal\custom_block\CustomBlockTypeInterface $custom_block_type * The custom block type to add. + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request object. * * @return array * A form array as expected by drupal_render(). */ - public function addForm(CustomBlockTypeInterface $custom_block_type) { + public function addForm(CustomBlockTypeInterface $custom_block_type, Request $request) { // @todo Remove this when https://drupal.org/node/1981644 is in. drupal_set_title(t('Add %type custom block', array( '%type' => $custom_block_type->label() @@ -99,13 +102,13 @@ public function addForm(CustomBlockTypeInterface $custom_block_type) { $block = $this->customBlockStorage->create(array( 'type' => $custom_block_type->id() )); - if (($theme = $this->request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) { + if (($theme = $request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) { // We have navigated to this page from the block library and will keep track // of the theme for redirecting the user to the configuration page for the // newly created block in the given theme. $block->setTheme($theme); } - return entity_get_form($block); + return $this->entityManager->getForm($block); } } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index e309ec7..0b45d87 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -729,7 +729,7 @@ function comment_node_page_additions(EntityInterface $node) { function comment_add(EntityInterface $node, $pid = NULL) { $values = array('nid' => $node->nid, 'pid' => $pid, 'node_type' => 'comment_node_' . $node->type); $comment = entity_create('comment', $values); - return entity_get_form($comment); + return Drupal::entityManager()->getForm($comment); } /** diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php index b7b6458..0888dba 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php @@ -28,7 +28,7 @@ class ConfigTestController { */ public function edit(ConfigTest $config_test) { drupal_set_title(String::format('Edit %label', array('%label' => $config_test->label())), PASS_THROUGH); - return entity_get_form($config_test); + return \Drupal::entityManager()->getForm($config_test); } /** diff --git a/core/modules/contact/contact.pages.inc b/core/modules/contact/contact.pages.inc index 423cd72..0e07a94 100644 --- a/core/modules/contact/contact.pages.inc +++ b/core/modules/contact/contact.pages.inc @@ -48,7 +48,7 @@ function contact_site_page(Category $category = NULL) { $message = entity_create('contact_message', array( 'category' => $category->id(), )); - return entity_get_form($message); + return Drupal::entityManager()->getForm($message); } /** @@ -78,7 +78,7 @@ function contact_personal_page($recipient) { 'recipient' => $recipient, 'category' => 'personal', )); - return entity_get_form($message); + return Drupal::entityManager()->getForm($message); } /** diff --git a/core/modules/field/tests/modules/field_test/field_test.entity.inc b/core/modules/field/tests/modules/field_test/field_test.entity.inc index f00a57e..e6f3d5c 100644 --- a/core/modules/field/tests/modules/field_test/field_test.entity.inc +++ b/core/modules/field/tests/modules/field_test/field_test.entity.inc @@ -208,7 +208,7 @@ function field_test_entity_add($fttype) { $fttype = str_replace('-', '_', $fttype); $entity = field_test_create_entity(NULL, NULL, $fttype); drupal_set_title(t('Create test_entity @bundle', array('@bundle' => $fttype)), PASS_THROUGH); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } /** @@ -216,7 +216,7 @@ function field_test_entity_add($fttype) { */ function field_test_entity_edit(TestEntity $entity) { drupal_set_title(t('test_entity @ftid revision @ftvid', array('@ftid' => $entity->ftid, '@ftvid' => $entity->ftvid)), PASS_THROUGH); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } /** diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index 78a43bd..7346712 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -29,7 +29,7 @@ function menu_overview_page() { */ function menu_menu_add() { $menu = entity_create('menu', array()); - return entity_get_form($menu); + return Drupal::entityManager()->getForm($menu); } /** @@ -45,7 +45,7 @@ function menu_menu_add() { */ function menu_menu_edit(Menu $menu) { drupal_set_title(t('Edit menu %label', array('%label' => $menu->label())), PASS_THROUGH); - return entity_get_form($menu); + return Drupal::entityManager()->getForm($menu); } /** @@ -387,5 +387,5 @@ function menu_link_add(Menu $menu) { 'menu_name' => $menu->id(), )); drupal_set_title(t('Add menu link')); - return entity_get_form($menu_link); + return Drupal::entityManager()->getForm($menu_link); } diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 9830e1f..f81210e 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -92,7 +92,7 @@ function node_add($node_type) { 'langcode' => $langcode ? $langcode : language_default()->langcode, ))->getBCEntity(); drupal_set_title(t('Create @name', array('@name' => $node_type->name)), PASS_THROUGH); - return entity_get_form($node); + return Drupal::entityManager()->getForm($node); } /** diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index 984a205..cc42901 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -38,7 +38,7 @@ function testUpdateAllowedValues() { // All three options appear. $entity = entity_create('entity_test', array()); - $form = entity_get_form($entity); + $form = \Drupal::entityManager()->getForm($entity); $this->assertTrue(!empty($form[$this->fieldName][$langcode][1]), 'Option 1 exists'); $this->assertTrue(!empty($form[$this->fieldName][$langcode][2]), 'Option 2 exists'); $this->assertTrue(!empty($form[$this->fieldName][$langcode][3]), 'Option 3 exists'); @@ -64,7 +64,7 @@ function testUpdateAllowedValues() { $this->field['settings']['allowed_values'] = array(2 => 'Two'); field_update_field($this->field); $entity = entity_create('entity_test', array()); - $form = entity_get_form($entity); + $form = \Drupal::entityManager()->getForm($entity); $this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist'); $this->assertTrue(!empty($form[$this->fieldName][$langcode][2]), 'Option 2 exists'); $this->assertTrue(empty($form[$this->fieldName][$langcode][3]), 'Option 3 does not exist'); @@ -72,7 +72,7 @@ function testUpdateAllowedValues() { // Completely new options appear. $this->field['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); field_update_field($this->field); - $form = entity_get_form($entity); + $form = \Drupal::entityManager()->getForm($entity); $this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist'); $this->assertTrue(empty($form[$this->fieldName][$langcode][2]), 'Option 2 does not exist'); $this->assertTrue(empty($form[$this->fieldName][$langcode][3]), 'Option 3 does not exist'); @@ -95,7 +95,7 @@ function testUpdateAllowedValues() { )) ->save(); $entity = entity_create('entity_test', array()); - $form = entity_get_form($entity); + $form = \Drupal::entityManager()->getForm($entity); $this->assertTrue(!empty($form[$this->fieldName][$langcode][1]), 'Option 1 exists'); $this->assertTrue(!empty($form[$this->fieldName][$langcode][2]), 'Option 2 exists'); $this->assertTrue(!empty($form[$this->fieldName][$langcode][3]), 'Option 3 exists'); diff --git a/core/modules/shortcut/shortcut.admin.inc b/core/modules/shortcut/shortcut.admin.inc index 8b120fc..60dab60 100644 --- a/core/modules/shortcut/shortcut.admin.inc +++ b/core/modules/shortcut/shortcut.admin.inc @@ -175,7 +175,7 @@ function shortcut_set_switch_submit($form, &$form_state) { */ function shortcut_set_add() { $entity = entity_create('shortcut', array()); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php index 2a6e833..ff78829 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php @@ -79,7 +79,7 @@ function testEntityFormLanguage() { // Explicitly set form langcode. $langcode = $this->langcodes[0]; $form_state['langcode'] = $langcode; - entity_get_form($node, 'default', $form_state); + \Drupal::entityManager()->getForm($node, 'default', $form_state); $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: FALSE; $this->assertTrue($langcode == $form_langcode, 'Form language is the same as the language parameter.'); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 68098eb..55d0dac 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -257,7 +257,7 @@ function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) { function entity_test_add($entity_type) { drupal_set_title(t('Create an @type', array('@type' => $entity_type))); $entity = entity_create($entity_type, array()); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } /** @@ -273,7 +273,7 @@ function entity_test_add($entity_type) { */ function entity_test_edit(EntityInterface $entity) { drupal_set_title($entity->label(), PASS_THROUGH); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } /** diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index b73006e..9c36916 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -2267,8 +2267,8 @@ function form_test_two_instances() { 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $node2 = clone($node1); - $return['node_form_1'] = entity_get_form($node1); - $return['node_form_2'] = entity_get_form($node2); + $return['node_form_1'] = Drupal::entityManager()->getForm($node1); + $return['node_form_2'] = Drupal::entityManager()->getForm($node2); return $return; } diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index e2d6841..24b71f9 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -17,7 +17,7 @@ function taxonomy_vocabulary_add() { // most likely default value until we have better flexible settings. 'langcode' => language_default()->langcode, )); - return entity_get_form($vocabulary); + return Drupal::entityManager()->getForm($vocabulary); } /** @@ -398,7 +398,7 @@ function taxonomy_term_add($vocabulary) { if (module_exists('language')) { $term->langcode = language_get_default_langcode('taxonomy_term', $vocabulary->id()); } - return entity_get_form($term); + return Drupal::entityManager()->getForm($term); } /** diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc index c7de9e2..cd212eb 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -202,7 +202,7 @@ function translation_entity_add_page(EntityInterface $entity, Language $source = $form_state['translation_entity']['target'] = $target; $controller = translation_entity_controller($entity->entityType()); $form_state['translation_entity']['translation_form'] = !$controller->getAccess($entity, 'update'); - return entity_get_form($entity, $operation, $form_state); + return Drupal::entityManager()->getForm($entity, $operation, $form_state); } /** @@ -223,7 +223,7 @@ function translation_entity_edit_page(EntityInterface $entity, Language $languag $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; $form_state['langcode'] = $language->langcode; $form_state['translation_entity']['translation_form'] = TRUE; - return entity_get_form($entity, $operation, $form_state); + return Drupal::entityManager()->getForm($entity, $operation, $form_state); } /** diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Controller/ViewsUIController.php b/core/modules/views_ui/lib/Drupal/views_ui/Controller/ViewsUIController.php index cbeec41..e4b1bfa 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Controller/ViewsUIController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Controller/ViewsUIController.php @@ -234,8 +234,8 @@ public function edit(ViewUI $view, $display_id = NULL) { } drupal_set_title($name); - $build['edit'] = entity_get_form($view, 'edit', array('display_id' => $display_id)); - $build['preview'] = entity_get_form($view, 'preview', array('display_id' => $display_id)); + $build['edit'] = $this->entityManager->getForm($view, 'edit', array('display_id' => $display_id)); + $build['preview'] = $this->entityManager->getForm($view, 'preview', array('display_id' => $display_id)); return $build; }