You are here

function fontawesome_editor_js_settings_alter in Font Awesome Icons 8.2

Same name and namespace in other branches
  1. 8 fontawesome.module \fontawesome_editor_js_settings_alter()

Implements hook_editor_js_settings_alter().

This function allows for the proper functionality of the icons inside the CKEditor when using SVG with JS as the Font Awesome display method. This function also provides for the use of empty tags inside the CKEditor. These tags are normally stripped, which makes the traditional method of using Font Awesome unworkable. Allowing those tags here lets users use the methods of including icons described in all of the Font Awesome guides and docs.

See fontawesome_ckeditor_css_alter() for allowing the use of the icons inside CKEditor when using the Webfonts with CSS display method.

File

./fontawesome.module, line 447
Drupal integration with Font Awesome, the iconic font for use with Bootstrap.

Code

function fontawesome_editor_js_settings_alter(array &$settings) {

  // Load the configuration settings.
  $configuration_settings = \Drupal::config('fontawesome.settings');

  // Attach our JS libraries as needed for loading inside the editor.
  if ($configuration_settings
    ->get('method') == 'svg') {

    // SVG mode requires loading javascript.
    $fontawesome_library = \Drupal::service('library.discovery')
      ->getLibraryByName('fontawesome', 'fontawesome.svg');
    if (!$configuration_settings
      ->get('use_cdn')) {
      $fontawesome_library['js'][0]['data'] = base_path() . $fontawesome_library['js'][0]['data'];
    }
    $settings['editor']['fontawesome']['fontawesomeLibraries']['primary'] = $fontawesome_library['js'][0]['data'];

    // Load the shim file as well if needed.
    if ($configuration_settings
      ->get('use_shim')) {
      $fontawesome_library = \Drupal::service('library.discovery')
        ->getLibraryByName('fontawesome', 'fontawesome.svg.shim');
      if (!$configuration_settings
        ->get('use_cdn')) {
        $fontawesome_library['js'][0]['data'] = base_path() . $fontawesome_library['js'][0]['data'];
      }
      $settings['editor']['fontawesome']['fontawesomeLibraries']['shim'] = $fontawesome_library['js'][0]['data'];
    }
  }

  // Attach the list of allowed empty tags.
  $settings['editor']['fontawesome']['allowedEmptyTags'] = [
    'i',
    'span',
  ];
}