function share_everywhere_entity_form_submit in Share Everywhere 2.x
Same name and namespace in other branches
- 8 share_everywhere.module \share_everywhere_entity_form_submit()
Custom form submit to save Share Everywhere settings on entities.
1 string reference to 'share_everywhere_entity_form_submit'
- share_everywhere_inject_into_entity_forms in ./
share_everywhere.module - Injects Share Everywhere settings into node or product forms.
File
- ./
share_everywhere.module, line 265 - A module that adds social buttons to your website.
Code
function share_everywhere_entity_form_submit(&$form, FormStateInterface $form_state) {
$config = \Drupal::configFactory()
->getEditable('share_everywhere.settings');
$entity = $form_state
->getFormObject()
->getEntity();
$config_key = 'enabled_entities.' . $entity
->getEntityTypeId();
$enabled_entities = $config
->get($config_key) ?? [];
$se_enabled = $form_state
->getValue([
'share_everywhere',
'enabled',
], 0);
$key = array_search($entity
->id(), $enabled_entities);
if ($key !== FALSE && !$se_enabled) {
unset($enabled_entities[$key]);
$config
->set($config_key, array_values($enabled_entities))
->save();
}
elseif ($key === FALSE && $se_enabled) {
$enabled_entities[] = $entity
->id();
$config
->set($config_key, $enabled_entities)
->save();
}
}