summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-10-11 22:04:13 (GMT)
committer webchick2012-10-11 22:04:13 (GMT)
commitd462cafd50d5f7cbaab61f2cd271e3a5bc1df718 (patch)
tree9e187fc7d6afadebaae52a61e4fe2f20a1bedde0
parentebe67a14baa52f96f82c01a6e9671e43cbd76990 (diff)
Issue #1742438 by larowlan, Christian Biggins, kim.pepper, dcam, Everett Zufelt, mgifford: Fixed Vertical tabs header and container rendered even when no vertical tabs.
-rw-r--r--includes/form.inc22
-rw-r--r--modules/simpletest/tests/form.test20
-rw-r--r--modules/simpletest/tests/form_test.module14
3 files changed, 52 insertions, 4 deletions
diff --git a/includes/form.inc b/includes/form.inc
index 826b677..6a1e2f7 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -3735,11 +3735,25 @@ function form_process_vertical_tabs($element, &$form_state) {
*/
function theme_vertical_tabs($variables) {
$element = $variables['element'];
- // Add required JavaScript and Stylesheet.
- drupal_add_library('system', 'drupal.vertical-tabs');
+ // Even if there are no tabs the element will still have a child element for
+ // the active tab. We need to iterate over the tabs to ascertain if any
+ // are visible before showing the wrapper and h2.
+ $visible_tab = FALSE;
+ $output = '';
+ foreach (element_children($element['group']) as $tab_index) {
+ if (!isset($element['group'][$tab_index]['#access']) ||
+ !empty($element['group'][$tab_index]['#access'])) {
+ $visible_tab = TRUE;
+ break;
+ }
+ }
+ if ($visible_tab) {
+ // Add required JavaScript and Stylesheet.
+ drupal_add_library('system', 'drupal.vertical-tabs');
- $output = '<h2 class="element-invisible">' . t('Vertical Tabs') . '</h2>';
- $output .= '<div class="vertical-tabs-panes">' . $element['#children'] . '</div>';
+ $output = '<h2 class="element-invisible">' . t('Vertical Tabs') . '</h2>';
+ $output .= '<div class="vertical-tabs-panes">' . $element['#children'] . '</div>';
+ }
return $output;
}
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index 675e8d1..08d2fca 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -930,6 +930,10 @@ class FormsElementsVerticalTabsFunctionalTest extends DrupalWebTestCase {
function setUp() {
parent::setUp('form_test');
+
+ $this->admin_user = $this->drupalCreateUser(array('access vertical_tab_test tabs'));
+ $this->web_user = $this->drupalCreateUser();
+ $this->drupalLogin($this->admin_user);
}
/**
@@ -943,6 +947,22 @@ class FormsElementsVerticalTabsFunctionalTest extends DrupalWebTestCase {
$position2 = strpos($this->content, 'misc/collapse.js');
$this->assertTrue($position1 !== FALSE && $position2 !== FALSE && $position1 < $position2, t('vertical-tabs.js is included before collapse.js'));
}
+
+ /**
+ * Ensures that vertical tab markup is not shown if user has no tab access.
+ */
+ function testWrapperNotShownWhenEmpty() {
+ // Test admin user can see vertical tabs and wrapper.
+ $this->drupalGet('form_test/vertical-tabs');
+ $wrapper = $this->xpath("//div[@class='vertical-tabs-panes']");
+ $this->assertTrue(isset($wrapper[0]), 'Vertical tab panes found.');
+
+ // Test wrapper markup not present for non-privileged web user.
+ $this->drupalLogin($this->web_user);
+ $this->drupalGet('form_test/vertical-tabs');
+ $wrapper = $this->xpath("//div[@class='vertical-tabs-panes']");
+ $this->assertFalse(isset($wrapper[0]), 'Vertical tab wrappers are not displayed to unprivileged users.');
+ }
}
/**
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module
index 5d65276..5dd1ce7 100644
--- a/modules/simpletest/tests/form_test.module
+++ b/modules/simpletest/tests/form_test.module
@@ -223,6 +223,18 @@ function form_test_menu() {
}
/**
+ * Implements hook_permission().
+ */
+function form_test_permission() {
+ $perms = array(
+ 'access vertical_tab_test tabs' => array(
+ 'title' => t('Access vertical_tab_test tabs'),
+ ),
+ );
+ return $perms;
+}
+
+/**
* Form submit handler to return form values as JSON.
*/
function _form_test_submit_values_json($form, &$form_state) {
@@ -631,6 +643,7 @@ function _form_test_vertical_tabs_form($form, &$form_state) {
'#title' => t('Tab 1'),
'#collapsible' => TRUE,
'#group' => 'vertical_tabs',
+ '#access' => user_access('access vertical_tab_test tabs')
);
$form['tab1']['field1'] = array(
'#title' => t('Field 1'),
@@ -641,6 +654,7 @@ function _form_test_vertical_tabs_form($form, &$form_state) {
'#title' => t('Tab 2'),
'#collapsible' => TRUE,
'#group' => 'vertical_tabs',
+ '#access' => user_access('access vertical_tab_test tabs')
);
$form['tab2']['field2'] = array(
'#title' => t('Field 2'),