function share_everywhere_inject_into_entity_forms in Share Everywhere 8
Same name and namespace in other branches
- 2.x share_everywhere.module \share_everywhere_inject_into_entity_forms()
Injects Share Everywhere settings into node or product forms.
2 calls to share_everywhere_inject_into_entity_forms()
File
- ./
share_everywhere.module, line 229 - A module that adds social buttons to your website.
Code
function share_everywhere_inject_into_entity_forms(&$form, FormStateInterface $form_state) {
$config = \Drupal::config('share_everywhere.settings');
$entity = $form_state
->getFormObject()
->getEntity();
if ($entity
->getEntityTypeId() == 'commerce_product') {
$enabled_types = $config
->get('product_types');
}
else {
$enabled_types = $config
->get('content_types');
}
if ($config
->get('per_entity') && in_array($entity
->bundle(), $enabled_types)) {
$enabled_products = $config
->get('enabled_entities.' . $entity
->getEntityTypeId()) ?? [];
$entity_is_enabled = in_array($entity
->id(), $enabled_products);
$form['share_everywhere'] = [
'#type' => 'details',
'#title' => t('Share Everywhere Settings'),
'#group' => 'advanced',
'#weight' => 100,
'#tree' => TRUE,
'#open' => $entity_is_enabled,
];
$form['share_everywhere']['enabled'] = [
'#type' => 'checkbox',
'#title' => t('Show social share buttons'),
'#default_value' => $entity_is_enabled,
];
$form['actions']['submit']['#submit'][] = 'share_everywhere_entity_form_submit';
}
}