You are here

public function SettingsForm::submitForm in Entity Print 8

Same name and namespace in other branches
  1. 8.2 src/Form/SettingsForm.php \Drupal\entity_print\Form\SettingsForm::submitForm()

Form submission handler.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/SettingsForm.php, line 197

Class

SettingsForm
Defines a form that configures Entity Print settings.

Namespace

Drupal\entity_print\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($plugin_id = $form_state
    ->getValue('pdf_engine')) {

    // Load the config entity, submit the relevant plugin form and then save
    // it.
    $entity = $this
      ->loadConfigEntity($plugin_id);

    /** @var \Drupal\entity_print\Plugin\PdfEngineInterface $plugin */
    $plugin = $entity
      ->getPdfEnginePluginCollection()
      ->get($entity
      ->id());
    $plugin
      ->submitConfigurationForm($form, $form_state);
    $entity
      ->save();
  }

  // Save the global settings.
  $values = $form_state
    ->getValues();
  $this
    ->config('entity_print.settings')
    ->set('default_css', $values['default_css'])
    ->set('force_download', $values['force_download'])
    ->set('pdf_engine', $values['pdf_engine'])
    ->save();
}