function _social_tagging_entity_validate in Open Social 10.0.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
- 8.4 modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
- 8.5 modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
- 8.6 modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
- 8.7 modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
- 8.8 modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
- 10.3.x modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
- 10.1.x modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
- 10.2.x modules/social_features/social_tagging/social_tagging.module \_social_tagging_entity_validate()
Validate function that overrides the tagging field with new values.
1 string reference to '_social_tagging_entity_validate'
- social_tagging_social_tagging_field_form_alter in modules/
social_features/ social_tagging/ social_tagging.module - Function do a changes related to social_tagging field.
File
- modules/
social_features/ social_tagging/ social_tagging.module, line 265 - Contains social_tagging.module.
Code
function _social_tagging_entity_validate($form, FormStateInterface $form_state) {
// Get the taggingservice.
$tag_service = Drupal::getContainer()
->get('social_tagging.tag_service');
// Get the main categories.
$categories = $tag_service
->getCategories();
// Init categories.
$tagging_values = [];
$counter = 0;
// Loop over the categories.
foreach ($categories as $category) {
if (!empty($form_state
->getValue('social_tagging_' . social_tagging_to_machine_name($category)))) {
foreach ($form_state
->getValue('social_tagging_' . social_tagging_to_machine_name($category)) as $selected) {
$tagging_values[] = [
'target_id' => $selected,
'_weight' => (string) $counter,
];
$counter++;
}
}
}
// Set the values in the social_tagging field.
$form_state
->setValue('social_tagging', $tagging_values);
}