function social_simple_form_node_type_form_alter in Social simple 8
Same name and namespace in other branches
- 2.0.x social_simple.module \social_simple_form_node_type_form_alter()
Implements hook_form_FORM_ID_alter().
File
- ./
social_simple.module, line 118 - Contains social.module..
Code
function social_simple_form_node_type_form_alter(&$form, FormStateInterface $form_state) {
/** @var \Drupal\node\NodeTypeInterface $type */
$type = $form_state
->getFormObject()
->getEntity();
$form['social_simple'] = [
'#type' => 'details',
'#group' => 'additional_settings',
'#title' => t('Social simple share'),
'#access' => \Drupal::currentUser()
->hasPermission('administer social simple') || \Drupal::currentUser()
->hasPermission('administer nodes'),
];
$form['social_simple']['social_simple_share'] = [
'#type' => 'checkbox',
'#title' => t('Display social network share links'),
'#default_value' => $type
->getThirdPartySetting('social_simple', 'share', 0),
];
$form['social_simple']['social_simple_title'] = [
'#type' => 'textfield',
'#title' => t('The title used above the share links.'),
'#default_value' => $type
->getThirdPartySetting('social_simple', 'title', ''),
'#states' => [
'visible' => [
':input[name="social_simple_share"]' => [
'checked' => TRUE,
],
],
],
];
/** @var \Drupal\social_simple\SocialSimpleGenerator $social_simple_generator */
$social_simple_generator = \Drupal::service('social_simple.generator');
$form['social_simple']['social_simple_networks'] = [
'#type' => 'checkboxes',
'#title' => t('Select the social networks availables for this content type'),
'#options' => $social_simple_generator
->getNetworks(),
'#default_value' => $type
->getThirdPartySetting('social_simple', 'networks', []),
'#states' => [
'visible' => [
':input[name="social_simple_share"]' => [
'checked' => TRUE,
],
],
],
];
$options = [];
$valid_field_type = [
'entity_reference',
];
$fields = \Drupal::service('entity_field.manager')
->getFieldDefinitions('node', $type
->id());
/** @var \Drupal\Core\Field\BaseFieldDefinition $field */
foreach ($fields as $name => $field) {
if (!empty($field
->getTargetBundle()) && in_array($field
->getType(), $valid_field_type)) {
$options[$name] = $field
->getLabel();
}
}
$form['social_simple']['social_simple_hashtags'] = [
'#type' => 'select',
'#title' => t('Twitter hashtags'),
'#options' => [
'0' => t('- None -'),
] + $options,
'#default_value' => $type
->getThirdPartySetting('social_simple', 'hashtags', []),
'#states' => [
'visible' => [
':input[name="social_simple_networks[twitter]"]' => [
'checked' => TRUE,
],
],
],
];
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler
->moduleExists('forward')) {
$form['social_simple']['social_simple_forward_integration'] = [
'#type' => 'checkbox',
'#title' => t('Integrate the <a href="https://www.drupal.org/project/forward">Forward module</a> with the Mail button.'),
'#default_value' => $type
->getThirdPartySetting('social_simple', 'forward_integration', FALSE),
];
}
$form['#entity_builders'][] = 'social_simple_form_node_type_form_builder';
}