function social_editor_filter_process_format in Open Social 8
Same name and namespace in other branches
- 8.9 modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 8.2 modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 8.3 modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 8.4 modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 8.5 modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 8.6 modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 8.7 modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 8.8 modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 10.3.x modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 10.0.x modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 10.1.x modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
- 10.2.x modules/social_features/social_editor/social_editor.module \social_editor_filter_process_format()
Process callback for form elements that have a text format selector attached.
This callback runs after filter_process_format() and performs additional modifications to the form element.
See also
\Drupal\filter\Element\TextFormat::processFormat()
1 string reference to 'social_editor_filter_process_format'
- social_editor_element_info_alter in modules/
social_features/ social_editor/ social_editor.module - Implements hook_element_info_alter().
File
- modules/
social_features/ social_editor/ social_editor.module, line 36 - The Social editor module.
Code
function social_editor_filter_process_format(array &$element, FormStateInterface $form_state, array $complete_form) {
// Init.
$disable_fields = FALSE;
// Forms.
$forms = [
"social_post_entity_form",
"comment_post_comment_form",
"comment_comment_form",
];
// Allowed formats.
$allowed_format = 'simple_text';
// Check if it needs to be done here.
if (in_array($complete_form['#form_id'], $forms)) {
// Remove user formats except simple_text.
foreach ($element['format']['format']['#options'] as $key => $value) {
if ($key !== $allowed_format) {
unset($element['format']['format']['#options'][$key]);
}
}
// No changes can be made in text formats, so remove the fields.
$disable_fields = TRUE;
}
else {
// Remove simple_text.
foreach ($element['format']['format']['#options'] as $key => $value) {
if ($key === $allowed_format) {
unset($element['format']['format']['#options'][$key]);
}
}
}
// No changes can be made in text formats, so deny access to the fields.
if ($disable_fields == TRUE || count($element['format']['format']['#options']) == 1) {
// Deny access to format fields.
$element['format']['format']['#access'] = FALSE;
$element['format']['guidelines']['#access'] = FALSE;
$element['format']['help']['#access'] = FALSE;
}
return $element;
}