Skip to content
Snippets Groups Projects
Verified Commit 64e10dfa authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3365229 by narendraR, lauriii, bnjmnm, Chris Matthews, yoroy, ckrina,...

Issue #3365229 by narendraR, lauriii, bnjmnm, Chris Matthews, yoroy, ckrina, hooroomoo: Add separate 'Save' and 'Save and add fields' to Add Content, Comment, Media and Block Type Forms
parent b5bff583
No related branches found
No related tags found
41 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4594Applying patch for Views Global Text area field to allow extra HTML tags. As video, source and iframe tag is not rendering. Due to which Media embedded video and remote-video not rendering in Views Global Text area field.,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3546refactored dialog.pcss file,!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3502Issue #3335308: Confusing behavior with FormState::setFormState and FormState::setMethod,!3452Issue #3332701: Refactor Claro's tablesort-indicator stylesheet,!3451Issue #2410579: Allows setting the current language programmatically.,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!31312878513-10.1.x,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!673Issue #3214208: FinishResponseSubscriber could create duplicate headers,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
Showing
with 107 additions and 63 deletions
......@@ -86,7 +86,11 @@ public function testBlockContentTypeCreation() {
'id' => 'foo',
'label' => 'title for foo',
];
$this->submitForm($edit, 'Save');
$this->submitForm($edit, 'Save and manage fields');
// Asserts that form submit redirects to the expected manage fields page.
$this->assertSession()->addressEquals('admin/structure/block-content/manage/' . $edit['id'] . '/fields');
$block_type = BlockContentType::load('foo');
$this->assertInstanceOf(BlockContentType::class, $block_type);
......
......@@ -69,7 +69,7 @@ protected function setUp(): void {
// Set "Article" content type to use multilingual support.
$edit = ['language_configuration[language_alterable]' => TRUE];
$this->drupalGet('admin/structure/types/manage/article');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
// Enable content language negotiation UI.
\Drupal::state()->set('language_test.content_language_type', TRUE);
......
......@@ -76,7 +76,11 @@ public function testCommentTypeCreation() {
'target_entity_type_id' => 'node',
];
$this->drupalGet('admin/structure/comment/types/add');
$this->submitForm($edit, 'Save');
$this->submitForm($edit, 'Save and manage fields');
// Asserts that form submit redirects to the expected manage fields page.
$this->assertSession()->addressEquals('admin/structure/comment/manage/' . $edit['id'] . '/fields');
$comment_type = CommentType::load('foo');
$this->assertInstanceOf(CommentType::class, $comment_type);
......
......@@ -112,7 +112,7 @@ public function testEnforceRevisionsEntityFormAlter() {
// Ensure checkboxes in the 'workflow' section can be altered, even when
// 'revision' is enforced and disabled.
$this->drupalGet('admin/structure/types/manage/moderated');
$this->submitForm(['options[promote]' => TRUE], 'Save content type');
$this->submitForm(['options[promote]' => TRUE], 'Save');
$this->drupalGet('admin/structure/types/manage/moderated');
$this->assertSession()->checkboxChecked('options[promote]');
}
......
......@@ -116,7 +116,7 @@ protected function createContentTypeFromUi($content_type_name, $content_type_id,
'name' => $content_type_name,
'type' => $content_type_id,
];
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
// Check the content type has been set to create new revisions.
$this->assertTrue(NodeType::load($content_type_id)->shouldCreateNewRevision());
......
......@@ -68,7 +68,7 @@ public function testEnable() {
'type' => 'foo',
];
$this->drupalGet('admin/structure/types/add');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
$this->drupalGet('admin/config/regional/content-language');
$this->assertSession()->responseContains('entity_types[node]');
}
......
......@@ -47,7 +47,7 @@ public function testContentTypeUI() {
// Enable content translation.
$edit = ['language_configuration[content_translation]' => TRUE];
$this->drupalGet('admin/structure/types/manage/article');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
// Make sure add page does not inherit translation configuration from first
// content type.
......
......@@ -174,7 +174,7 @@ public function testSettingsUI() {
$this->assertSession()->fieldExists('language_configuration[content_translation]');
$this->assertSession()->checkboxNotChecked('edit-language-configuration-content-translation');
$this->drupalGet('admin/structure/types/manage/article');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
$this->drupalGet('admin/structure/types/manage/article');
$this->assertSession()->checkboxChecked('edit-language-configuration-content-translation');
......@@ -217,7 +217,7 @@ public function testSettingsUI() {
'language_configuration[content_translation]' => TRUE,
];
$this->drupalGet('admin/structure/types/manage/article');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
$this->getSession()->getPage()->hasContent('"Show language selector" is not compatible with translating content that has default language: und. Either do not hide the language selector or pick a specific language.');
// Test that the order of the language list is similar to other language
......
......@@ -123,26 +123,6 @@ function field_ui_entity_bundle_create($entity_type, $bundle) {
\Drupal::service('router.builder')->setRebuildNeeded();
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Adds a button 'Save and manage fields' to the 'Create content type' form.
*
* @see \Drupal\node\NodeTypeForm
* @see field_ui_form_node_type_form_submit()
*/
function field_ui_form_node_type_form_alter(&$form, FormStateInterface $form_state) {
// We want to display the button only on add page.
if ($form_state->getFormObject()->getEntity()->isNew()) {
$form['actions']['save_continue'] = $form['actions']['submit'];
$form['actions']['save_continue']['#value'] = t('Save and manage fields');
$form['actions']['save_continue']['#weight'] = $form['actions']['save_continue']['#weight'] + 5;
$form['actions']['save_continue']['#submit'][] = 'field_ui_form_node_type_form_submit';
// Hide the 'Save content type' button.
$form['actions']['submit']['#access'] = FALSE;
}
}
/**
* Implements hook_entity_operation().
*/
......@@ -185,17 +165,6 @@ function field_ui_entity_operation(EntityInterface $entity) {
return $operations;
}
/**
* Form submission handler for the 'Save and manage fields' button.
*
* @see field_ui_form_node_type_form_alter()
*/
function field_ui_form_node_type_form_submit($form, FormStateInterface $form_state) {
if ($form_state->getTriggeringElement()['#parents'][0] === 'save_continue' && $route_info = FieldUI::getOverviewRouteInfo('node', $form_state->getValue('type'))) {
$form_state->setRedirectUrl($route_info);
}
}
/**
* Implements hook_entity_view_mode_presave().
*/
......@@ -285,3 +254,47 @@ function field_ui_preprocess_form_element__new_storage_type(&$variables) {
// programmatically distinguished.
$variables['variant'] = $variables['element']['#variant'] ?? NULL;
}
/**
* Implements hook_form_alter().
*
* Adds a button 'Save and manage fields' to forms.
*
* @see \Drupal\node\NodeTypeForm
* @see \Drupal\comment\CommentTypeForm
* @see \Drupal\media\MediaTypeForm
* @see \Drupal\block_content\BlockContentTypeForm
* @see field_ui_form_manage_field_form_submit()
*/
function field_ui_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$forms = [
'node_type_add_form',
'comment_type_add_form',
'media_type_add_form',
'block_content_type_add_form',
];
if (!in_array($form_id, $forms)) {
return;
}
if ($form_state->getFormObject()->getEntity()->isNew()) {
$form['actions']['save_continue'] = $form['actions']['submit'];
unset($form['actions']['submit']['#button_type']);
$form['actions']['save_continue']['#value'] = t('Save and manage fields');
$form['actions']['save_continue']['#weight'] = $form['actions']['save_continue']['#weight'] - 5;
$form['actions']['save_continue']['#submit'][] = 'field_ui_form_manage_field_form_submit';
}
}
/**
* Form submission handler for the 'Save and manage fields' button.
*
* @see field_ui_form_alter()
*/
function field_ui_form_manage_field_form_submit($form, FormStateInterface $form_state) {
$provider = $form_state->getFormObject()->getEntity()->getEntityType()->getProvider();
$id = $form_state->getFormObject()->getEntity()->id();
if ($form_state->getTriggeringElement()['#parents'][0] === 'save_continue' && $route_info = FieldUI::getOverviewRouteInfo($provider, $id)) {
$form_state->setRedirectUrl($route_info);
}
}
......@@ -230,7 +230,7 @@ public function testForum() {
'post comments',
]));
$this->drupalGet('admin/structure/types/manage/forum');
$this->submitForm(['options[promote]' => 'promote'], 'Save content type');
$this->submitForm(['options[promote]' => 'promote'], 'Save');
$this->createForumTopic($this->forum, FALSE);
$this->createForumTopic($this->forum, FALSE);
$this->drupalGet('node');
......
......@@ -121,7 +121,7 @@ public function testForumUninstallWithField() {
'type' => 'forum',
];
$this->drupalGet('admin/structure/types/add');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
$this->assertTrue((bool) NodeType::load('forum'), 'Node type with machine forum created.');
$this->drupalGet('admin/structure/types/manage/forum');
$this->clickLink('Delete');
......
......@@ -15,5 +15,5 @@ related:
<li>{% trans %}Locate the content type you want to configure, and click <em>Edit</em> in the <em>Operations</em> list.{% endtrans %}</li>
<li>{% trans %}Under <em>Menu settings</em>, check the menus that you want to be available when editing a content item of this type.{% endtrans %}</li>
<li>{% trans %}Optionally, select the <em>Default parent item</em>, to put links to content items under a default location in the menu structure.{% endtrans %}</li>
<li>{% trans %}Click <em>Save content type</em>.{% endtrans %}</li>
<li>{% trans %}Click <em>Save</em>.{% endtrans %}</li>
</ol>
......@@ -182,7 +182,7 @@ public function testNodeTypeUpdate() {
'language_configuration[language_alterable]' => TRUE,
];
$this->drupalGet('admin/structure/types/manage/article');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
// Check the language default configuration for the articles.
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article');
$uuid = $configuration->uuid();
......@@ -193,7 +193,7 @@ public function testNodeTypeUpdate() {
'title_label' => 'Name',
];
$this->drupalGet('admin/structure/types/manage/article');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
// Check that we still have the settings for the updated node type.
$configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', 'article');
$this->assertEquals('current_interface', $configuration->getDefaultLangcode(), 'The default language configuration has been kept on the updated Article content type.');
......@@ -222,7 +222,7 @@ public function testNodeTypeDelete() {
'language_configuration[language_alterable]' => TRUE,
];
$this->drupalGet('admin/structure/types/manage/article');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
// Check the language default configuration for articles is present.
$configuration = \Drupal::entityTypeManager()->getStorage('language_content_settings')->load('node.article');
......
......@@ -105,7 +105,7 @@ public function testContentTypeLanguageConfiguration() {
'language_configuration[language_alterable]' => TRUE,
];
$this->drupalGet("admin/structure/types/manage/{$type2->id()}");
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
$this->assertSession()->pageTextContains("The content type {$type2->label()} has been updated.");
$this->drupalLogout();
\Drupal::languageManager()->reset();
......@@ -194,7 +194,7 @@ public function testContentTypeDirLang() {
'language_configuration[language_alterable]' => TRUE,
];
$this->drupalGet("admin/structure/types/manage/{$type->id()}");
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
$this->assertSession()->pageTextContains("The content type {$type->label()} has been updated.");
$this->drupalLogout();
......
......@@ -25,23 +25,42 @@ class MediaTypeCreationTest extends MediaFunctionalTestBase {
/**
* Tests the media type creation form with only the mandatory options.
*
* @dataProvider providerMediaTypeCreationForm
*/
public function testMediaTypeCreationForm() {
$machine_name = mb_strtolower($this->randomMachineName());
public function testMediaTypeCreationForm($button_label, $address, $machine_name) {
$this->drupalGet('/admin/structure/media/add');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldExists('label')->setValue($this->randomString());
$this->assertSession()->fieldExists('id')->setValue($machine_name);
$this->assertSession()->selectExists('source')->selectOption('test');
$this->assertSession()->buttonExists('Save')->press();
$this->assertSession()->buttonExists($button_label)->press();
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldValueEquals('Test config value', 'This is default value.');
$this->assertSession()->buttonExists('Save')->press();
$this->assertSession()->buttonExists($button_label)->press();
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->addressEquals('admin/structure/media');
$this->assertSession()->addressEquals($address);
$this->assertInstanceOf(MediaType::class, MediaType::load($machine_name));
}
/**
* Data provider for testMediaTypeCreationForm().
*/
public function providerMediaTypeCreationForm() {
$machine_name = mb_strtolower($this->randomMachineName());
return [
[
'Save',
'admin/structure/media',
$machine_name,
],
[
'Save and manage fields',
'admin/structure/media/manage/' . $machine_name . '/fields',
$machine_name,
],
];
}
}
......@@ -67,11 +67,11 @@ public function testMediaTypes() {
$page->selectFieldOption('source', 'test');
$this->assertJsCondition("jQuery('.form-item-source-configuration-test-config-value').length > 0");
$page->fillField('description', $description);
$page->pressButton('Save');
$page->pressButton('Save and manage fields');
// The wait prevents intermittent test failures.
$result = $assert_session->waitForLink('Add media type');
$result = $assert_session->waitForLink('Create a new field');
$this->assertNotEmpty($result);
$assert_session->addressEquals('admin/structure/media');
$assert_session->addressEquals('admin/structure/media/manage/' . $machine_name . '/fields');
$assert_session->pageTextContains('The media type ' . $name . ' has been added.');
$this->drupalGet('admin/structure/media');
$assert_session->pageTextContains($name);
......
......@@ -624,7 +624,7 @@ protected function createMediaTypeViaForm($source_plugin_id, $field_name) {
$form_state->setValues([
'label' => 'Test type',
'id' => $source_plugin_id,
'op' => 'Save',
'op' => 'Save and manage fields',
]);
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
......
......@@ -297,6 +297,10 @@ function media_library_form_alter(array &$form, FormStateInterface $form_state,
// Configures media_library displays when a type is submitted.
if ($form_state->getFormObject() instanceof MediaTypeForm) {
$form['actions']['submit']['#submit'][] = '_media_library_media_type_form_submit';
// @see field_ui_form_alter()
if (isset($form['actions']['save_continue'])) {
$form['actions']['save_continue']['#submit'][] = '_media_library_media_type_form_submit';
}
}
}
......
......@@ -112,8 +112,8 @@ public function testDisplayModes() {
'source' => 'file',
];
$this->drupalGet('admin/structure/media/add');
$this->submitForm($edit, 'Save');
$this->submitForm([], 'Save');
$this->submitForm($edit, 'Save and manage fields');
$this->submitForm([], 'Save and manage fields');
$this->assertSession()->pageTextContains("Media Library form and view displays have been created for the $type_five_id media type.");
$this->assertFormDisplay($type_five_id, TRUE, FALSE);
$this->assertViewDisplay($type_five_id, 'medium');
......
......@@ -98,7 +98,7 @@ public function testMenuNodeFormWidget() {
'menu_options[main]' => FALSE,
];
$this->drupalGet('admin/structure/types/manage/page');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
// Verify that no menu settings are displayed and nodes can be created.
$this->drupalGet('node/add/page');
......@@ -120,7 +120,7 @@ public function testMenuNodeFormWidget() {
'menu_parent' => 'main:',
];
$this->drupalGet('admin/structure/types/manage/page');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
$this->assertSession()->pageTextContains('The selected menu link is not under one of the selected menus.');
$this->assertSession()->pageTextNotContains("The content type Basic page has been updated.");
......@@ -131,7 +131,7 @@ public function testMenuNodeFormWidget() {
'menu_parent' => 'main:',
];
$this->drupalGet('admin/structure/types/manage/page');
$this->submitForm($edit, 'Save content type');
$this->submitForm($edit, 'Save');
$this->assertSession()->pageTextContains("The content type Basic page has been updated.");
// Test that we can preview a node that will create a menu item.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment