diff --git a/nodewords.admin.inc b/nodewords.admin.inc index ecd399a..f446237 100644 --- a/nodewords.admin.inc +++ b/nodewords.admin.inc @@ -249,10 +249,20 @@ function nodewords_custom_pages_edit_submit($form, &$form_state) { */ function nodewords_settings_form() { $edit_tags = variable_get('nodewords_edit', array()); + $disabled_tags = variable_get('nodewords_disabled', array()); $form = array(); $options = array(); + $options_all = array(); $tags_info = nodewords_get_possible_tags(); + $all_tags_info = nodewords_get_possible_tags(TRUE, TRUE); + if (!empty($all_tags_info)) { + foreach ($all_tags_info as $name => $info) { + $options_all[$name] = $info['label']; + } + + uasort($options_all, 'strnatcmp'); + } if (!empty($tags_info)) { foreach ($tags_info as $name => $info) { $options[$name] = $info['label']; @@ -260,7 +270,19 @@ function nodewords_settings_form() { uasort($options, 'strnatcmp'); } - + $form['disabled'] = array( + '#type' => 'fieldset', + '#title' => t('Disabled meta tags'), + '#description' => t('Select meta tags to disable.'), + '#collapsible' => TRUE, + '#group' => 'nodewords', + ); + $form['disabled']['nodewords_disabled'] = array( + '#type' => 'checkboxes', + '#options' => $options_all, + '#default_value' => $disabled_tags, + '#checkall' => TRUE, + ); $form['edit'] = array( '#type' => 'fieldset', '#title' => t('Meta tags to show on edit forms'), diff --git a/nodewords.install b/nodewords.install index 9833f4c..802661a 100644 --- a/nodewords.install +++ b/nodewords.install @@ -185,6 +185,7 @@ function nodewords_uninstall() { variable_del('nodewords_use_frontpage_tags'); variable_del('nodewords_use_path_alias'); variable_del('nodewords_use_teaser'); + variable_del('nodewords_disabled'); $node_types = array_keys(node_get_types('names')); $variables = array( diff --git a/nodewords.module b/nodewords.module index 4cf678b..9d35cb6 100644 --- a/nodewords.module +++ b/nodewords.module @@ -841,13 +841,16 @@ function nodewords_form($type, $tags, $options = array()) { /** * Query all the modules implementing meta tags and return the list of meta tags. * - * @param $load + * @param bool $load * If TRUE, the file containing the code implementing the meta tags will be loaded. * - * @return + * @param bool $show_disabled + * If TRUE, loads disabled tags. + * + * @return array * An array containing the list of meta tags definitions. */ -function nodewords_get_possible_tags($load = FALSE) { +function nodewords_get_possible_tags($load = FALSE, $show_disabled = FALSE) { static $tags_info = array(); if ($load) { @@ -898,6 +901,10 @@ function nodewords_get_possible_tags($load = FALSE) { } } } + if (!$show_disabled) { + $allowed_tags = array_filter(variable_get('nodewords_disabled', array())); + $tags_info = array_diff_key($tags_info, $allowed_tags); + } return $tags_info; } diff --git a/nodewords.test b/nodewords.test index 1e4b15f..98a6ccc 100644 --- a/nodewords.test +++ b/nodewords.test @@ -105,6 +105,60 @@ class NodewordsFunctionalityTestCase extends DrupalWebTestCase { } +/** + * Nodewords tag disable Test Case implementation. + */ +class NodewordsTagDisableTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Nodewords tag disabletest', + 'description' => 'Test nodewords meta tags disable functionality.', + 'group' => 'nodewords' + ); + } + + function setUp() { + // Enable minimum required modules. + parent::setUp('nodewords', 'nodewords_basic'); + } + + /** + * Verify the meta tags disabled functionality. + */ + function testDisabledTags() { + // Create an administrator user. + $permissions = array( + 'administer content types', + 'administer meta tags', + 'administer search', + 'administer site configuration' + ); + $admin_user = $this->drupalCreateUser($permissions); + // Log in to Drupal using the administrator user. + $this->drupalLogin($admin_user); + $this->drupalGet('admin/content/nodewords'); + + // Make sure abstract meta tag is not disabled by default. + $this->assertField('nodewords_edit[abstract]'); + + // Disable abstract meta tag. + $edit = array( + 'nodewords_disabled[abstract]' => TRUE, + ); + $this->drupalPost(null, $edit, t('Save configuraion')); + // Check that the settings have been updated. + $this->assertRaw(t('The configuration options have been saved.')); + + // Make sure abstract meta tag is not available as an option to show on edit form. + $this->assertNoField('nodewords_edit[abstract]'); + + // Make sure it is not present in node add form. + $this->drupalGet('node/add/page'); + $this->assertNoField('nodewords[abstract][value]'); + } + +} /** * Nodewords Search integration Test Case implementation.