You are here

public function JavascriptLibrariesCustomForm::submitForm in JavaScript Libraries Manager 8

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 FormInterface::submitForm

File

src/Form/JavascriptLibrariesCustomForm.php, line 111
Contains \Drupal\javascript_libraries\Form\JavascriptLibrariesCustomForm.

Class

JavascriptLibrariesCustomForm

Namespace

Drupal\javascript_libraries\Form

Code

public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $custom = \Drupal::config('javascript_libraries.settings')
    ->get('javascript_libraries_custom_libraries');
  foreach ($form_state
    ->getValue([
    'libraries',
  ]) as $key => $library) {
    $custom[$key]['scope'] = $library['scope'];
    $custom[$key]['weight'] = $library['weight'];
  }
  \Drupal::configFactory()
    ->getEditable('javascript_libraries.settings')
    ->set('javascript_libraries_custom_libraries', $custom)
    ->save();
  drupal_set_message(t('The JavaScript library settings have been updated.'));
}