public function ShareEverywhereConfigForm::submitForm in Share Everywhere 8
Same name and namespace in other branches
- 2.x src/Form/ShareEverywhereConfigForm.php \Drupal\share_everywhere\Form\ShareEverywhereConfigForm::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/ ShareEverywhereConfigForm.php, line 415
Class
- ShareEverywhereConfigForm
- Provides a settings form for Share Everywhere module.
Namespace
Drupal\share_everywhere\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('share_everywhere.settings');
$entity_types = $this->entityTypeBundleInfo
->getBundleInfo('node');
$form_values = $form_state
->getValues();
$current_location = $config
->get('location');
$new_location = $form_values['location'];
$commerce_product = $this->moduleHandler
->moduleExists('commerce_product');
if (($current_location == 'content' || $new_location == 'content') && $current_location != $new_location) {
$this->entityFieldManager
->clearCachedFieldDefinitions();
}
foreach ($form_values['buttons'] as $key => $value) {
$config
->set('buttons.' . $key . '.enabled', (int) $value['enabled']);
if (isset($value['weight'])) {
$config
->set('buttons.' . $key . '.weight', $value['weight']);
}
$config
->save();
}
$config
->set('title', $form_values['title_text'])
->set('display_title', $form_values['display_title'])
->set('style', $form_values['style'])
->set('include_css', $form_values['libraries']['include_css'])
->set('include_js', $form_values['libraries']['include_js'])
->set('collapsible', (int) $form_values['collapsible'])
->set('location', $form_values['location'])
->set('alignment', $form_values['alignment'])
->set('per_entity', $form_values['per_entity'])
->set('content_types', $form_values['content_types'])
->save();
if (!empty($entity_types)) {
foreach ($entity_types as $key => $entity_type) {
$config
->set('view_modes.' . $key, $form_values[$key . '_options'])
->save();
}
}
if ($commerce_product) {
$config
->set('product_types', $form_values['product_types'])
->save();
$entity_types = $this->entityTypeBundleInfo
->getBundleInfo('commerce_product');
if (!empty($entity_types)) {
foreach ($entity_types as $key => $entity_type) {
$config
->set('product_view_modes.' . $key, $form_values[$key . '_options'])
->save();
}
}
}
if (!empty(trim($form_values['pages']))) {
$pages = array_filter(explode("\r\n", $form_values['pages']), function ($page) {
return !empty(trim($page));
});
$config
->set('restricted_pages.pages', $pages)
->set('restricted_pages.type', $form_values['type'])
->save();
}
else {
$config
->set('restricted_pages.pages', [])
->save();
}
$this->renderCache
->deleteAll();
parent::submitForm($form, $form_state);
}