public function SettingsForm::submitForm in Like & Dislike 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 ConfigFormBase::submitForm
File
- src/
Form/ SettingsForm.php, line 179
Class
- SettingsForm
- Class SettingsForm.
Namespace
Drupal\like_and_dislike\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('like_and_dislike.settings');
$enabled_types = [];
foreach ($form_state
->getValue('enabled_types') as $entity_type_id => $entity_type_settings) {
// Skip disabled content entity types.
if (!$entity_type_settings['enabled']) {
continue;
}
// Put enabled content entity type into configuration, only save entity
// types with bundles if at least one bundle is checked.
if (isset($entity_type_settings['bundle_info']) && array_keys(array_filter($entity_type_settings['bundle_info']['bundles']))) {
// Filter-out non-selected bundles.
$enabled_types[$entity_type_id] = array_keys(array_filter($entity_type_settings['bundle_info']['bundles']));
}
else {
$enabled_types[$entity_type_id] = [];
}
}
$config
->set('enabled_types', $enabled_types);
$config
->set('allow_cancel_vote', $form_state
->getValue('allow_cancel_vote'));
$config
->set('hide_vote_widget', $form_state
->getValue('hide_vote_widget'));
$config
->save();
parent::submitForm($form, $form_state);
// Settings changes might not immediately be updated for the view display.
// Thus clear the entity extra field caches.
$this->entityFieldManager
->clearCachedFieldDefinitions();
}