You are here

panopoly_core.module in Panopoly Core 7

File

panopoly_core.module
View source
<?php

include_once 'panopoly_core.features.inc';

/**
 * Implements hook_menu_alter().
 */
function panopoly_core_menu_alter(&$items) {

  // Remove unnecessary 'title calback' => check_plain() that on node/add/%
  // pages from node.module.
  foreach (node_type_get_types() as $type) {
    $type_url_str = str_replace('_', '-', $type->type);
    $menu_item_key = 'node/add/' . $type_url_str;
    if (isset($items[$menu_item_key]['title callback']) && $items[$menu_item_key]['title callback'] == 'check_plain') {
      unset($items[$menu_item_key]['title callback']);
    }
  }
}

/**
 * Implements hook_apps_app_info()
 */
function panopoly_core_apps_app_info() {
  return array(
    'configure form' => 'panopoly_core_configure_form',
  );
}

/**
 * Configuration Form for Panopoly Core
 */
function panopoly_core_configure_form($form, &$form_state) {
  $form = array();
  $form['panopoly_core_breadcrumb_title'] = array(
    '#title' => t('Append Page Title to Site Breadcrumb'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => array(
      '1' => 'Enabled',
      '0' => 'Disabled',
    ),
    '#default_value' => variable_get('panopoly_core_breadcrumb_title', 1),
    '#description' => t('Do you want Panopoly to append the page title to the site breadcrumb?'),
  );
  $form['panopoly_core_override_jquery_ui_theme'] = array(
    '#title' => t('Override jQuery UI theme provided by any theme'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => array(
      '1' => 'Enabled',
      '0' => 'Disabled',
    ),
    '#default_value' => variable_get('panopoly_core_override_jquery_ui_theme', 1),
    '#description' => t('Panopoly provides a custom jQuery UI theme. If this option is disabled, it will only be used by themes that don\'t provide one of their own. However, if enabled, we\'ll override all themes.'),
  );
  return system_settings_form($form);
}

/**
 * Implements hook_theme_registry_alter().
 */
function panopoly_core_theme_registry_alter(&$registry) {

  // Ensure that panopoly_core_preprocess_page() always runs last.
  if (($index = array_search('panopoly_core_preprocess_page', $registry['page']['preprocess functions'])) !== FALSE) {
    array_splice($registry['page']['preprocess functions'], $index, 1);
  }
  $registry['page']['preprocess functions'][] = 'panopoly_core_preprocess_page';
}

/**
 * Implementation of hook_preprocess_html()
 *
 * We are telling the site that everything is a region-content. This is important since
 * when we disable the block module it loses this classes which some things assume for generalized
 * CSS considerations (i.e. Bartik's spacing of ul/ol).
 */
function panopoly_core_preprocess_html(&$variables) {
  $variables['classes_array'][] = 'region-content';
}

/**
 * Implements hook_preprocess_page().
 */
function panopoly_core_preprocess_page(&$variables) {

  // The breadcrumbs are rendered in template_process_page(), so this is an
  // opportunity to modify them right before that.
  if (variable_get('panopoly_core_breadcrumb_title', TRUE)) {
    $breadcrumb = drupal_get_breadcrumb();
    if (drupal_is_front_page()) {

      // If it is the homepage, remove the breadcrumb.
      $breadcrumb = array();
    }
    elseif (is_array($breadcrumb) && count($breadcrumb) > 0 && drupal_get_title()) {

      // Set the current page title in the breadcrumb.
      $breadcrumb[] = drupal_get_title();
    }
    drupal_set_breadcrumb($breadcrumb);
  }
}

/**
 * Implements hook_apps_servers_info()
 */
function panopoly_core_apps_servers_info() {
  $info = drupal_parse_info_file(drupal_get_path('module', 'panopoly_core') . '/panopoly_core.info');
  return array(
    'panopoly' => array(
      'title' => 'Panopoly',
      'description' => 'Apps for Panopoly',
      'manifest' => empty($info['version']) || $info['version'] == '7.x-1.x-dev' || strpos($info['version'], '-dev') ? 'http://apps.getpantheon.com/panopoly-dev' : 'http://apps.getpantheon.com/panopoly',
    ),
  );
}

/**
 * Implements hook_module_implements_alter().
 */
function panopoly_core_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'css_alter' || $hook == 'modules_enabled') {
    $group = $implementations['panopoly_core'];
    unset($implementations['panopoly_core']);
    $implementations['panopoly_core'] = $group;
  }
}

/**
 * Implementation hook_element_info_alter().
 */
