You are here

function social_core_filter_process_format in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  2. 8 modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  3. 8.2 modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  4. 8.3 modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  5. 8.4 modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  6. 8.5 modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  7. 8.6 modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  8. 8.7 modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  9. 10.3.x modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  10. 10.0.x modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  11. 10.1.x modules/social_features/social_core/social_core.module \social_core_filter_process_format()
  12. 10.2.x modules/social_features/social_core/social_core.module \social_core_filter_process_format()

Remove ability of selecting format if full_html is available.

@todo Instead of defining the list of fields it would be better to add a separate Setting to all text_format fields, allowing to select whether to show format selector or not.

1 string reference to 'social_core_filter_process_format'
social_core_element_info_alter in modules/social_features/social_core/social_core.module
Implements hook_element_info_alter().

File

modules/social_features/social_core/social_core.module, line 414
The Social core module.

Code

function social_core_filter_process_format($element) {

  // Only fields listed here will have text format settings disabled.
  $full_html_field_ids = [
    'edit-body-0',
    'edit-field-profile-self-introduction-0',
    'edit-field-group-description-0',
  ];
  $element_id = $element['#id'];

  // Check if there is generated sub-id and cleanup it.
  if (($sub_id = strpos($element_id, '--')) !== FALSE) {
    $element_id = substr($element_id, 0, $sub_id);
  }
  $full_html = FilterFormat::load('full_html');
  $permission_name = $full_html
    ->getPermissionName();
  $account = \Drupal::currentUser();
  if ($element['#type'] == 'text_format' && $element['#format'] == 'full_html' && !$account
    ->hasPermission($permission_name)) {
    $element['#format'] = 'basic_html';
    $element['value']['#format'] = 'basic_html';
    $element['format']['format']['#default_value'] = 'basic_html';
    $element['format']['format']['#value'] = 'basic_html';
    $element['value']['#disabled'] = FALSE;
    $element['format']['format']['#access'] = FALSE;
    $element['format']['#access'] = TRUE;
    $key = array_search('filter_form_access_denied', $element['value']['#pre_render']);
    if (isset($element['value']['#pre_render'][$key])) {
      unset($element['value']['#pre_render'][$key]);
    }
  }
  elseif ($element['#type'] === 'text_format' && $account
    ->hasPermission($permission_name) && in_array($element_id, $full_html_field_ids)) {
    $element['#format'] = 'full_html';
    $element['format']['format']['#access'] = FALSE;
    $element['format']['format']['#value'] = 'full_html';
    $element['format']['help']['#access'] = FALSE;
    $element['format']['format']['#options'] = [
      'full_html' => 'Full HTML',
    ];
  }
  return $element;
}