public function JavascriptLibrariesEditForm::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/ JavascriptLibrariesEditForm.php, line 143 - Contains \Drupal\javascript_libraries\Form\JavascriptLibrariesEditForm.
Class
Namespace
Drupal\javascript_libraries\FormCode
public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
switch ($form_state
->getValue([
'library_type',
])) {
case 'external':
if (empty($form['#library']['id'])) {
// New URL
$form['#library']['id'] = 'ext-' . db_next_id();
}
// @FIXME
// Could not extract the default value because it is either indeterminate, or
// not scalar. You'll need to provide a default value in
// config/install/javascript_libraries.settings.yml and config/schema/javascript_libraries.schema.yml.
$custom = \Drupal::config('javascript_libraries.settings')
->get('javascript_libraries_custom_libraries');
if (strlen($form_state
->getValue([
'name',
])) == 0) {
$parts = explode('/', $form_state
->getValue([
'external_url',
]));
$form_state
->setValue([
'name',
], '... /' . end($parts));
}
$custom[$form['#library']['id']] = [
'id' => $form['#library']['id'],
'type' => 'external',
'scope' => $form_state
->getValue([
'scope',
]),
'name' => $form_state
->getValue([
'name',
]),
'weight' => $form['#library']['weight'],
'uri' => $form_state
->getValue([
'external_url',
]),
'cache' => $form_state
->getValue([
'cache_external',
]),
];
\Drupal::configFactory()
->getEditable('javascript_libraries.settings')
->set('javascript_libraries_custom_libraries', $custom)
->save();
break;
case 'file':
_javascript_libraries_file_submit($form, $form_state);
// Change query-strings on css/js files to enforce reload for all users.
javascript_libraries_js_cache_clear();
break;
}
drupal_set_message('Your library has been added. Please configure the region and weight.');
$form_state
->set([
'redirect',
], 'admin/config/system/javascript-libraries/custom');
}