function panopoly_core_element_info_alter(&$type) {

  // Rather than implementing hook_css_alter(), we'll add a custom pre render
  // function for the styles elemement. This is to allow us to override
  // seven_css_alter(), which always runs after any module's implementation.
  if (isset($type['styles']['#pre_render'])) {
    array_unshift($type['styles']['#pre_render'], 'panopoly_core_pre_render_styles');
  }
}

/**
 * Implements hook_modules_enabled().
 *
 * This hook is implemented to assign some default permissions for panelizer's handling
 * of taxonomy terms. This has to be done in this hook to run after both features
 * and defaultconfig which power the functionality. Hopefully a more general solution
 * can be found. More information - http://drupal.org/node/1837312.
 */
function panopoly_core_modules_enabled($modules) {

  // Only run this logic if we are executing as part of an install profile
  // and only for this particular module.
  if (drupal_installation_attempted() && in_array('panopoly_core', $modules)) {

    // Rebuild some caches so this all works right
    taxonomy_features_rebuild('panopoly_core');
    drupal_static_reset('panelizer_entity_plugin_get_handler');

    // Define some permissions for the editor role
    if ($editor = user_role_load_by_name('editor')) {
      user_role_grant_permissions($editor->rid, array(
        'administer panelizer taxonomy_term panopoly_categories breadcrumbs',
      ));
      user_role_grant_permissions($editor->rid, array(
        'administer panelizer taxonomy_term panopoly_categories content',
      ));
      user_role_grant_permissions($editor->rid, array(
        'administer panelizer taxonomy_term panopoly_categories context',
      ));
      user_role_grant_permissions($editor->rid, array(
        'administer panelizer taxonomy_term panopoly_categories defaults',
      ));
      user_role_grant_permissions($editor->rid, array(
        'administer panelizer taxonomy_term panopoly_categories layout',
      ));
      user_role_grant_permissions($editor->rid, array(
        'administer panelizer taxonomy_term panopoly_categories overview',
      ));
      user_role_grant_permissions($editor->rid, array(
        'administer panelizer taxonomy_term panopoly_categories settings',
      ));
    }

    // Define some permissions for the admin role
    if ($administrator = user_role_load_by_name('administrator')) {
      user_role_grant_permissions($administrator->rid, array(
        'administer panelizer taxonomy_term panopoly_categories breadcrumbs',
      ));
      user_role_grant_permissions($administrator->rid, array(
        'administer panelizer taxonomy_term panopoly_categories content',
      ));
      user_role_grant_permissions($administrator->rid, array(
        'administer panelizer taxonomy_term panopoly_categories context',
      ));
      user_role_grant_permissions($administrator->rid, array(
        'administer panelizer taxonomy_term panopoly_categories defaults',
      ));
      user_role_grant_permissions($administrator->rid, array(
        'administer panelizer taxonomy_term panopoly_categories layout',
      ));
      user_role_grant_permissions($administrator->rid, array(
        'administer panelizer taxonomy_term panopoly_categories overview',
      ));
      user_role_grant_permissions($administrator->rid, array(
        'administer panelizer taxonomy_term panopoly_categories settings',
      ));
    }
  }
}

/**
 * Implementation of hook_css_alter()
 */
function panopoly_core_css_alter() {

  // Deprecated
}

/**
 * Implements hook_library_alter().
 */
