You are here

public function EmailedExport::buildConfigurationForm in Webform Scheduled Tasks 8.2

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides TaskPluginBase::buildConfigurationForm

File

src/Plugin/WebformScheduledTasks/Task/EmailedExport.php, line 125

Class

EmailedExport
A task which emails an export of a list of webforms.

Namespace

Drupal\webform_scheduled_tasks\Plugin\WebformScheduledTasks\Task

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['email_addresses'] = [
    '#title' => $this
      ->t('Email addresses'),
    '#required' => TRUE,
    '#description' => $this
      ->t('Enter a list of email addresses to notify when the export is complete. The list should be coma separated values.'),
    '#type' => 'textarea',
    '#attributes' => [
      'placeholder' => 'foo@example.com, bar@example.com',
    ],
    '#default_value' => $this->configuration['email_addresses'],
  ];
  $form['storage_type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Storage type'),
    '#options' => [
      static::STORAGE_TYPE_FILESYSTEM => $this
        ->t('Save to private filesystem'),
      static::STORAGE_TYPE_EMAIL => $this
        ->t('Send as email attachment'),
    ],
    '#default_value' => $this->configuration['storage_type'],
    '#required' => TRUE,
    '#description' => $this
      ->t('Select how the resulting file will be delivered to the configured users. Saving the file to the file system will generate a private file which only privileged roles will have access to.'),
  ];
  $form['attachment_storage_type_warning'] = [
    '#type' => 'webform_message',
    '#message_type' => 'warning',
    '#message_message' => $this
      ->t('<strong>Warning:</strong> Sending email file attachments requires webform to have already been configured for attachments. See <a target="_blank" href=":help">this help topic for more information</a>.', [
      ':help' => 'https://www.drupal.org/node/3021480',
    ]),
    '#states' => [
      'visible' => [
        ':input[name="task_settings[storage_type]"]' => [
          'value' => 'email',
        ],
      ],
    ],
  ];
  $form['delete_submissions'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Delete submissions after export'),
    '#default_value' => $this->configuration['delete_submissions'],
    '#description' => $this
      ->t('Delete submissions after this task has been run.'),
  ];
  $form['include_attachments'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Include attachments'),
    '#default_value' => $this->configuration['include_attachments'],
    '#description' => $this
      ->t('Include attachments uploaded by users in the exported archive.'),
  ];
  $this
    ->buildExportPluginForm($form, $form_state);
  return $form;
}