You are here

public function WebformAttachmentBase::form in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentBase.php \Drupal\webform_attachment\Plugin\WebformElement\WebformAttachmentBase::form()

Gets the actual configuration webform array to be built.

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 An associative array contain the element's configuration webform without any default values.

Overrides WebformElementBase::form

4 calls to WebformAttachmentBase::form()
WebformAttachmentToken::form in modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentToken.php
Gets the actual configuration webform array to be built.
WebformAttachmentTwig::form in modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentTwig.php
Gets the actual configuration webform array to be built.
WebformAttachmentUrl::form in modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentUrl.php
Gets the actual configuration webform array to be built.
WebformEntityPrintAttachment::form in modules/webform_entity_print_attachment/src/Plugin/WebformElement/WebformEntityPrintAttachment.php
Gets the actual configuration webform array to be built.
4 methods override WebformAttachmentBase::form()
WebformAttachmentToken::form in modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentToken.php
Gets the actual configuration webform array to be built.
WebformAttachmentTwig::form in modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentTwig.php
Gets the actual configuration webform array to be built.
WebformAttachmentUrl::form in modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentUrl.php
Gets the actual configuration webform array to be built.
WebformEntityPrintAttachment::form in modules/webform_entity_print_attachment/src/Plugin/WebformElement/WebformEntityPrintAttachment.php
Gets the actual configuration webform array to be built.

File

modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentBase.php, line 163

Class

WebformAttachmentBase
Provides a base class for 'webform_attachment' elements.

Namespace

Drupal\webform_attachment\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['attachment'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Attachment settings'),
  ];
  $form['attachment']['message'] = [
    '#type' => 'webform_message',
    '#message_message' => $this
      ->t("Please make sure to enable 'Include files as attachments' for each email handler that you want to send this attachment."),
    '#message_type' => 'warning',
    '#message_close' => TRUE,
    '#message_storage' => WebformMessage::STORAGE_SESSION,
    '#access' => TRUE,
  ];
  $form['attachment']['display_on'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Display on'),
    '#options' => $this
      ->getDisplayOnOptions(TRUE),
  ];
  $form['attachment']['display_on_message'] = [
    '#type' => 'webform_message',
    '#message_message' => $this
      ->t("The attachment's link will only be diplayed on the form after the submission is completed."),
    '#message_type' => 'warning',
    '#access' => TRUE,
    '#states' => [
      'visible' => [
        [
          ':input[name="properties[display_on]"]' => [
            'value' => 'form',
          ],
        ],
        'or',
        [
          ':input[name="properties[display_on]"]' => [
            'value' => 'both',
          ],
        ],
      ],
    ],
  ];
  $form['attachment']['filename'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('File name'),
    '#description' => $this
      ->t("Please enter the attachment's file name with a file extension. The file extension will be used to determine the attachment's content (mime) type."),
    '#maxlength' => NULL,
  ];
  $form['attachment']['link_title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link title'),
    '#description' => $this
      ->t('Enter the title to be displayed when the attachment is displayed as a link.'),
  ];
  $form['attachment']['trim'] = [
    '#type' => 'checkbox',
    '#return_value' => TRUE,
    '#title' => $this
      ->t("Remove whitespace around the attachment's content"),
    '#description' => $this
      ->t("If checked, all spaces and returns around the attachment's content with be removed."),
    '#weight' => 10,
  ];
  $form['attachment']['sanitize'] = [
    '#type' => 'checkbox',
    '#return_value' => TRUE,
    '#title' => $this
      ->t('Sanitize file name'),
    '#description' => $this
      ->t('If checked, file name will be transliterated, lower-cased and all special characters converted to dashes (-).'),
    '#weight' => 10,
  ];
  $form['attachment']['download'] = [
    '#type' => 'checkbox',
    '#return_value' => TRUE,
    '#title' => $this
      ->t('Force users to download the attachment'),
    '#description' => $this
      ->t('If checked the attachment will be automatically download.'),
    '#weight' => 10,
  ];
  $form['attachment']['tokens'] = [
    '#access' => TRUE,
    '#weight' => 10,
  ] + $this->tokenManager
    ->buildTreeElement();

  // Add warning about disabled attachments.
  $form['conditional_logic']['states_attachment'] = [
    '#type' => 'webform_message',
    '#message_message' => t('Disabled attachments will not be included as file attachments in sent emails.'),
    '#message_type' => 'warning',
    '#message_close' => TRUE,
    '#message_storage' => WebformMessage::STORAGE_SESSION,
    '#access' => TRUE,
  ];
  return $form;
}