You are here

public function SettingsFormWarning::buildForm in General Data Protection Regulation Compliance 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/SettingsFormWarning.php, line 90

Class

SettingsFormWarning
Implements the form controller.

Namespace

Drupal\gdpr_compliance\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('gdpr_compliance.settings');
  $form['from-morelink'] = [
    '#title' => $this
      ->t('Url for form [Link to site policy agreement].'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#default_value' => $config
      ->get('from-morelink'),
    '#description' => $this
      ->t('Relative path starts with "/", or absolute start with http/https.'),
  ];
  $form['user'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('@module GDPR form warning', [
      '@module' => 'user',
    ]),
    '#open' => TRUE,
  ];
  $form["user"]['user-register'] = [
    '#title' => $this
      ->t('Enable on user registration'),
    '#description' => $this
      ->t('Display alert on user-register form (/user/register).'),
    '#type' => 'checkbox',
    '#default_value' => $config
      ->get('user-register'),
  ];
  $form["user"]['user-login'] = [
    '#title' => $this
      ->t('Enable on user login'),
    '#description' => $this
      ->t('Display alert on user-login form (/user/login).'),
    '#type' => 'checkbox',
    '#default_value' => $config
      ->get('user-login'),
  ];
  foreach ($this->entityTypes as $enity_type => $enity_info) {
    $name = $enity_info['name'];
    $form[$enity_type] = [
      '#type' => 'details',
      '#title' => $this
        ->t('@name GDPR form warning', [
        '@name' => $name,
      ]),
      '#open' => TRUE,
    ];
    if (!$this->moduleHandler
      ->moduleExists($enity_info['module'])) {
      $form[$enity_type]['#open'] = FALSE;
      $form[$enity_type]["{$enity_type}-miss"] = [
        '#markup' => '<p>' . $this
          ->t("Module '@module' not enabled.", [
          '@module' => $name,
        ]) . '</p>',
      ];
    }
    else {
      $form[$enity_type]["{$enity_type}-mode"] = [
        '#title' => $this
          ->t("Display mode"),
        '#type' => 'radios',
        '#options' => [
          'disable' => 'Disable',
          'all' => 'All',
          'custom' => 'Custom bundles',
        ],
        '#default_value' => $config
          ->get("{$enity_type}-mode"),
      ];
      $options = [];
      $bundles = $this
        ->getBundles($enity_type);
      if (!empty($bundles)) {
        foreach ($bundles as $key => $value) {
          $options[$key] = $value['label'];
        }
        $form[$enity_type]["{$enity_type}-bundles"] = [
          '#title' => $this
            ->t("@name bundles warning display on", [
            '@name' => $name,
          ]),
          '#type' => 'checkboxes',
          '#options' => $options,
        ];
        $default = $config
          ->get("{$enity_type}-bundles");
        if (!empty($default)) {
          $form[$enity_type]["{$enity_type}-bundles"]['#default_value'] = $default;
        }
      }
    }
  }
  return parent::buildForm($form, $form_state);
}