Issue #997826 by dww, Lendude, sukanya.ramakrishnan, amar.deokar, JonMcL, larowlan, jibran, idebr: #states doesn't work correctly with type text_format

merge-requests/4973/head
catch 2021-02-08 12:43:37 +00:00
parent 5425271050
commit 722be736f5
3 changed files with 50 additions and 0 deletions

View File

@ -165,6 +165,11 @@ class TextFormat extends RenderElement {
}
}
// 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',

View File

@ -121,6 +121,15 @@ class JavascriptStatesForm extends FormBase {
],
],
];
$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'] = [

View File

@ -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 @@ class JavascriptStatesTest extends WebDriverTestBase {
$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 @@ class JavascriptStatesTest extends WebDriverTestBase {
$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 @@ class JavascriptStatesTest extends WebDriverTestBase {
$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());
}
/**