diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 444634b..6513ff7 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -484,11 +484,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 9e1d12f..2ed26a5 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -201,6 +201,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 dfed7fd..c969ef1 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php @@ -71,7 +71,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 f94ce25..df52dfe 100644 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@ -50,7 +50,7 @@ function block_admin_add($plugin_id, $theme) { 'plugin' => $plugin_id, 'theme' => $theme, )); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } /** @@ -80,7 +80,7 @@ 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 9c802c4..9949d47 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -62,7 +62,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); } /** @@ -78,7 +78,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 0c2cd55..afa1da1 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -726,7 +726,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/config_test.module b/core/modules/config/tests/config_test/config_test.module index 9949d90..6d66452 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -86,7 +86,7 @@ function config_test_load($id) { */ function config_test_add_page() { $entity = entity_create('config_test', array()); - return entity_get_form($entity); + return Drupal::entityManager()->getForm($entity); } /** @@ -100,7 +100,7 @@ function config_test_add_page() { */ function config_test_edit_page(ConfigTest $config_test) { drupal_set_title(format_string('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.admin.inc b/core/modules/contact/contact.admin.inc index 32ddf71..3e1248f 100644 --- a/core/modules/contact/contact.admin.inc +++ b/core/modules/contact/contact.admin.inc @@ -33,7 +33,7 @@ function contact_category_list() { function contact_category_add() { drupal_set_title(t('Add contact form category')); $category = entity_create('contact_category', array()); - return entity_get_form($category); + return Drupal::entityManager()->getForm($category); } /** @@ -49,5 +49,5 @@ function contact_category_add() { */ function contact_category_edit(Category $category) { drupal_set_title(t('Edit %label contact form category', array('%label' => $category->label())), PASS_THROUGH); - return entity_get_form($category); + return Drupal::entityManager()->getForm($category); } diff --git a/core/modules/contact/contact.pages.inc b/core/modules/contact/contact.pages.inc index 5ee9fb7..a86caeb 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); } /** @@ -77,7 +77,7 @@ function contact_personal_page($recipient) { $message = entity_create('contact_message', array( 'recipient' => $recipient, )); - return entity_get_form($message); + return Drupal::entityManager()->getForm($message); } /** diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php index 66d8cbf..065ab7f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php @@ -317,7 +317,7 @@ public function save() { } // Otherwise, the field instance is being updated. else { - $original = \Drupal::service('plugin.manager.entity') + $original = \Drupal::entityManager() ->getStorageController($this->entityType) ->loadUnchanged($this->getOriginalID()); 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 817986f..ed41f11 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 4150b99..8cd2563 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 863babd..17c554b 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -24,7 +24,7 @@ */ function node_page_edit($node) { drupal_set_title(t('Edit @type @title', array('@type' => node_get_type_label($node), '@title' => $node->label())), PASS_THROUGH); - return entity_get_form($node); + return Drupal::entityManager()->getForm($node); } /** @@ -108,7 +108,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 efd8d5c..29816a9 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -37,7 +37,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'); @@ -63,7 +63,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'); @@ -71,7 +71,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'); @@ -94,7 +94,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 2f7acf6..126b653 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 012b909..6815b01 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 = 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 e8c1d9b..ceb57d0 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -234,7 +234,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); } /** @@ -250,7 +250,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 97657a1..778640e 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_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 0703071..c6f5518 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -99,7 +99,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); } /** @@ -480,7 +480,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 38ae80b..cfea2a4 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 9946ae2..417f004 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')) { @@ -479,5 +479,5 @@ function user_admin_roles_list() { function user_admin_role_add() { drupal_set_title(t('Add role')); $role = entity_create('user_role', array()); - return entity_get_form($role); + return Drupal::entityManager()->getForm($role); } 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 7cb32fd..9d619f8 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; }