You are here

public function AdminSettingForm::buildForm in Restrict Abusive Words 8

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/AdminSettingForm.php, line 38
Contains \Drupal\restrict_abusive_words\Form\AdminSettingForm.

Class

AdminSettingForm
Contribute form.

Namespace

Drupal\restrict_abusive_words\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $node_types = array();
  $user_role = array();
  $config = $this
    ->config('restrict_abusive_words.settings');
  foreach (user_roles() as $rid => $role) {
    $user_role[$role
      ->get('id')] = $role
      ->label();
  }
  $general_form = array(
    'user_register_form' => t('User Registration Form'),
    'user_profile_form' => t('User Profile Form'),
    'webform' => t('Webform'),
  );
  foreach (NodeType::loadMultiple() as $machne_name => $node_type) {
    $node_types[$node_type
      ->get('type')] = $node_type
      ->label();
  }
  $actions = array(
    'prevent_form' => t('Prevent the form to submit'),
    'deactive_form' => t('Deactive'),
  );
  $form['action_type'] = array(
    '#type' => 'radios',
    '#title' => t('Choose the action.'),
    '#description' => t('Choose the action after submitting the form, it will prevent the form or deactive the content/user etc.'),
    '#options' => $actions,
    '#default_value' => $config
      ->get('action_type'),
  );
  $form['disable_user_roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Disable User Roles'),
    '#description' => t('Disable Restrict Abusive Words for the selected user roles. By default no user role is selected.'),
    '#options' => $user_role,
    '#default_value' => $config
      ->get('disable_user_roles'),
  );
  $form['enable_user_roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Enable User Roles'),
    '#description' => t('Restrict to use abusive word for the selected user roles. If do not check any user roles, it will assume all user roles.'),
    '#options' => $user_role,
    '#default_value' => $config
      ->get('enable_user_roles'),
  );
  $form['general_form'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select General Form'),
    '#description' => t('Restrict abusive word to use in General Form.'),
    '#options' => $general_form,
    '#default_value' => $config
      ->get('general_form'),
  );
  $form['entity_node'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select Node Form'),
    '#description' => t('Restrict abusive word to use in Node Form.'),
    '#options' => $node_types,
    '#default_value' => $config
      ->get('entity_node'),
  );
  $form['entity_comment'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select Comment Node Form'),
    '#description' => t('Restrict abusive word to use in Comment Node Form.'),
    '#options' => $node_types,
    '#default_value' => $config
      ->get('entity_comment'),
  );
  return parent::buildForm($form, $form_state);
}