You are here

public function WebformEntitySettingsAssetsForm::form in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/EntitySettings/WebformEntitySettingsAssetsForm.php \Drupal\webform\EntitySettings\WebformEntitySettingsAssetsForm::form()

Gets the actual form array to be built.

Overrides WebformEntitySettingsBaseForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/EntitySettings/WebformEntitySettingsAssetsForm.php, line 17

Class

WebformEntitySettingsAssetsForm
Webform CSS and JS assets.

Namespace

Drupal\webform\EntitySettings

Code

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

  /** @var \Drupal\webform\WebformInterface $webform */
  $webform = $this->entity;
  $form['description'] = [
    '#type' => 'webform_message',
    '#message_message' => $this
      ->t('The below CSS and JavasScript will be loaded on all pages that references and loads this webform.'),
    '#message_type' => 'info',
    '#message_close' => TRUE,
    '#message_storage' => WebformMessage::STORAGE_SESSION,
  ];
  $form['css'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Custom CSS'),
    '#description' => $this
      ->t('Enter custom CSS to be attached to the webform.') . '<br/>' . $this
      ->t("To customize only webform specific elements, you should use the '.webform-submission-form' selector"),
  ];
  $form['css']['css'] = [
    '#type' => 'webform_codemirror',
    '#mode' => 'css',
    '#title' => $this
      ->t('CSS'),
    '#title_display' => 'invisible',
    '#default_value' => $webform
      ->getCss(),
  ];
  $form['javascript'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Custom JavaScript'),
    '#description' => $this
      ->t('Enter custom JavaScript to be attached to the webform.'),
  ];
  $form['javascript']['javascript'] = [
    '#type' => 'webform_codemirror',
    '#mode' => 'javascript',
    '#title' => $this
      ->t('JavaScript'),
    '#title_display' => 'invisible',
    '#default_value' => $webform
      ->getJavaScript(),
  ];
  return parent::form($form, $form_state);
}