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

Issue #3002571 by johnchque, Berdir, kishor_kolekar, ravi.shankar, Anandhi...

Issue #3002571 by johnchque, Berdir, kishor_kolekar, ravi.shankar, Anandhi Karnan, StephaneQ, alexpott, smustgrave: Multiple warning messages when having untranslatable fields
parent 3041dbfe
No related branches found
No related tags found
43 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,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!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,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!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
......@@ -629,9 +629,21 @@ public function entityFormSharedElements($element, FormStateInterface $form_stat
}
}
if ($display_warning && !$form_state->isSubmitted() && !$form_state->isRebuilding()) {
if ($display_warning) {
$url = $entity->getUntranslated()->toUrl('edit-form')->toString();
$this->messenger->addWarning($this->t('Fields that apply to all languages are hidden to avoid conflicting changes. <a href=":url">Edit them on the original language form</a>.', [':url' => $url]));
$message['warning'][] = $this->t('Fields that apply to all languages are hidden to avoid conflicting changes. <a href=":url">Edit them on the original language form</a>.', [':url' => $url]);
// Explicitly renders this warning message. This prevents repetition on
// AJAX operations or form submission. Other messages will be rendered in
// the default location.
// @see \Drupal\Core\Render\Element\StatusMessages.
$element['hidden_fields_warning_message'] = [
'#theme' => 'status_messages',
'#message_list' => $message,
'#weight' => -100,
'#status_headings' => [
'warning' => $this->t('Warning message'),
],
];
}
return $element;
......
......@@ -176,6 +176,13 @@ public function testHiddenWidgets() {
$this->submitForm([$settings_key => 0], 'Save configuration');
$this->assertSession()->fieldValueEquals($field_name, 1);
$this->assertSession()->fieldDisabled($field_name);
// Verify that the untranslatable fields warning message is not displayed
// when submitting.
$this->drupalGet($it_edit_url);
$this->assertSession()->pageTextContains('Fields that apply to all languages are hidden to avoid conflicting changes.');
$this->submitForm([], 'Save (this translation)');
$this->assertSession()->pageTextNotContains('Fields that apply to all languages are hidden to avoid conflicting changes.');
}
}
......@@ -93,21 +93,15 @@ protected function setUp(): void {
* Whether or not the entity is the default translation.
* @param bool $translation_form
* Whether or not the form is a translation form.
* @param bool $is_submitted
* Whether or not the form should be marked as submitted.
* @param bool $is_rebuilding
* Whether or not the form should be flagged for rebuild.
* @param array $expected
* The expected altered element.
* @param bool $display_warning
* Whether or not the warning message should be displayed.
*
* @dataProvider providerTestEntityFormSharedElements
*
* @covers ::entityFormSharedElements
* @covers ::addTranslatabilityClue
*/
public function testEntityFormSharedElements(array $element, $default_translation_affected, $default_translation, $translation_form, $is_submitted, $is_rebuilding, array $expected, $display_warning) {
public function testEntityFormSharedElements(array $element, $default_translation_affected, $default_translation, $translation_form, array $expected) {
$this->state->set('entity_test.translation', TRUE);
$this->state->set('entity_test.untranslatable_fields.default_translation_affected', $default_translation_affected);
$this->entityTypeBundleInfo->clearCachedBundles();
......@@ -126,21 +120,11 @@ public function testEntityFormSharedElements(array $element, $default_translatio
$form_state
->addBuildInfo('callback_object', $form_object)
->set(['content_translation', 'translation_form'], $translation_form);
if ($is_submitted) {
$form_state->setSubmitted();
}
$form_state->setRebuild($is_rebuilding);
$handler = $this->entityTypeManager->getHandler($this->entityTypeId, 'translation');
$actual = $handler->entityFormSharedElements($element, $form_state, $element);
$this->assertEquals($expected, $actual);
if ($display_warning) {
$messages = $this->messenger->messagesByType('warning');
$this->assertCount(1, $messages);
$expected_message = sprintf('Fields that apply to all languages are hidden to avoid conflicting changes. <a href="%s">Edit them on the original language form</a>.', $entity->toUrl('edit-form')->toString());
$this->assertSame($expected_message, (string) reset($messages));
}
}
/**
......@@ -159,10 +143,7 @@ public function providerTestEntityFormSharedElements() {
'default_translation_affected' => TRUE,
'default_translation' => TRUE,
'translation_form' => FALSE,
'is_submitted' => TRUE,
'is_rebuilding' => TRUE,
'expected' => $element,
'display_warning' => FALSE,
];
$element = [
......@@ -226,6 +207,16 @@ public function providerTestEntityFormSharedElements() {
'name' => [
'#type' => 'textfield',
],
'hidden_fields_warning_message' => [
'#theme' => 'status_messages',
'#message_list' => [
'warning' => [t('Fields that apply to all languages are hidden to avoid conflicting changes. <a href=":url">Edit them on the original language form</a>.')],
],
'#weight' => -100,
'#status_headings' => [
'warning' => t('Warning message'),
],
],
];
$expected = $element;
$expected['name']['#access'] = FALSE;
......@@ -233,13 +224,6 @@ public function providerTestEntityFormSharedElements() {
$tests['hide-untranslatable']['element'] = $element;
$tests['hide-untranslatable']['expected'] = $expected;
$tests['is-rebuilding'] = $tests['hide-untranslatable'];
$tests['is-rebuilding']['is_submitted'] = FALSE;
$tests['display-warning'] = $tests['is-rebuilding'];
$tests['display-warning']['is_rebuilding'] = FALSE;
$tests['display-warning']['display_warning'] = TRUE;
$tests['no-translation-form'] = $tests['no-translatability-clue'];
$tests['no-translation-form']['translation_form'] = FALSE;
......
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