function panopoly_core_library_alter(&$libraries, $module) {
  if ($module == 'system') {

    // Installs our custom jQuery UI theme.
    if (isset($libraries['ui'])) {
      if (isset($libraries['ui']['css']['misc/ui/jquery.ui.theme.css'])) {
        $libraries['ui']['css']['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('module', 'panopoly_core') . '/css/panopoly-jquery-ui-theme.css';
      }
      if (isset($libraries['ui']['css']['misc/ui/jquery.ui.core.css'])) {
        unset($libraries['ui']['css']['misc/ui/jquery.ui.core.css']);
      }
    }

    // If our jQuery UI theme is in use, then we need to remove unnecessary CSS,
    // because it's all merged into our theme.
    $jquery_ui_unnecessary_css = array(
      'ui.button',
      'ui.resizable',
      'ui.selectable',
      'ui.dialog',
      'ui.tabs',
    );
    foreach ($jquery_ui_unnecessary_css as $name) {
      if (isset($libraries[$name])) {
        if (isset($libraries[$name]['css'])) {
          unset($libraries[$name]['css']);
        }
      }
    }
  }
}

/**
 * Pre render the styles element.
 */
function panopoly_core_pre_render_styles($elements) {
  $css =& $elements['#items'];

  // We only need to mess with the CSS if a jQuery UI theme is loaded.
  if (!isset($css['misc/ui/jquery.ui.theme.css'])) {
    return $elements;
  }
  $seven_theme = drupal_get_path('theme', 'seven') . '/jquery.ui.theme.css';

  // Always override the Seven theme's jQuery UI theme (because its for an
  // earlier version of jQuery UI and doesn't quite work right).
  if ($css['misc/ui/jquery.ui.theme.css']['data'] === $seven_theme || variable_get('panopoly_core_override_jquery_ui_theme', 1)) {
    $css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('module', 'panopoly_core') . '/css/panopoly-jquery-ui-theme.css';
  }
  return $elements;
}

/**
 * Implements hook_date_format_types()
 */
function panopoly_core_date_format_types() {
  return array(
    'panopoly_time' => t('Time'),
    'panopoly_day' => t('Day'),
  );
}

/**
 * Implements hook_date_formats().
 */
function panopoly_core_date_formats() {
  $formats = array();
  $formats[] = array(
    'type' => 'panopoly_time',
    'format' => 'g:ia',
    'locales' => array(),
  );
  $formats[] = array(
    'type' => 'panopoly_day',
    'format' => 'F j, Y',
    'locales' => array(),
  );
  return $formats;
}

/**
 * Helpfer function to get view modes
 */
function panopoly_core_view_mode_options() {
  $entity_info = entity_get_info('node');
  $options = array();
  if (!empty($entity_info['view modes'])) {
    foreach ($entity_info['view modes'] as $mode => $settings) {
      if (!in_array($mode, array(
        'rss',
        'search_index',
        'search_result',
        'token',
      ))) {
        $options[$mode] = $settings['label'];
      }
    }
  }
  return $options;
}

/**
 * Helpfer function to import demo content for apps using Migrate.
 */
function _panopoly_core_import_demo_content($classes = array()) {

  // Ensure that migration classes are registered.
  migrate_get_module_apis(TRUE);

  // Process the migrations to import demo content.
  foreach ($classes as $class) {

    // Register the Migration class since auto-registration is not supported
    // since Migrate module version 2.6
    Migration::registerMigration($class);

    // Get a handle on our migration class.
    $migration = Migration::getInstance($class);

    // Disable message output from migrate ince this import is used within
    // the context of the Apps module where these messages make no sense.
    Migration::setDisplayFunction('_panopoly_core_null_message');

    // Process the migration.
    $migration
      ->processImport();
  }
}

/**
 * Helpfer function to import demo content for apps using Migrate.
 */
function _panopoly_core_rollback_demo_content($classes = array()) {

  // Roll back the migrations to delete the demo content.
  foreach ($classes as $class) {

    // Get a handle on our migration class.
    $migration = Migration::getInstance($class);

    // Disable message output from migrate ince this import is used within
    // the context of the Apps module where these messages make no sense.
    Migration::setDisplayFunction('_panopoly_core_null_message');

    // Roll back the migration.
    $migration
      ->processRollback();

    // deregister the Migration classes since it will not exist after the
    // module is disabled.
    Migration::deregisterMigration($class);
  }
}

/**
 * Helpfer function to import demo content for apps using Migrate.
 */
function _panopoly_core_null_message($message, $level) {
  return;
}

Functions

Namesort descending Description
panopoly_core_apps_app_info Implements hook_apps_app_info()
panopoly_core_apps_servers_info Implements hook_apps_servers_info()
panopoly_core_configure_form Configuration Form for Panopoly Core
panopoly_core_css_alter Implementation of hook_css_alter()
panopoly_core_date_formats Implements hook_date_formats().
panopoly_core_date_format_types Implements hook_date_format_types()
panopoly_core_element_info_alter Implementation hook_element_info_alter().
panopoly_core_library_alter Implements hook_library_alter().
panopoly_core_menu_alter Implements hook_menu_alter().
panopoly_core_modules_enabled Implements hook_modules_enabled().
panopoly_core_module_implements_alter Implements hook_module_implements_alter().
panopoly_core_preprocess_html Implementation of hook_preprocess_html()
panopoly_core_preprocess_page Implements hook_preprocess_page().
panopoly_core_pre_render_styles Pre render the styles element.
panopoly_core_theme_registry_alter Implements hook_theme_registry_alter().
panopoly_core_view_mode_options Helpfer function to get view modes
_panopoly_core_import_demo_content Helpfer function to import demo content for apps using Migrate.
_panopoly_core_null_message Helpfer function to import demo content for apps using Migrate.
_panopoly_core_rollback_demo_content Helpfer function to import demo content for apps using Migrate.