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 2d5786d..d29208d 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -239,6 +239,33 @@ public function getAccessController($entity_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/Routing/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php index 838b031..8ce6210 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Routing/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 a0dc773..7538905 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -55,7 +55,7 @@ function custom_block_add(CustomBlockType $block_type) { // newly created block in the given theme. $block->setTheme($theme); } - return entity_get_form($block); + return Drupal::entityManager()->getForm($block); } /** @@ -71,7 +71,7 @@ function custom_block_add(CustomBlockType $block_type) { */ 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/comment/comment.module b/core/modules/comment/comment.module index 8d9cb4b..2adbef1 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 d781264..c375dca 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 @@ -205,7 +205,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); } /** @@ -213,7 +213,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 f08ddbd..b7219d9 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); } /** @@ -372,5 +372,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 8255df5..d1fc52a 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); - $output = entity_get_form($node); + $output = Drupal::entityManager()->getForm($node); return $output; } 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 e8ab3b5..11c97bb 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 35b332b..60398c1 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -255,7 +255,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); } /** @@ -271,7 +271,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 63973aa..28b7d4a 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/user/user.admin.inc b/core/modules/user/user.admin.inc index 7c04815..626e9f2 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -27,7 +27,7 @@ function user_admin($callback_arg = '') { case t('Create new account'): case 'create': $account = entity_create('user', array()); - $build['user_register'] = entity_get_form($account, 'register'); + $build['user_register'] = Drupal::entityManager()->getForm($account, 'register'); break; default: if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'cancel')) { diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Routing/ViewsUIController.php b/core/modules/views_ui/lib/Drupal/views_ui/Routing/ViewsUIController.php index 472b460..e7fecc4 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Routing/ViewsUIController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Routing/ViewsUIController.php @@ -244,8 +244,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; }