You are here

public function ProtectedSubmissionsForm::buildForm in Protected Submissions 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/ProtectedSubmissionsForm.php, line 56

Class

ProtectedSubmissionsForm
ProtectedSubmissionsForm class.

Namespace

Drupal\protected_submissions\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Form constructor.
  $form = parent::buildForm($form, $form_state);

  // Default settings.
  $config = $this
    ->config('protected_submissions.settings');
  $language_scripts = [
    'Adlam' => 'Adlam',
    'Ahom' => 'Ahom',
    'Anatolian Hieroglyphs' => 'Anatolian Hieroglyphs',
    'Arabic' => 'Arabic',
    'Aramaic' => 'Aramaic',
    'Armenian' => 'Armenian',
    'Avestan' => 'Avestan',
    'Balinese' => 'Balinese',
    'Bamum' => 'Bamum',
    'Bassa Vah' => 'Bassa Vah',
    'Batak' => 'Batak',
    'Bengali and Assamese' => 'Bengali and Assamese',
    'Bhaiksuki' => 'Bhaiksuki',
    'Bopomofo' => 'Bopomofo',
    'Brahmi' => 'Brahmi',
    'Buginese' => 'Buginese',
    'Buhid' => 'Buhid',
    'Canadian Aboriginal' => 'Canadian Aboriginal',
    'Carian' => 'Carian',
    'Caucasian Albanian' => 'Caucasian Albanian',
    'Chakma' => 'Chakma',
    'Cham' => 'Cham',
    'Cherokee' => 'Cherokee',
    'Chorasmian' => 'Chorasmian',
    'CJK' => 'CJK',
    'Coptic' => 'Coptic',
    'Cuneiform' => 'Cuneiform',
    'Currency Symbols' => 'Currency Symbols',
    'Cypriot Syllabary' => 'Cypriot Syllabary',
    'Cyrillic' => 'Cyrillic',
    'Deseret' => 'Deseret',
    'Devanagari' => 'Devanagari',
    'Diacritical Marks' => 'Diacritical Marks',
    'Dives Akuru' => 'Dives Akuru',
    'Dogra' => 'Dogra',
    'Egyptian Hieroglyphs' => 'Egyptian Hieroglyphs',
    'Elbasan' => 'Elbasan',
    'Elymaic' => 'Elymaic',
    'Ethiopic' => 'Ethiopic',
    'Georgian' => 'Georgian',
    'Glagolitic' => 'Glagolitic',
    'Gothic' => 'Gothic',
    'Grantha' => 'Grantha',
    'Greek' => 'Greek',
    'Gujarati' => 'Gujarati',
    'Gunjala Gondi' => 'Gunjala Gondi',
    'Gurmukhi' => 'Gurmukhi',
    'Hangul Jamo' => 'Hangul Jamo',
    'Hangul Syllables' => 'Hangul Syllables',
    'Hanifi Rohingya' => 'Hanifi Rohingya',
    'Hanunoo' => 'Hanunoo',
    'Hatran' => 'Hatran',
    'Hebrew' => 'Hebrew',
    'Hiragana' => 'Hiragana',
    'Javanese' => 'Javanese',
    'Kaithi' => 'Kaithi',
    'Kana' => 'Kana',
    'Kanbun' => 'Kanbun',
    'Kannada' => 'Kannada',
    'Katakana' => 'Katakana',
    'Kayah Li' => 'Kayah Li',
    'Kharoshthi' => 'Kharoshthi',
    'Khitan Small Script' => 'Khitan Small Script',
    'Khmer' => 'Khmer',
    'Khojki' => 'Khojki',
    'Khudawadi' => 'Khudawadi',
    'Lao' => 'Lao',
    'Latin' => 'Latin',
    'Lepcha' => 'Lepcha',
    'Limbu' => 'Limbu',
    'Lisu' => 'Lisu',
    'Lycian' => 'Lycian',
    'Lydian' => 'Lydian',
    'Mahajani' => 'Mahajani',
    'Makasar' => 'Makasar',
    'Malayalam' => 'Malayalam',
    'Mandaic' => 'Mandaic',
    'Manichaean' => 'Manichaean',
    'Marchen' => 'Marchen',
    'Masaram Gondi' => 'Masaram Gondi',
    'Medefaidrin' => 'Medefaidrin',
    'Meetei Mayek' => 'Meetei Mayek',
    'Mende Kikaku' => 'Mende Kikaku',
    'Meroitic' => 'Meroitic',
    'Miao' => 'Miao',
    'Modi' => 'Modi',
    'Modifier Letters' => 'Modifier Letters',
    'Mongolian' => 'Mongolian',
    'Mro' => 'Mro',
    'Myanmar' => 'Myanmar',
    'Multani' => 'Multani',
    'Nabataean' => 'Nabataean',
    'Nandinagari' => 'Nandinagari',
    'New Tai Lue' => 'New Tai Lue',
    'Newa' => 'Newa',
    'Nko' => 'Nko',
    'Nushu' => 'Nushu',
    'Nyiakeng Puachue Hmong' => 'Nyiakeng Puachue Hmong',
    'Ogham' => 'Ogham',
    'Ol Chiki' => 'Ol Chiki',
    'Old Hungarian' => 'Old Hungarian',
    'Old Italic' => 'Old Italic',
    'Old Permic' => 'Old Permic',
    'Old Persian' => 'Old Persian',
    'Old Sogdian' => 'Old Sogdian',
    'Old Turkic' => 'Old Turkic',
    'Oriya' => 'Oriya',
    'Osage' => 'Osage',
    'Osmanya' => 'Osmanya',
    'Pahawh Hmong' => 'Pahawh Hmong',
    'Pahlavi' => 'Pahlavi',
    'Palmyrene' => 'Palmyrene',
    'Parthian' => 'Parthian',
    'Pau Cin Hau' => 'Pau Cin Hau',
    'Phags Pa' => 'Phags Pa',
    'Phoenician' => 'Phoenician',
    'Rejang' => 'Rejang',
    'Runic' => 'Runic',
    'Samaritan' => 'Samaritan',
    'Saurashtra' => 'Saurashtra',
    'Sharada' => 'Sharada',
    'Shavian' => 'Shavian',
    'Siddham' => 'Siddham',
    'Sinhala' => 'Sinhala',
    'Sogdian' => 'Sogdian',
    'Sora Sompeng' => 'Sora Sompeng',
    'Soyombo' => 'Soyombo',
    'Sundanese' => 'Sundanese',
    'Superscripts and Subscripts' => 'Superscripts and Subscripts',
    'Syloti Nagri' => 'Syloti Nagri',
    'Syriac' => 'Syriac',
    'Tagalog' => 'Tagalog',
    'Tagbanwa' => 'Tagbanwa',
    'Tai Le' => 'Tai Le',
    'Tai Tham' => 'Tai Tham',
    'Tai Viet' => 'Tai Viet',
    'Takri' => 'Takri',
    'Tamil' => 'Tamil',
    'Tangut' => 'Tangut',
    'Telugu' => 'Telugu',
    'Thaana' => 'Thaana',
    'Thai' => 'Thai',
    'Tibetan' => 'Tibetan',
    'Tifinagh' => 'Tifinagh',
    'Tirhuta' => 'Tirhuta',
    'Ugaritic' => 'Ugaritic',
    'Vai' => 'Vai',
    'Vedic Extensions' => 'Vedic Extensions',
    'Wancho' => 'Wancho',
    'Warang Citi' => 'Warang Citi',
    'Yezidi' => 'Yezidi',
    'Yi' => 'Yi',
    'Yijing' => 'Yijing',
    'Zanabazar Square' => 'Zanabazar Square',
  ];
  $form['allowed_scripts'] = [
    '#type' => 'checkboxes',
    '#options' => $language_scripts,
    '#default_value' => $config
      ->get('protected_submissions.allowed_scripts'),
    '#title' => $this
      ->t('Allowed language scripts'),
    '#required' => TRUE,
    '#description' => $this
      ->t('Select language scripts allowed for submission.'),
  ];
  $form['check_quantity'] = [
    '#type' => 'textfield',
    '#default_value' => $config
      ->get('protected_submissions.check_quantity'),
    '#title' => $this
      ->t('Number of characters to validate'),
    '#size' => 5,
    '#required' => TRUE,
    '#description' => $this
      ->t('Spam texts can be constructed using mixed characters from multiple languages.
      Checking each character would cause performance overhead, so we validate only randomly selected characters.
      Indicate how many characters from submitted text should be validated for allowed language scripts.'),
  ];

  // Page title field.
  $form['reject_message'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Reject message:'),
    '#default_value' => $config
      ->get('protected_submissions.reject_message'),
    '#required' => TRUE,
    '#description' => $this
      ->t('Enter a message to display when submission of undesired pattern is attempted.'),
  ];

  // Source text field.
  $form['reject_patterns'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Reject patterns:'),
    '#default_value' => $config
      ->get('protected_submissions.reject_patterns'),
    '#required' => TRUE,
    '#description' => $this
      ->t('Enter words or patterns to reject, separating them with commas or new lines.'),
  ];

  // Give users option to enable/disable logging if Database Logging is on.
  if ($this->moduleHandler
    ->moduleExists('dblog')) {
    $form['log_rejected'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Log rejected submissions'),
      '#default_value' => $config
        ->get('protected_submissions.log_rejected'),
      '#required' => FALSE,
      '#description' => $this
        ->t('Checking on this option could potentially flood <a href="@log">the website\'s log</a>, so use this feature only if you need to analyze the rejected submissions.', [
        '@log' => '/admin/reports/dblog',
      ]),
    ];
  }
  $form['#attached']['library'][] = 'protected_submissions/protected_submissions';
  return $form;
}