diff --git a/core/modules/aggregator/src/FeedForm.php b/core/modules/aggregator/src/FeedForm.php index b0a5e01..228cd53 100644 --- a/core/modules/aggregator/src/FeedForm.php +++ b/core/modules/aggregator/src/FeedForm.php @@ -62,10 +62,11 @@ public function validate(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - parent::save($form, $form_state); - $feed = $this->entity; $insert = (bool) $feed->id(); + + parent::save($form, $form_state); + // @ŧodo Split this into dedicated add and edit forms. if ($insert) { drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $feed->label()))); diff --git a/core/modules/block_content/src/Form/BlockContentTypeAddForm.php b/core/modules/block_content/src/Form/BlockContentTypeAddForm.php index ae9aac7..e6f327c 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeAddForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeAddForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $block_type = $this->entity; - $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Custom block type %label has been added.', array('%label' => $block_type->label()))); $this->logger('block_content')->notice('Custom block type %label has been added.', array( diff --git a/core/modules/block_content/src/Form/BlockContentTypeEditForm.php b/core/modules/block_content/src/Form/BlockContentTypeEditForm.php index 922c3d7..f3e2d34 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeEditForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeEditForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $block_type = $this->entity; - $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Custom block type %label has been updated.', array('%label' => $block_type->label()))); $this->logger('block_content')->notice('Custom block type %label has been updated.', array( diff --git a/core/modules/comment/src/Form/CommentTypeAddForm.php b/core/modules/comment/src/Form/CommentTypeAddForm.php index d35ca21..d9b589f 100644 --- a/core/modules/comment/src/Form/CommentTypeAddForm.php +++ b/core/modules/comment/src/Form/CommentTypeAddForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $block_type = $this->entity; - $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Comment type %label has been added.', array('%label' => $block_type->label()))); $this->logger->notice('Comment type %label has been added.', array( diff --git a/core/modules/comment/src/Form/CommentTypeEditForm.php b/core/modules/comment/src/Form/CommentTypeEditForm.php index fcf9470..317bde2 100644 --- a/core/modules/comment/src/Form/CommentTypeEditForm.php +++ b/core/modules/comment/src/Form/CommentTypeEditForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $block_type = $this->entity; - $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Comment type %label has been updated.', array('%label' => $block_type->label()))); $this->logger->notice('Comment type %label has been updated.', array( diff --git a/core/modules/contact/src/Form/CategoryAddForm.php b/core/modules/contact/src/Form/CategoryAddForm.php index 2c295e1..a8279ba 100644 --- a/core/modules/contact/src/Form/CategoryAddForm.php +++ b/core/modules/contact/src/Form/CategoryAddForm.php @@ -7,7 +7,6 @@ namespace Drupal\contact\Form; -use Drupal\contact\CategoryFormBase; use Drupal\Core\Form\FormStateInterface; /** @@ -22,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $category = $this->entity; - $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Category %label has been added.', array('%label' => $category->label()))); $this->logger('contact')->notice('Category %label has been added.', array( diff --git a/core/modules/contact/src/Form/CategoryEditForm.php b/core/modules/contact/src/Form/CategoryEditForm.php index 82656c9..be1a62a 100644 --- a/core/modules/contact/src/Form/CategoryEditForm.php +++ b/core/modules/contact/src/Form/CategoryEditForm.php @@ -7,7 +7,6 @@ namespace Drupal\contact\Form; -use Drupal\contact\CategoryFormBase; use Drupal\Core\Form\FormStateInterface; /** @@ -22,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $block_type = $this->entity; - $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Category %label has been updated.', array('%label' => $block_type->label()))); $this->logger('contact')->notice('Category %label has been updated.', array( diff --git a/core/modules/contact/src/Form/CategoryFormBase.php b/core/modules/contact/src/Form/CategoryFormBase.php index 8267363..f442ed2 100644 --- a/core/modules/contact/src/Form/CategoryFormBase.php +++ b/core/modules/contact/src/Form/CategoryFormBase.php @@ -5,7 +5,7 @@ * Contains \Drupal\contact\Form\CategoryFormBase. */ -namespace Drupal\contact; +namespace Drupal\contact\Form; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityTypeInterface; diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index 9898678..2d85070 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -208,7 +208,7 @@ function content_translation_add_page(EntityInterface $entity, LanguageInterface $form_state['content_translation']['source'] = $source; $form_state['content_translation']['target'] = $target; $form_state['content_translation']['translation_form'] = !$entity->access('update'); - return \Drupal::service('entity.form_builder')->getForm($entity, 'default', $form_state); + return \Drupal::service('entity.form_builder')->getForm($entity, 'add', $form_state); } /** @@ -230,7 +230,7 @@ function content_translation_edit_page(EntityInterface $entity, LanguageInterfac $language = !empty($language) ? $language : \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); $form_state['langcode'] = $language->id; $form_state['content_translation']['translation_form'] = TRUE; - return \Drupal::service('entity.form_builder')->getForm($entity, 'default', $form_state); + return \Drupal::service('entity.form_builder')->getForm($entity, 'edit', $form_state); } /** diff --git a/core/modules/field/src/Tests/FieldAttachOtherTest.php b/core/modules/field/src/Tests/FieldAttachOtherTest.php index b6cdbdf..c48a63c 100644 --- a/core/modules/field/src/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/src/Tests/FieldAttachOtherTest.php @@ -295,7 +295,7 @@ function testEntityFormDisplayExtractFormValues() { $entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->instance->bundle)); // Build the form for all fields. - $display = entity_get_form_display($entity_type, $this->fieldTestData->instance->bundle, 'add'); + $display = entity_get_form_display($entity_type, $this->fieldTestData->instance->bundle, 'default'); $form = array(); $form_state = new FormState(); $display->buildForm($entity_init, $form, $form_state); @@ -331,7 +331,7 @@ function testEntityFormDisplayExtractFormValues() { $values_2[1]['value'] = 0; // Pretend the form has been built. - $form_state['build_info']['callback_object'] = \Drupal::entityManager()->getFormObject($entity_type, 'default'); + $form_state['build_info']['callback_object'] = \Drupal::entityManager()->getFormObject($entity_type, 'add'); \Drupal::formBuilder()->prepareForm('field_test_entity_form', $form, $form_state); drupal_process_form('field_test_entity_form', $form, $form_state); $form_state->setValue($this->fieldTestData->field_name, $values); @@ -350,13 +350,13 @@ function testEntityFormDisplayExtractFormValues() { $expected_values[] = array('value' => $values[$key]['value']); } } - $this->assertIdentical($entity->{$this->fieldTestData->field_name}->getValue(), $expected_values, 'Submit filters empty values'); + $this->assertIdentical($entity->{$this->fieldTestData->field_name}->getValue(), $expected_values); foreach ($weights_2 as $key => $value) { if ($key != 1) { $expected_values_2[] = array('value' => $values_2[$key]['value']); } } - $this->assertIdentical($entity->{$this->fieldTestData->field_name_2}->getValue(), $expected_values_2, 'Submit filters empty values'); + $this->assertIdentical($entity->{$this->fieldTestData->field_name_2}->getValue(), $expected_values_2); // Call EntityFormDisplayInterface::extractFormValues() for a single field (the second field). foreach ($display->getComponents() as $name => $options) { @@ -373,7 +373,7 @@ function testEntityFormDisplayExtractFormValues() { } } $this->assertTrue($entity->{$this->fieldTestData->field_name}->isEmpty(), 'The first field is empty in the entity object'); - $this->assertIdentical($entity->{$this->fieldTestData->field_name_2}->getValue(), $expected_values_2, 'Submit filters empty values'); + $this->assertIdentical($entity->{$this->fieldTestData->field_name_2}->getValue(), $expected_values_2); } } diff --git a/core/modules/field_ui/src/Form/FieldInstanceConfigDeleteForm.php b/core/modules/field_ui/src/Form/FieldInstanceConfigDeleteForm.php index 97470db..d8de78f 100644 --- a/core/modules/field_ui/src/Form/FieldInstanceConfigDeleteForm.php +++ b/core/modules/field_ui/src/Form/FieldInstanceConfigDeleteForm.php @@ -68,7 +68,7 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { $field_storage = $this->entity->getFieldStorageDefinition(); $bundles = entity_get_bundles(); $bundle_label = $bundles[$this->entity->entity_type][$this->entity->bundle]['label']; diff --git a/core/modules/language/src/Form/LanguageDeleteForm.php b/core/modules/language/src/Form/LanguageDeleteForm.php index 26c83a2..54c3ca5 100644 --- a/core/modules/language/src/Form/LanguageDeleteForm.php +++ b/core/modules/language/src/Form/LanguageDeleteForm.php @@ -106,7 +106,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { // @todo This should be replaced with $this->entity->delete() when the // additional logic in language_delete() is ported. $success = language_delete($this->entity->id()); diff --git a/core/modules/menu_ui/src/Form/MenuAddForm.php b/core/modules/menu_ui/src/Form/MenuAddForm.php index 8269db6..3883b73 100644 --- a/core/modules/menu_ui/src/Form/MenuAddForm.php +++ b/core/modules/menu_ui/src/Form/MenuAddForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $menu = $this->entity; - $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Menu %label has been added.', array('%label' => $menu->label()))); $this->logger('menu')->notice('Menu %label has been added.', array('%label' => $menu->label(), 'link' => $edit_link)); diff --git a/core/modules/menu_ui/src/Form/MenuDeleteForm.php b/core/modules/menu_ui/src/Form/MenuDeleteForm.php index 299df36..f4b7c5b 100644 --- a/core/modules/menu_ui/src/Form/MenuDeleteForm.php +++ b/core/modules/menu_ui/src/Form/MenuDeleteForm.php @@ -92,7 +92,7 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { $form_state->setRedirect('menu_ui.overview_page'); // Locked menus may not be deleted. diff --git a/core/modules/menu_ui/src/Form/MenuEditForm.php b/core/modules/menu_ui/src/Form/MenuEditForm.php index 2845fb6..af1a028 100644 --- a/core/modules/menu_ui/src/Form/MenuEditForm.php +++ b/core/modules/menu_ui/src/Form/MenuEditForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $menu = $this->entity; - $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Menu %label has been updated.', array('%label' => $menu->label()))); $this->logger('menu')->notice('Menu %label has been updated.', array('%label' => $menu->label(), 'link' => $edit_link)); diff --git a/core/modules/menu_ui/src/Form/MenuFormBase.php b/core/modules/menu_ui/src/Form/MenuFormBase.php index 75e3356..f4bff84 100644 --- a/core/modules/menu_ui/src/Form/MenuFormBase.php +++ b/core/modules/menu_ui/src/Form/MenuFormBase.php @@ -174,13 +174,20 @@ public function menuNameExists($value) { /** * {@inheritdoc} */ - public function save(array $form, FormStateInterface $form_state) { - parent::save($form, $form_state); + public function submit(array $form, FormStateInterface $form_state) { + parent::submit($form, $form_state); $menu = $this->entity; if (!$menu->isNew() || $menu->isLocked()) { $this->submitOverviewForm($form, $form_state); } + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); } diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index a2cdc5f..b9e96fd 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -28,8 +28,8 @@ * "view_builder" = "Drupal\node\NodeViewBuilder", * "access" = "Drupal\node\NodeAccessControlHandler", * "form" = { - * "add" = "Drupal\node\NodeAddForm", - * "edit" = "Drupal\node\NodeEditForm", + * "add" = "Drupal\node\Form\NodeAddForm", + * "edit" = "Drupal\node\Form\NodeEditForm", * "delete" = "Drupal\node\Form\NodeDeleteForm", * }, * "list_builder" = "Drupal\node\NodeListBuilder", diff --git a/core/modules/node/src/Form/NodeAddForm.php b/core/modules/node/src/Form/NodeAddForm.php index 9eb4734..780bd46 100644 --- a/core/modules/node/src/Form/NodeAddForm.php +++ b/core/modules/node/src/Form/NodeAddForm.php @@ -22,7 +22,7 @@ public function save(array $form, FormStateInterface $form_state) { /** @var \Drupal\node\NodeInterface $node */ $node = $this->entity; - $node_type = $this->nodeTypeStorage->load($node->getType()); + $node_type = $this->entityManager->getStorage('node_type')->load($node->getType()); $t_args = array('@type' => $node_type->label(), '%title' => $node->label()); $log_context = array( '@type' => $node->getType(), diff --git a/core/modules/node/src/Form/NodeEditForm.php b/core/modules/node/src/Form/NodeEditForm.php index 87f1956..ad7c4be 100644 --- a/core/modules/node/src/Form/NodeEditForm.php +++ b/core/modules/node/src/Form/NodeEditForm.php @@ -22,7 +22,7 @@ public function save(array $form, FormStateInterface $form_state) { /** @var \Drupal\node\NodeInterface $node */ $node = $this->entity; - $node_type = $this->nodeTypeStorage->load($node->getType()); + $node_type = $this->entityManager->getStorage('node_type')->load($node->getType()); $t_args = array('@type' => $node_type->label(), '%title' => $node->label()); $log_context = array( '@type' => $node->getType(), diff --git a/core/modules/node/src/Form/NodeFormBase.php b/core/modules/node/src/Form/NodeFormBase.php index 439b90a..df75813 100644 --- a/core/modules/node/src/Form/NodeFormBase.php +++ b/core/modules/node/src/Form/NodeFormBase.php @@ -22,13 +22,6 @@ abstract class NodeFormBase extends ContentEntityForm { /** - * The node type storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $nodeTypeStorage; - - /** * Default settings for this content/node type. * * @var array @@ -36,25 +29,6 @@ protected $settings; /** - * Constructs a NodeFormBase. - * - * @param \Drupal\Core\Entity\EntityStorageInteface - * The node type storage. - */ - public function __construct(EntityStorageInterface $node_type_storage) { - $this->nodeTypeStorage = $node_type_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager')->getStorage('node_type') - ); - } - - /** * {@inheritdoc} */ protected function prepareEntity() { diff --git a/core/modules/options/src/Tests/OptionsFieldTest.php b/core/modules/options/src/Tests/OptionsFieldTest.php index 8832326..81c893b 100644 --- a/core/modules/options/src/Tests/OptionsFieldTest.php +++ b/core/modules/options/src/Tests/OptionsFieldTest.php @@ -29,7 +29,7 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase { function testUpdateAllowedValues() { // All three options appear. $entity = entity_create('entity_test'); - $form = \Drupal::service('entity.form_builder')->getForm($entity); + $form = \Drupal::service('entity.form_builder')->getForm($entity, 'add'); $this->assertTrue(!empty($form[$this->fieldName]['widget'][1]), 'Option 1 exists'); $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists'); $this->assertTrue(!empty($form[$this->fieldName]['widget'][3]), 'Option 3 exists'); @@ -55,7 +55,7 @@ function testUpdateAllowedValues() { $this->fieldStorage->settings['allowed_values'] = array(2 => 'Two'); $this->fieldStorage->save(); $entity = entity_create('entity_test'); - $form = \Drupal::service('entity.form_builder')->getForm($entity); + $form = \Drupal::service('entity.form_builder')->getForm($entity, 'add'); $this->assertTrue(empty($form[$this->fieldName]['widget'][1]), 'Option 1 does not exist'); $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists'); $this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist'); @@ -66,7 +66,7 @@ function testUpdateAllowedValues() { // The entity holds an outdated field object with the old allowed values // setting, so we need to reintialize the entity object. $entity = entity_create('entity_test'); - $form = \Drupal::service('entity.form_builder')->getForm($entity); + $form = \Drupal::service('entity.form_builder')->getForm($entity, 'add'); $this->assertTrue(empty($form[$this->fieldName]['widget'][1]), 'Option 1 does not exist'); $this->assertTrue(empty($form[$this->fieldName]['widget'][2]), 'Option 2 does not exist'); $this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist'); @@ -87,7 +87,7 @@ function testUpdateAllowedValues() { )) ->save(); $entity = entity_create('entity_test'); - $form = \Drupal::service('entity.form_builder')->getForm($entity); + $form = \Drupal::service('entity.form_builder')->getForm($entity, 'add'); $this->assertTrue(!empty($form[$this->fieldName]['widget'][1]), 'Option 1 exists'); $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists'); $this->assertTrue(!empty($form[$this->fieldName]['widget'][3]), 'Option 3 exists'); diff --git a/core/modules/system/src/Tests/Ajax/MultiFormTest.php b/core/modules/system/src/Tests/Ajax/MultiFormTest.php index 44de1a2..2dcbcc8 100644 --- a/core/modules/system/src/Tests/Ajax/MultiFormTest.php +++ b/core/modules/system/src/Tests/Ajax/MultiFormTest.php @@ -60,8 +60,8 @@ function testMultiForm() { // desired elements. $field_name = 'field_ajax_test'; $field_xpaths = array( - 'page-node-form' => '//form[@id="page-node-form"]//div[contains(@class, "field-name-field-ajax-test")]', - 'page-node-form--2' => '//form[@id="page-node-form--2"]//div[contains(@class, "field-name-field-ajax-test")]', + 'page-node-add-form' => '//form[@id="page-node-add-form"]//div[contains(@class, "field-name-field-ajax-test")]', + 'page-node-add-form--2' => '//form[@id="page-node-add-form--2"]//div[contains(@class, "field-name-field-ajax-test")]', ); $button_name = $field_name . '_add_more'; $button_value = t('Add another item'); diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php index 246b053..5bbe653 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php @@ -74,7 +74,7 @@ function testEntityFormLanguage() { // Explicitly set form langcode. $langcode = $this->langcodes[0]; $form_state['langcode'] = $langcode; - \Drupal::service('entity.form_builder')->getForm($node, 'default', $form_state); + \Drupal::service('entity.form_builder')->getForm($node, 'add', $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/src/Tests/Form/RebuildTest.php b/core/modules/system/src/Tests/Form/RebuildTest.php index 7e5a39b..c06660d 100644 --- a/core/modules/system/src/Tests/Form/RebuildTest.php +++ b/core/modules/system/src/Tests/Form/RebuildTest.php @@ -88,7 +88,7 @@ function testPreserveFormActionAfterAJAX() { // submission and verify it worked by ensuring the updated page has two text // field items in the field for which we just added an item. $this->drupalGet('node/add/page'); - $this->drupalPostAjaxForm(NULL, array(), array('field_ajax_test_add_more' => t('Add another item')), 'system/ajax', array(), array(), 'page-node-form'); + $this->drupalPostAjaxForm(NULL, array(), array('field_ajax_test_add_more' => t('Add another item')), 'system/ajax', array(), array(), 'page-node-add-form'); $this->assert(count($this->xpath('//div[contains(@class, "field-name-field-ajax-test")]//input[@type="text"]')) == 2, 'AJAX submission succeeded.'); // Submit the form with the non-Ajax "Save" button, leaving the title field @@ -101,7 +101,7 @@ function testPreserveFormActionAfterAJAX() { // Ensure that the form contains two items in the multi-valued field, so we // know we're testing a form that was correctly retrieved from cache. - $this->assert(count($this->xpath('//form[contains(@id, "page-node-form")]//div[contains(@class, "form-item-field-ajax-test")]//input[@type="text"]')) == 2, 'Form retained its state from cache.'); + $this->assert(count($this->xpath('//form[contains(@id, "page-node-add-form")]//div[contains(@class, "form-item-field-ajax-test")]//input[@type="text"]')) == 2, 'Form retained its state from cache.'); // Ensure that the form's action is correct. $forms = $this->xpath('//form[contains(@class, "node-page-form")]'); diff --git a/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php b/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php index 600b1d9..a021892 100644 --- a/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php +++ b/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php @@ -30,8 +30,8 @@ public function twoFormInstances() { ); $node1 = $this->entityManager()->getStorage('node')->create($values); $node2 = clone($node1); - $return['node_form_1'] = $this->entityFormBuilder()->getForm($node1); - $return['node_form_2'] = $this->entityFormBuilder()->getForm($node2); + $return['node_form_1'] = $this->entityFormBuilder()->getForm($node1, 'add'); + $return['node_form_2'] = $this->entityFormBuilder()->getForm($node2, 'add'); return $return; } diff --git a/core/modules/taxonomy/src/Form/VocabularyAddForm.php b/core/modules/taxonomy/src/Form/VocabularyAddForm.php index cfaad2c..72d0b17 100644 --- a/core/modules/taxonomy/src/Form/VocabularyAddForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyAddForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $vocabulary = $this->entity; - $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); diff --git a/core/modules/taxonomy/src/Form/VocabularyEditForm.php b/core/modules/taxonomy/src/Form/VocabularyEditForm.php index a55741a..c19bd7c 100644 --- a/core/modules/taxonomy/src/Form/VocabularyEditForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyEditForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $vocabulary = $this->entity; - $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); diff --git a/core/modules/taxonomy/src/Form/VocabularyFormBase.php b/core/modules/taxonomy/src/Form/VocabularyFormBase.php index 86fdde3..82dbbfd 100644 --- a/core/modules/taxonomy/src/Form/VocabularyFormBase.php +++ b/core/modules/taxonomy/src/Form/VocabularyFormBase.php @@ -148,21 +148,6 @@ public function save(array $form, FormStateInterface $form_state) { $vocabulary = $this->entity; - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); - switch ($status) { - case SAVED_NEW: - drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); - $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); - $form_state->setRedirectUrl($vocabulary->urlInfo('overview-form')); - break; - - case SAVED_UPDATED: - drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); - $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); - $form_state->setRedirect('taxonomy.vocabulary_list'); - break; - } - $form_state->setValue('vid', $vocabulary->id()); $form_state['vid'] = $vocabulary->id(); } diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml index 1182589..549cb8e 100644 --- a/core/modules/taxonomy/taxonomy.routing.yml +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -37,7 +37,7 @@ taxonomy.term_delete: taxonomy.vocabulary_add: path: '/admin/structure/taxonomy/add' defaults: - _entity_form: 'taxonomy_vocabulary' + _entity_form: 'taxonomy_vocabulary.add' _title: 'Add vocabulary' requirements: _entity_create_access: 'taxonomy_vocabulary' @@ -45,7 +45,7 @@ taxonomy.vocabulary_add: taxonomy.vocabulary_edit: path: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}' defaults: - _entity_form: 'taxonomy_vocabulary.default' + _entity_form: 'taxonomy_vocabulary.edit' _title_callback: '\Drupal\taxonomy\Controller\TaxonomyController::vocabularyTitle' requirements: _entity_access: 'taxonomy_vocabulary.update' diff --git a/core/modules/user/src/Form/RoleAddForm.php b/core/modules/user/src/Form/RoleAddForm.php index fa06c88..ad78411 100644 --- a/core/modules/user/src/Form/RoleAddForm.php +++ b/core/modules/user/src/Form/RoleAddForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $entity = $this->entity; - $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); $this->logger('user')->notice('Role %label has been added.', array('%label' => $entity->label(), 'link' => $edit_link)); diff --git a/core/modules/user/src/Form/RoleEditForm.php b/core/modules/user/src/Form/RoleEditForm.php index d724efe..f3fe806 100644 --- a/core/modules/user/src/Form/RoleEditForm.php +++ b/core/modules/user/src/Form/RoleEditForm.php @@ -21,7 +21,7 @@ public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $entity = $this->entity; - $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + $edit_link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); $this->logger('user')->notice('Role %label has been updated.', array('%label' => $entity->label(), 'link' => $edit_link)); diff --git a/core/modules/user/src/Form/UserCancelForm.php b/core/modules/user/src/Form/UserCancelForm.php index 2dcef4e..4349660 100644 --- a/core/modules/user/src/Form/UserCancelForm.php +++ b/core/modules/user/src/Form/UserCancelForm.php @@ -118,6 +118,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ + public function actions(array $form, FormStateInterface $form_state) { + $actions = parent::actions($form, $form_state); + // Separate 'submit' and 'save' stages do not apply for this form. + // @see \Drupal\Core\Entity\EntityForm::actions() + $actions['submit']['#submit'] = array(array($this, 'submit')); + return $actions; + } + + /** + * {@inheritdoc} + */ public function submit(array $form, FormStateInterface $form_state) { // Cancel account immediately, if the current user has administrative // privileges, no confirmation mail shall be sent, and the user does not diff --git a/core/modules/user/user.routing.yml b/core/modules/user/user.routing.yml index 3363394..7df023e 100644 --- a/core/modules/user/user.routing.yml +++ b/core/modules/user/user.routing.yml @@ -94,7 +94,7 @@ user.role_list: user.role_add: path: '/admin/people/roles/add' defaults: - _entity_form: user_role.default + _entity_form: user_role.add _title: 'Add role' requirements: _permission: 'administer permissions' @@ -102,7 +102,7 @@ user.role_add: entity.user_role.edit_form: path: '/admin/people/roles/manage/{user_role}' defaults: - _entity_form: user_role.default + _entity_form: user_role.edit _title: 'Edit role' requirements: _entity_access: user_role.update diff --git a/core/modules/views/src/Tests/ViewTestBase.php b/core/modules/views/src/Tests/ViewTestBase.php index 82e42e2..45811cc 100644 --- a/core/modules/views/src/Tests/ViewTestBase.php +++ b/core/modules/views/src/Tests/ViewTestBase.php @@ -58,9 +58,9 @@ protected function enableViewsTestModule() { \Drupal::state()->set('views_test_data_views_data', $this->viewsData()); \Drupal::moduleHandler()->install(array('views_test_data')); - $this->resetAll(); - $this->rebuildContainer(); - $this->container->get('module_handler')->reload(); + // $this->resetAll(); + // $this->rebuildContainer(); + // $this->container->get('module_handler')->reload(); // Load the test dataset. $data_set = $this->dataSet(); diff --git a/core/modules/views_ui/src/ViewAddForm.php b/core/modules/views_ui/src/ViewAddForm.php index b7c2a1e..f83073f 100644 --- a/core/modules/views_ui/src/ViewAddForm.php +++ b/core/modules/views_ui/src/ViewAddForm.php @@ -181,11 +181,11 @@ public function validate(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function save(array $form, FormStateInterface $form_state) { + public function submit(array $form, FormStateInterface $form_state) { try { /** @var $wizard \Drupal\views\Plugin\views\wizard\WizardInterface */ $wizard = $form_state['wizard_instance']; - $view = $wizard->createView($form, $form_state); + $this->entity = $wizard->createView($form, $form_state); } // @todo Figure out whether it really makes sense to throw and catch exceptions on the wizard. catch (WizardException $e) { @@ -193,9 +193,15 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->setRedirect('views_ui.list'); return; } - $view->save(); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); - $form_state->setRedirectUrl($view->urlInfo('edit-form')); + $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); } /** diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 2791adb..4f100ff 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -311,8 +311,7 @@ public function submit(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - parent::save($form, $form_state); - + $view = $this->entity; $query = $this->requestStack->getCurrentRequest()->query; $destination = $query->get('destination'); @@ -338,6 +337,8 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->setRedirectUrl(Url::createFromPath($destination)); } + parent::save($form, $form_state); + drupal_set_message($this->t('The view %name has been saved.', array('%name' => $view->label()))); // Remove this view from cache so we can edit it properly.