You are here

public function SiteWideJSForm::buildForm in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  2. 8.2 modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  3. 8.3 modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  4. 8.4 modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  5. 8.5 modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  6. 8.6 modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  7. 8.7 modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  8. 8.8 modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  9. 10.3.x modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  10. 10.0.x modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  11. 10.1.x modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::buildForm()
  12. 10.2.x modules/custom/sitewide_js/src/Form/SiteWideJSForm.php \Drupal\sitewide_js\Form\SiteWideJSForm::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

modules/custom/sitewide_js/src/Form/SiteWideJSForm.php, line 34

Class

SiteWideJSForm
Class SiteWideJSForm.

Namespace

Drupal\sitewide_js\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('sitewide_js.settings');
  $form['warning']['#markup'] = $this
    ->t('<h2>Warning</h2><p>Be careful, in this section you can make sitewide changes to the HTML template and therefore break both the front-end javascript applications and the layout for your website.</p>');
  $form['swjs_enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable site wide JS'),
    '#description' => $this
      ->t('Turn sitewide JS on or off.'),
    '#default_value' => $config
      ->get('swjs_enabled'),
  ];
  $form['swjs_location'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('JS Location'),
    '#description' => $this
      ->t('The output location of the sitewide JS.'),
    '#default_value' => $config
      ->get('swjs_location'),
    '#options' => [
      0 => $this
        ->t('Header'),
      1 => $this
        ->t('Footer'),
    ],
  ];
  $form['swjs_footer_region'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Footer region'),
    '#description' => $this
      ->t('Footer region to put the JS in.'),
    '#default_value' => $config
      ->get('swjs_footer_region'),
    '#states' => [
      'visible' => [
        ':input[name="swjs_location"]' => [
          'value' => '1',
        ],
      ],
    ],
  ];
  $form['swjs_javascript'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Javascript'),
    '#description' => $this
      ->t('The JS to add to the site.'),
    '#default_value' => $config
      ->get('swjs_javascript'),
  ];
  return parent::buildForm($form, $form_state);
}