diff --git a/feedback.admin.inc b/feedback.admin.inc index 1e517a1..086b2bf 100644 --- a/feedback.admin.inc +++ b/feedback.admin.inc @@ -128,14 +128,16 @@ function feedback_admin_view_form_submit($form, &$form_state) { /** * Form builder; The general feedback settings form. * - * Currently this form is a necessity as a parent for the field local tasks. - * * @ingroup forms */ function feedback_admin_settings_form($form, &$form_state) { - drupal_set_message(t('There are no feedback settings yet, but you can configure fields.')); - $form = array(); - return $form; + $form['feedback_excluded_paths'] = array( + '#type' => 'textarea', + '#title' => t('Paths to exclude from feedback display'), + '#default_value' => variable_get('feedback_excluded_paths', 'admin/reports/feedback'), + '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')), + ); + return system_settings_form($form); } /** diff --git a/feedback.module b/feedback.module index cb3bb30..eb2d652 100644 --- a/feedback.module +++ b/feedback.module @@ -158,7 +158,7 @@ function feedback_block_view($delta = '') { $block = array(); switch($delta) { case 'form': - if (!user_access('access feedback form') || $_GET['q'] == 'admin/reports/feedback') { + if (!user_access('access feedback form')) { break; } $block['subject'] = '' . t('Feedback') . ''; @@ -172,7 +172,7 @@ function feedback_block_view($delta = '') { * Implements hook_page_build(). */ function feedback_page_build(&$page) { - if (user_access('access feedback form') && $_GET['q'] != 'admin/reports/feedback') { + if (user_access('access feedback form') && !feedback_match_path(variable_get('feedback_excluded_paths', 'admin/reports/feedback'))) { $block = (object) feedback_block_view('form'); $block->module = 'feedback'; $block->delta = 'form'; @@ -191,6 +191,32 @@ function feedback_page_build(&$page) { } /** + * Check if the current path matches any pattern in a set of patterns. + * + * @param $patterns + * String containing a set of patterns separated by \n, \r or \r\n. + * + * @return + * Boolean value: TRUE if the current path or alias matches a pattern. + */ +function feedback_match_path($patterns) { + // Convert path to lowercase. This allows comparison of the same path + // with different case. Ex: /Page, /page, /PAGE. + $patterns = drupal_strtolower($patterns); + + // Convert the current path to lowercase. + $path = drupal_strtolower(drupal_get_path_alias($_GET['q'])); + + // Compare the lowercase internal and lowercase path alias (if any). + $page_match = drupal_match_path($path, $patterns); + if ($path != $_GET['q']) { + $page_match = $page_match || drupal_match_path($_GET['q'], $patterns); + } + + return $page_match; +} + +/** * Form constructor for the feedback form. */ function feedback_form($form, &$form_state) { diff --git a/tests/feedback.test b/tests/feedback.test index e9cfc14..d196820 100644 --- a/tests/feedback.test +++ b/tests/feedback.test @@ -23,7 +23,7 @@ class FeedbackTestCase extends DrupalWebTestCase { // @todo Remove soft-dependency on Block. parent::setUp(array('block', 'feedback')); - $this->admin_user = $this->drupalCreateUser(array('access feedback form', 'view feedback messages')); + $this->admin_user = $this->drupalCreateUser(array('access feedback form', 'view feedback messages', 'administer feedback')); $this->web_user = $this->drupalCreateUser(array('access feedback form')); $this->drupalLogin($this->web_user); } @@ -52,4 +52,19 @@ class FeedbackTestCase extends DrupalWebTestCase { $this->drupalPost(NULL, $edit, t('Submit')); $this->assertFieldByName('feedback-messages[1][1]', 1, t('Processed message found.')); } + + /** + * Test visibility settings. + */ + function testFeedbackVisibility() { + $this->drupalLogin($this->admin_user); + $this->drupalGet('user'); + $this->assertRaw('' . t('Feedback') . '', t('Feedback form shown.')); + $edit = array( + 'feedback_excluded_paths' => 'user*', + ); + $this->drupalPost('admin/config/user-interface/feedback', $edit, t('Save configuration')); + $this->drupalGet('user'); + $this->assertNoRaw('' . t('Feedback') . '', t('Feedback form not shown.')); + } }