You are here

varbase_editor.module in Varbase Editor 7.3

Same filename and directory in other branches
  1. 8.7 varbase_editor.module
  2. 9.0.x varbase_editor.module

File

varbase_editor.module
View source
<?php

/**
 * @file
 * Code for the Varbase CKEditor feature.
 */
include_once 'varbase_editor.features.inc';

/**
 * Implements hook_wysiwyg_filter_elements_blacklist_alter().
 */
function varbase_editor_wysiwyg_filter_elements_blacklist_alter(&$blacklist) {
  $blacklist = array_diff($blacklist, array(
    'iframe',
    'object',
    'embed',
  ));
}

/**
 * Implements hook_media_wysiwyg_token_to_markup_alter().
 */
function varbase_editor_media_wysiwyg_token_to_markup_alter(&$element, &$tag_info, &$settings) {
  if (isset($element['#theme']) && $element['#theme'] == 'image_formatter') {

    // Add img-responsive class to images added through wysiwyg.
    $element['#attributes']['class'][] = 'img-responsive';
  }
  if (isset($element['content']['#view_mode']) && $element['content']['#view_mode'] == 'wysiwyg') {

    // Remove container added by media_wysiwyg_token_to_markup(),
    // this needs to be hadled by view_mode.
    unset($element['content']['#type']);
  }
}

/**
 * Implements template_preprocess_file_entity().
 */
function varbase_editor_preprocess_file_entity(&$variables) {

  // Move classes add by media from the removed container to the file_entity view_mode.
  // See varbase_support_media_wysiwyg_token_to_markup_alter().
  if (!empty($variables['elements']['#view_mode']) && $variables['elements']['#view_mode'] == 'wysiwyg') {
    if (isset($variables['elements']['#attributes']) && isset($variables['elements']['#attributes']['class'])) {
      $variables['classes_array'] = array_merge($variables['classes_array'], $variables['elements']['#attributes']['class']);
    }
  }
  if (!empty($variables['elements']['file']['#attributes']['style'])) {
    $variables['attributes_array']['style'] = '';
    $styles_array = media_wysiwyg_parse_css_declarations($variables['elements']['file']['#attributes']['style']);

    // move wysiwyg styles on image to the file view_mode wrapper.
    $variables['attributes_array']['style'] .= !empty($styles_array['width']) ? "width: {$styles_array['width']};" : '';
  }
}