You are here

panopoly_wysiwyg.install in Panopoly WYSIWYG 7

Same filename and directory in other branches
  1. 8.2 panopoly_wysiwyg.install

Install hooks for Panopoly WYSIWYG.

File

panopoly_wysiwyg.install
View source
<?php

/**
 * @file
 * Install hooks for Panopoly WYSIWYG.
 */

/**
 * Ensure that filter settings get updated.
 */
function panopoly_wysiwyg_update_7101() {
  features_revert(array(
    'panopoly_wysiwyg' => array(
      'filter',
    ),
  ));
}

/**
 * Add image classes to captions so responsive images don't break
 */
function panopoly_wysiwyg_update_7102() {

  // Because of the way Drupal handles filter_format_load() we need to use the method
  // outlined here: https://www.drupal.org/node/1304930
  $format = filter_format_load('panopoly_wysiwyg_text');
  if (empty($format->filters)) {
    $filters = filter_list_format($format->format);
    $format->filters = array();
    foreach ($filters as $name => $filter) {
      foreach ($filter as $k => $v) {
        $format->filters[$name][$k] = $v;
      }
    }
  }

  // Add the 'panopoly_images_fix_captions' filter
  $format->filters['panopoly_images_fix_captions'] = array(
    'weight' => 0,
    'status' => 1,
  );

  // Save the updated format.
  filter_format_save($format);
}

/**
 * Remove the 'Convert line breaks into HTML' filter from the WYSIWYG format.
 */
function panopoly_wysiwyg_update_7103() {

  // Because of the way Drupal handles filter_format_load() we need to use the method
  // outlined here: https://www.drupal.org/node/1304930
  $format = filter_format_load('panopoly_wysiwyg_text');
  if (empty($format->filters)) {
    $filters = filter_list_format($format->format);
    $format->filters = array();
    foreach ($filters as $name => $filter) {
      foreach ($filter as $k => $v) {
        $format->filters[$name][$k] = $v;
      }
    }
  }

  // Disable the 'filter_autop' filter.
  $format->filters['filter_autop']['status'] = 0;
  filter_format_save($format);
}

/**
 * Make sure that users can insert into the WYSIWYG.
 */
function panopoly_wysiwyg_update_7104() {

  // This is duplicated from panopoly_widgets_update_7016() where this code
  // was originally place erroneously. We decided not to remove it for
  // consistency (so sites that upgraded later would have the same settings
  // as those we graded earlier) which is why this exists in both places.
  $roles = user_roles(TRUE, 'access media browser');
  foreach ($roles as $rid => $role) {
    user_role_grant_permissions($rid, array(
      'use media wysiwyg',
    ));
  }
}

/**
 * Clean up the HTML wysiwyg profile.
 */
function panopoly_wysiwyg_update_7105() {
  $unused_settings = array(
    'block_formats',
    'convert_fonts_to_spans',
    'paste_auto_cleanup_on_paste',
    'path_loc',
    'remove_linebreaks',
    'resizing',
    'theme',
    'toolbar_align',
    'toolbar_loc',
    'verify_html',
  );
  $query = db_select('wysiwyg', 'w')
    ->fields('w', array(
    'format',
    'editor',
    'settings',
  ))
    ->condition('w.format', 'panopoly_html_text')
    ->condition('w.editor', 'markitup');
  $profile = $query
    ->execute()
    ->fetchObject();
  if ($profile) {
    $settings = unserialize($profile->settings);
    foreach ($unused_settings as $name) {
      unset($settings[$name]);
    }
    db_update('wysiwyg')
      ->condition('format', $profile->format)
      ->fields(array(
      'settings' => serialize($settings),
    ))
      ->execute();
  }
}

Functions

Namesort descending Description
panopoly_wysiwyg_update_7101 Ensure that filter settings get updated.
panopoly_wysiwyg_update_7102 Add image classes to captions so responsive images don't break
panopoly_wysiwyg_update_7103 Remove the 'Convert line breaks into HTML' filter from the WYSIWYG format.
panopoly_wysiwyg_update_7104 Make sure that users can insert into the WYSIWYG.
panopoly_wysiwyg_update_7105 Clean up the HTML wysiwyg profile.