summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-08-31 15:41:54 +0100
committerAlex Pott2015-08-31 15:41:54 +0100
commitce45b6e2aad9968fad361e1c99377a0f6589cde6 (patch)
treea402b2527bfe6d013eab9ab63ef977438727e28a
parent7365cd41c3cdc54db64d89848e9c9f35e4de3c5e (diff)
Issue #1611954 by tim.plunkett, sun, samuel.mortenson, Berdir, mgifford, chx: Setting #access = FALSE on a vertical tab does not prevent input processing of the contained form elements
-rw-r--r--core/lib/Drupal/Core/Render/Element/VerticalTabs.php4
-rw-r--r--core/modules/system/src/Tests/Form/ElementsAccessTest.php40
-rw-r--r--core/modules/system/tests/modules/form_test/form_test.module11
-rw-r--r--core/modules/system/tests/modules/form_test/form_test.routing.yml8
-rw-r--r--core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsAccessForm.php136
5 files changed, 199 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/Render/Element/VerticalTabs.php b/core/lib/Drupal/Core/Render/Element/VerticalTabs.php
index 4c40aa7..adf6bd0 100644
--- a/core/lib/Drupal/Core/Render/Element/VerticalTabs.php
+++ b/core/lib/Drupal/Core/Render/Element/VerticalTabs.php
@@ -71,6 +71,10 @@ class VerticalTabs extends RenderElement {
* The processed element.
*/
public static function processVerticalTabs(&$element, FormStateInterface $form_state, &$complete_form) {
+ if (isset($element['#access']) && !$element['#access']) {
+ return $element;
+ }
+
// Inject a new details as child, so that form_process_details() processes
// this details element like any other details.
$element['group'] = array(
diff --git a/core/modules/system/src/Tests/Form/ElementsAccessTest.php b/core/modules/system/src/Tests/Form/ElementsAccessTest.php
new file mode 100644
index 0000000..478f500
--- /dev/null
+++ b/core/modules/system/src/Tests/Form/ElementsAccessTest.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\system\Tests\Form\ElementsAccessTest.
+ */
+
+namespace Drupal\system\Tests\Form;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests access control for form elements.
+ *
+ * @group Form
+ */
+class ElementsAccessTest extends WebTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('form_test');
+
+ /**
+ * Ensures that child values are still processed when #access = FALSE.
+ */
+ public function testAccessFalse() {
+ $this->drupalPostForm('form_test/vertical-tabs-access', NULL, t('Submit'));
+ $this->assertNoText(t('This checkbox inside a vertical tab does not have its default value.'));
+ $this->assertNoText(t('This textfield inside a vertical tab does not have its default value.'));
+ $this->assertNoText(t('This checkbox inside a fieldset does not have its default value.'));
+ $this->assertNoText(t('This checkbox inside a container does not have its default value.'));
+ $this->assertNoText(t('This checkbox inside a nested container does not have its default value.'));
+ $this->assertNoText(t('This checkbox inside a vertical tab whose fieldset access is allowed does not have its default value.'));
+ $this->assertText(t('The form submitted correctly.'));
+ }
+
+}
diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module
index 2a970a2..ee4c137 100644
--- a/core/modules/system/tests/modules/form_test/form_test.module
+++ b/core/modules/system/tests/modules/form_test/form_test.module
@@ -93,3 +93,14 @@ function form_test_user_register_form_rebuild($form, FormStateInterface $form_st
drupal_set_message('Form rebuilt.');
$form_state->setRebuild();
}
+
+/**
+ * Implements hook_form_FORM_ID_alter() for form_test_vertical_tabs_access_form().
+ */
+function form_test_form_form_test_vertical_tabs_access_form_alter(&$form, &$form_state, $form_id) {
+ $form['vertical_tabs1']['#access'] = FALSE;
+ $form['vertical_tabs2']['#access'] = FALSE;
+ $form['tabs3']['#access'] = TRUE;
+ $form['fieldset1']['#access'] = FALSE;
+ $form['container']['#access'] = FALSE;
+}
diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml
index 8a200a3..82243fa 100644
--- a/core/modules/system/tests/modules/form_test/form_test.routing.yml
+++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml
@@ -172,6 +172,14 @@ form_test.storage:
requirements:
_access: 'TRUE'
+form_test.vertical_tabs_access:
+ path: '/form_test/vertical-tabs-access'
+ defaults:
+ _form: '\Drupal\form_test\Form\FormTestVerticalTabsAccessForm'
+ _title: 'Vertical tabs tests'
+ requirements:
+ _access: 'TRUE'
+
form_test.state_clean:
path: '/form_test/form-state-values-clean'
defaults:
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsAccessForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsAccessForm.php
new file mode 100644
index 0000000..0f3a2cc
--- /dev/null
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsAccessForm.php
@@ -0,0 +1,136 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\form_test\Form\FormTestVerticalTabsAccessForm.
+ */
+
+namespace Drupal\form_test\Form;
+
+use Drupal\Core\Form\FormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+class FormTestVerticalTabsAccessForm extends FormBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getFormId() {
+ return 'form_test_vertical_tabs_access_form';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildForm(array $form, FormStateInterface $form_state) {
+ $form['vertical_tabs1'] = array(
+ '#type' => 'vertical_tabs',
+ );
+ $form['tab1'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Tab 1'),
+ '#collapsible' => TRUE,
+ '#group' => 'vertical_tabs1',
+ );
+ $form['tab1']['field1'] = array(
+ '#title' => t('Field 1'),
+ '#type' => 'checkbox',
+ '#default_value' => TRUE,
+ );
+ $form['tab2'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Tab 2'),
+ '#collapsible' => TRUE,
+ '#group' => 'vertical_tabs1',
+ );
+ $form['tab2']['field2'] = array(
+ '#title' => t('Field 2'),
+ '#type' => 'textfield',
+ '#default_value' => 'field2',
+ );
+
+ $form['fieldset1'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Fieldset'),
+ );
+ $form['fieldset1']['field3'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Field 3'),
+ '#default_value' => TRUE,
+ );
+
+ $form['container'] = array(
+ '#type' => 'container',
+ );
+ $form['container']['field4'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Field 4'),
+ '#default_value' => TRUE,
+ );
+ $form['container']['subcontainer'] = array(
+ '#type' => 'container',
+ );
+ $form['container']['subcontainer']['field5'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Field 5'),
+ '#default_value' => TRUE,
+ );
+
+ $form['vertical_tabs2'] = array(
+ '#type' => 'vertical_tabs',
+ );
+ $form['tab3'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Tab 3'),
+ '#collapsible' => TRUE,
+ '#group' => 'vertical_tabs2',
+ );
+ $form['tab3']['field6'] = array(
+ '#title' => t('Field 6'),
+ '#type' => 'checkbox',
+ '#default_value' => TRUE,
+ );
+
+ $form['actions'] = array(
+ '#type' => 'actions',
+ );
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ );
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ $values = $form_state->getValues();
+ if (empty($values['field1'])) {
+ $form_state->setErrorByName('tab1][field1', t('This checkbox inside a vertical tab does not have its default value.'));
+ }
+ if ($values['field2'] != 'field2') {
+ $form_state->setErrorByName('tab2][field2', t('This textfield inside a vertical tab does not have its default value.'));
+ }
+ if (empty($values['field3'])) {
+ $form_state->setErrorByName('fieldset][field3', t('This checkbox inside a fieldset does not have its default value.'));
+ }
+ if (empty($values['field4'])) {
+ $form_state->setErrorByName('container][field4', t('This checkbox inside a container does not have its default value.'));
+ }
+ if (empty($values['field5'])) {
+ $form_state->setErrorByName('container][subcontainer][field5', t('This checkbox inside a nested container does not have its default value.'));
+ }
+ if (empty($values['field5'])) {
+ $form_state->setErrorByName('tab3][field6', t('This checkbox inside a vertical tab whose fieldset access is allowed does not have its default value.'));
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ drupal_set_message(t('The form submitted correctly.'));
+ }
+
+}