You are here

public function DisableMessagesSettingsForm::buildForm in Disable Messages 8

Same name and namespace in other branches
  1. 2.x src/Form/DisableMessagesSettingsForm.php \Drupal\disable_messages\Form\DisableMessagesSettingsForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/DisableMessagesSettingsForm.php, line 54

Class

DisableMessagesSettingsForm
Provides a form for administering disable messages.

Namespace

Drupal\disable_messages\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = [];
  $form['disable_messages_enable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable filtering'),
    '#default_value' => $this
      ->config('disable_messages.settings')
      ->get('disable_messages_enable'),
    '#description' => $this
      ->t('Uncheck this checkbox to disable all message filtering. If you uncheck this, all messages will be shown to all users and no custom filtering rules will be applied.'),
  ];
  $form['disable_messages_ignore_patterns'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Messages to be disabled'),
    '#description' => $this
      ->t('Enter messages that should not be shown to end users. Regular expressions are supported. You do not have to include the opening and closing forward slashes for the regular expression. The system will automatically add /^ and $/ at the beginning and end of the pattern to ensure that the match is always a full match instead of a partial match. This will help prevent unexpected filtering of messages. So if you want to filter out a specific message ensure that you add the full message including any punctuation and additional HTML if any. Add one per line. See <a href="@PCRE" target="_blank"> PCRE </a> documentation for details on regular expressions.', [
      '@PCRE' => 'https://us3.php.net/manual/en/book.pcre.php',
    ]),
    '#default_value' => $this
      ->config('disable_messages.settings')
      ->get('disable_messages_ignore_patterns'),
  ];
  $form['disable_messages_ignore_case'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Ignore case'),
    '#default_value' => $this
      ->config('disable_messages.settings')
      ->get('disable_messages_ignore_case'),
    '#description' => $this
      ->t('Check this to ignore case while matching the patterns.'),
  ];
  $form['disable_messages_filter_options'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Page and user level filtering options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['disable_messages_filter_options']['role_information'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Filtering by role'),
    '#markup' => $this
      ->t('By default, permission to view all message types are given for all roles. You can change this in <a href="@link" target="_blank">administer permissions</a> to limit the roles which can view a given message type.', [
      '@link' => Url::fromRoute('user.admin_permissions')
        ->toString(),
    ]),
  ];
  $options = [
    $this
      ->t('Apply filters on all pages.'),
    $this
      ->t('Apply filters on every page except the listed pages.'),
    $this
      ->t('Apply filters only on the listed pages.'),
  ];
  $description = $this
    ->t("Enter one page per line as Drupal paths. 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.", [
    '%blog' => 'blog',
    '%blog-wildcard' => 'blog/*',
    '%front' => '<front>',
  ]);
  $form['disable_messages_filter_options']['disable_messages_filter_by_page'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Apply filters by page'),
    '#options' => $options,
    '#default_value' => $this
      ->config('disable_messages.settings')
      ->get('disable_messages_filter_by_page'),
  ];
  $form['disable_messages_filter_options']['disable_messages_page_filter_paths'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Pages'),
    '#default_value' => $this
      ->config('disable_messages.settings')
      ->get('disable_messages_page_filter_paths'),
    '#description' => $description,
  ];
  $form['disable_messages_filter_options']['disable_messages_exclude_users'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Users excluded from filtering'),
    '#size' => 40,
    '#default_value' => $this
      ->config('disable_messages.settings')
      ->get('disable_messages_exclude_users'),
    '#description' => $this
      ->t('Comma separated list of user ids to be excluded from any filtering. All messages will be shown to all the listed users irrespective of their permissons to view the corresponding type of message.'),
  ];
  $form['disable_messages_debug'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Debug options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['disable_messages_debug']['disable_messages_enable_debug'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable debug mode'),
    '#default_value' => $this
      ->config('disable_messages.settings')
      ->get('disable_messages_enable_debug'),
    '#description' => $this
      ->t('Check this to enable debug information. The debug information will be shown in an explicitly hidden div sent to the page via $closure. You can use firebug or a similar tool like that to set the visibility of this div or just view source to see the debug information. Safe to use even on production sites.'),
  ];
  $form['disable_messages_debug']['disable_messages_debug_visible_div'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show debug div as visible'),
    '#default_value' => $this
      ->config('disable_messages.settings')
      ->get('disable_messages_debug_visible_div'),
    '#description' => $this
      ->t("Frustrated with having to view source everytime? Don't worry. Enable this to show the debug messages in a visible div. <strong>Remember to disable this on the production sites if you enable debug there :)</strong>."),
  ];
  $form['#submit'][] = 'disable_messages_settings_form_submit';
  return parent::buildForm($form, $form_state);
}