Skip to content
Snippets Groups Projects
Commit 722be736 authored by catch's avatar catch
Browse files

Issue #997826 by dww, Lendude, sukanya.ramakrishnan, amar.deokar, JonMcL,...

Issue #997826 by dww, Lendude, sukanya.ramakrishnan, amar.deokar, JonMcL, larowlan, jibran, idebr: #states doesn't work correctly with type text_format
parent 54252710
Branches
Tags
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!16Draft: Resolve #2081585 "History storage"
......@@ -165,6 +165,11 @@ public static function processFormat(&$element, FormStateInterface $form_state,
}
}
// If the value element has #states set, copy it to the format element.
if (isset($element['value']['#states'])) {
$element['format']['#states'] = $element['value']['#states'];
}
// Prepare text format guidelines.
$element['format']['guidelines'] = [
'#type' => 'container',
......
......@@ -121,6 +121,15 @@ public function buildForm(array $form, FormStateInterface $form_state) {
],
],
];
$form['text_format_invisible_when_checkbox_trigger_checked'] = [
'#type' => 'text_format',
'#title' => 'Text format invisible when checkbox trigger checked',
'#states' => [
'invisible' => [
':input[name="checkbox_trigger"]' => ['checked' => TRUE],
],
],
];
// Checkboxes trigger.
$form['textfield_visible_when_checkboxes_trigger_value2_checked'] = [
......
......@@ -2,6 +2,7 @@
namespace Drupal\FunctionalJavascriptTests\Core\Form;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
......@@ -21,6 +22,33 @@ class JavascriptStatesTest extends WebDriverTestBase {
*/
protected static $modules = ['form_test'];
/**
* {@inheritdoc}
*/
protected function setUp():void {
parent::setUp();
// Add text formats.
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => [],
]);
$filtered_html_format->save();
$full_html_format = FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => [],
]);
$full_html_format->save();
$normal_user = $this->drupalCreateUser([
'use text format filtered_html',
'use text format full_html',
]);
$this->drupalLogin($normal_user);
}
/**
* Tests the JavaScript #states functionality of form elements.
*
......@@ -60,6 +88,10 @@ protected function doCheckboxTriggerTests() {
$this->assertNotEmpty($checkbox_unchecked_element);
$checkbox_visible_element = $page->findField('checkbox_visible_when_checkbox_trigger_checked');
$this->assertNotEmpty($checkbox_visible_element);
$text_format_invisible_value = $page->findField('text_format_invisible_when_checkbox_trigger_checked[value]');
$this->assertNotEmpty($text_format_invisible_value);
$text_format_invisible_format = $page->findField('text_format_invisible_when_checkbox_trigger_checked[format]');
$this->assertNotEmpty($text_format_invisible_format);
// Verify initial state.
$this->assertTrue($textfield_invisible_element->isVisible());
......@@ -69,6 +101,8 @@ protected function doCheckboxTriggerTests() {
$this->assertFalse($checkbox_checked_element->isChecked());
$this->assertTrue($checkbox_unchecked_element->isChecked());
$this->assertFalse($checkbox_visible_element->isVisible());
$this->assertTrue($text_format_invisible_value->isVisible());
$this->assertTrue($text_format_invisible_format->isVisible());
// Change state: check the checkbox.
$trigger->check();
......@@ -80,6 +114,8 @@ protected function doCheckboxTriggerTests() {
$this->assertTrue($checkbox_checked_element->isChecked());
$this->assertFalse($checkbox_unchecked_element->isChecked());
$this->assertTrue($checkbox_visible_element->isVisible());
$this->assertFalse($text_format_invisible_value->isVisible());
$this->assertFalse($text_format_invisible_format->isVisible());
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment