You are here

public function WebformProtectedDownloadsHandler::submitConfigurationForm in Webform Protected Downloads 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\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().

Overrides WebformHandlerBase::submitConfigurationForm

File

src/Plugin/WebformHandler/WebformProtectedDownloadsHandler.php, line 219

Class

WebformProtectedDownloadsHandler
Handler for protected downloads

Namespace

Drupal\webform_protected_downloads\Plugin\WebformHandler

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  $this->configuration = $this
    ->defaultConfiguration();
  parent::submitConfigurationForm($form, $form_state);
  $this
    ->applyFormStateToConfiguration($form_state);

  // Set the files as permanent through file usage
  $protectedFiles = $form_state
    ->getValue('protected_files');
  foreach ($protectedFiles as $protectedFile) {

    /** @var FileInterface $file */
    $file = $this->fileStorage
      ->load($protectedFile);
    if (!empty($file)) {
      $this->fileUsage
        ->add($file, 'webform_protected_downloads', 'webform', $this
        ->getWebform()
        ->id());
    }
  }
}