You are here

public function WebformEntityPrintAttachment::form in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_entity_print_attachment/src/Plugin/WebformElement/WebformEntityPrintAttachment.php \Drupal\webform_entity_print_attachment\Plugin\WebformElement\WebformEntityPrintAttachment::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 WebformAttachmentBase::form

File

modules/webform_entity_print_attachment/src/Plugin/WebformElement/WebformEntityPrintAttachment.php, line 68

Class

WebformEntityPrintAttachment
Provides a 'webform_entity_print_attachment' element.

Namespace

Drupal\webform_entity_print_attachment\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  // Require export type file extension.
  $file_extension = $this
    ->getExportTypeFileExtension();
  $t_args = [
    '@extension' => $file_extension,
  ];
  $form['attachment']['filename']['#description'] .= '<br/><br/>' . $this
    ->t('File name must include *.@extension file extension.', $t_args);
  $form['attachment']['filename']['#pattern'] = '^.*\\.' . $file_extension . '$';
  $form['attachment']['filename']['#pattern_error'] = $this
    ->t('File name must include *.@extension file extension.', $t_args);
  WebformElementHelper::process($form['attachment']['filename']);

  // View mode.
  $form['attachment']['view_mode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('View mode'),
    '#options' => [
      'html' => $this
        ->t('HTML'),
      'table' => $this
        ->t('Table'),
      'twig' => $this
        ->t('Twig template…'),
    ],
  ];
  $form['attachment']['template'] = [
    '#type' => 'webform_codemirror',
    '#title' => $this
      ->t('Twig template'),
    '#title_display' => 'invisible',
    '#mode' => 'twig',
    '#states' => [
      'visible' => [
        ':input[name="properties[view_mode]"]' => [
          'value' => 'twig',
        ],
      ],
    ],
  ];
  $form['attachment']['help'] = WebformTwigExtension::buildTwigHelp() + [
    '#states' => [
      'visible' => [
        ':input[name="properties[view_mode]"]' => [
          'value' => 'twig',
        ],
      ],
    ],
  ];

  // Set #access so that help is always visible.
  WebformElementHelper::setPropertyRecursive($form['attachment']['help'], '#access', TRUE);
  return $form;
}