You are here

panopoly_admin.module in Panopoly 7

Same filename and directory in other branches
  1. 8.2 modules/panopoly/panopoly_admin/panopoly_admin.module

File

modules/panopoly/panopoly_admin/panopoly_admin.module
View source
<?php

/**
 * @file
 */
include_once 'panopoly_admin.features.inc';

/**
 * Implementation of hook_apps_app_info()
 */
function panopoly_admin_apps_app_info() {
  return array(
    'configure form' => 'panopoly_admin_configure_form',
  );
}

/**
 * Configuration Form for Panopoly Admin
 */
function panopoly_admin_configure_form($form, &$form_state) {
  $form = array();
  $form['panopoly_admin_machine_name'] = array(
    '#title' => t('Machine Name'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => array(
      '1' => 'Enabled',
      '0' => 'Disabled',
    ),
    '#default_value' => variable_get('panopoly_admin_machine_name', 0),
    '#description' => t('Do you want to provide an option to specify a machine name (provided by the Default Content module) on the content editing form?'),
  );
  $form['panopoly_admin_front_page_and_sticky'] = array(
    '#title' => t('Front Page and Sticky Options'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => array(
      '1' => 'Enabled',
      '0' => 'Disabled',
    ),
    '#default_value' => variable_get('panopoly_admin_front_page_and_sticky', 0),
    '#description' => t('Do you want to provide the front page and sticky options on node content?'),
  );
  $form['panopoly_admin_link_description'] = array(
    '#title' => t('Menu Link Description'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => array(
      '1' => 'Enabled',
      '0' => 'Disabled',
    ),
    '#default_value' => variable_get('panopoly_admin_link_description', 0),
    '#description' => t('Do you want to provide a description field for a menu item link on the node edit page?'),
  );
  $form['panopoly_admin_advanced_plugins'] = array(
    '#title' => t('Use Advanced Panel Plugins'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => array(
      '1' => 'Enabled',
      '0' => 'Disabled',
    ),
    '#default_value' => variable_get('panopoly_admin_advanced_plugins', 0),
    '#description' => t('Do you want to enable the advanced Panel plugins in the Panopoly pane library? This includes rarely used Panel plugins for such things as view context, token support, and page elements?'),
  );
  return system_settings_form($form);
}

/**
 * Implementation of hook_ctools_plugin_directory()
 */
function panopoly_admin_ctools_plugin_directory($module, $plugin) {
  return 'plugins/' . $plugin;
}

/**
 * Implements hook_panels_pane_content_alter().
 */
function panopoly_admin_panels_pane_content_alter($content, $pane, $args, $context) {

  // Pass the title properly through to style plugins rendering regions
  $pane->title = isset($content->title) ? $content->title : NULL;

  // Hide the title of administrative panes when there isn't any content
  if (!empty($context['argument_node_edit_1']) && !empty($content->content) && is_array($content->content)) {
    foreach ($content->content as $content_item) {
      if (is_array($content_item) && isset($content_item['#access']) && $content_item['#access'] === FALSE) {
        $content->title = '';
      }
    }
  }
}

/**
 * Implements hook_theme_registry_alter().
 */
function panopoly_admin_theme_registry_alter(&$registry) {
  if (isset($registry['panels_add_content_modal'])) {

    // Put our preprocess function before the default one from Panels.
    $index = array_search('template_preprocess_panels_add_content_modal', $registry['panels_add_content_modal']['preprocess functions']);
    if ($index !== FALSE) {
      array_splice($registry['panels_add_content_modal']['preprocess functions'], $index, 0, 'panopoly_admin_prepreprocess_panels_add_content_modal');
    }
  }
}

/**
 * Preprocess the panels_add_content_modal() theme function.
 */
function panopoly_admin_prepreprocess_panels_add_content_modal(&$vars) {
  if (!variable_get('panopoly_admin_advanced_plugins', FALSE)) {

    // Remove advanced Panes from the 'Add content' modal.
    foreach ($vars['categories'] as $category_name => $category) {
      foreach ($category['content'] as $pane_name => $pane) {
        if (panopoly_admin_is_advanced_plugin($pane['title'], $category['title'])) {
          unset($vars['categories'][$category_name]['content'][$pane_name]);
        }
      }

      // If an entire category has been emptied, remove it as well.
      if (empty($vars['categories'][$category_name]['content'])) {
        unset($vars['categories'][$category_name]);
      }
    }
  }
}

/**
 * Implementation of hook_ctools_content_subtype_alter()
 */
function panopoly_admin_ctools_content_subtype_alter(&$subtype, &$plugin) {
  $category_label = is_string($subtype['category']) ? $subtype['category'] : $subtype['category'][0];

  // Switch the labeling of "Miscellaneous" to "Blocks"
  if ($category_label == 'Miscellaneous') {
    $subtype['category'] = 'Blocks';
  }
}

/**
 * Implementation of hook_form_alter()
 */
function panopoly_admin_form_alter(&$form, &$form_state, $form_id) {
  global $base_url;

  // Improve the title field
  if (isset($form['title']['#title'])) {
    $form['title']['#title_display'] = 'invisible';
    $form['title']['#attributes']['placeholder'] = $form['title']['#title'];
  }

  // Improve the node edit form
  if (isset($form['#entity_type']) && $form['#entity_type'] == 'node') {

    // Improve the URL selection form
    if (isset($form['path']) && isset($form['path']['alias'])) {
      unset($form['path']['#type']);

      // remove the fieldset
      unset($form['path']['alias']['#description']);
      $form['path']['alias']['#title'] = '<strong>' . t('Permalink') . ':</strong> ';
      $form['path']['alias']['#field_prefix'] = $base_url . '/';
      if (isset($form['path']['pathauto'])) {
        $form['path']['pathauto']['#access'] = FALSE;

        // Alter the place holder text based on the pathauto default value.
        $form['path']['alias']['#attributes'] = array(
          'placeholder' => '<' . t('magically generated') . '>',
        );
        $form['path']['alias']['#states'] = array();
        $form['#submit'][] = 'panopoly_admin_pathauto_submit';
      }
    }

    // Add clearfix to node body container to prevent clearing issue with
    // vertical tabs - @see https://drupal.org/node/1686500
    if (isset($form['body']['#type']) && $form['body']['#type'] == 'container') {
      $form['body']['#attributes']['class'][] = 'clearfix';
    }

    // Hide the body label if it's 'Body' (which isn't terribly helpful) and the
    // field is required.
    if (!empty($form['body'][LANGUAGE_NONE][0]['#required']) && $form['body'][LANGUAGE_NONE][0]['#title'] == t('Body')) {
      if ($form['body'][LANGUAGE_NONE][0]['summary']['#type'] == 'textarea') {

        // We can't just set '#title_display' to invisible because it'll break
        // the summary Javascript. So, we just set a class which we'll use in
        // our own Javascript to hide the label.
        $form['body']['#attributes']['class'][] = 'panopoly-admin-hide-body-label';
      }
      else {
        $form['body'][LANGUAGE_NONE][0]['#title_display'] = 'invisible';
      }
    }

    // Improve the publishing options by remove promote to front page and sticky
    if (isset($form['options']) && !variable_get('panopoly_admin_front_page_and_sticky', 0)) {
      $form['options']['promote']['#access'] = FALSE;
      $form['options']['sticky']['#access'] = FALSE;
    }

    // Improve authoring options
    if (isset($form['author'])) {
      unset($form['author']['name']['#description']);
      $form['author']['name']['#title'] = t('Author');
      $form['author']['name']['#size'] = '40';
      $form['author']['name']['#weight'] = 4;
      $form['author']['date']['#weight'] = 5;

      // Adjust options for Date Popup Module
      if (module_exists('date_popup_authored')) {
        $form['author']['date']['#title_display'] = 'invisible';
        $form['author']['date']['#size'] = 20;
      }
    }
  }

  // Improve and potentially hide the machine name option from Default Content
  if (isset($form['machine_name_fs'])) {
    $form['options']['machine_name_fs']['machine_name'] = $form['machine_name_fs']['machine_name'];
    $form['options']['machine_name_fs']['machine_name']['#size'] = '';
    $form['options']['machine_name_fs']['#weight'] = 30;
    $form['options']['machine_name_fs']['#access'] = variable_get('panopoly_admin_machine_name', FALSE);
    unset($form['options']['machine_name_fs']['machine_name']['#description']);
    unset($form['machine_name_fs']);
  }

  // Move the featured field into publishing options
  if (!empty($form['field_featured_status']) && $form['options']['#access']) {
    $form['options']['field_featured_status'] = $form['field_featured_status'];
    $form['field_featured_status'] = array(
      '#language' => $form['options']['field_featured_status']['#language'],
    );
  }

  // Remove the description from the featured image
  if (!empty($form['field_featured_image'])) {
    $form['field_featured_image'][LANGUAGE_NONE][0]['#title_display'] = 'invisible';
  }
  if (!empty($form['field_featured_categories']) && $form['field_featured_categories'][LANGUAGE_NONE]['#type'] != 'textfield') {
    $form['field_featured_categories'][LANGUAGE_NONE]['#title_display'] = 'invisible';

    // Hide the featured category field if there are no featured category options
    if (count($form['field_featured_categories'][LANGUAGE_NONE]['#options']) == 0 || !empty($form['field_featured_categories'][LANGUAGE_NONE]['#options']['_none']) && count($form['field_featured_categories'][LANGUAGE_NONE]['#options']) == 1) {
      $form['field_featured_categories']['#access'] = FALSE;
    }
  }

  // Improve the revision interface
  if (!empty($form['revision_information']['revision']['#access'])) {
    $form['revision_information']['log']['#states'] = array(
      'visible' => array(
        'input[name="revision"]' => array(
          'checked' => TRUE,
        ),
      ),
    );
    $form['revision_information']['log']['#weight'] = 10;
    $form['revision_information']['log']['#title_display'] = 'invisible';
    $form['revision_information']['revision']['#weight'] = 9;
    $form['options']['revision'] = $form['revision_information']['revision'];
    $form['options']['log'] = $form['revision_information']['log'];
    unset($form['revision_information']['#type']);
    unset($form['revision_information']['log']);
    unset($form['revision_information']['revision']);
  }

  // Improve the menu adding experience
  if (isset($form['menu']) && isset($form['menu']['enabled']) && !empty($form['menu']['#access'])) {
    $form['menu']['link']['link_title']['#size'] = '';
    $form['menu']['link']['weight']['#access'] = FALSE;
    $form['menu']['link']['link_title']['#title'] = t('Link title');
    $form['menu']['link']['parent']['#title'] = t('Parent');
    $form['menu']['link']['description']['#access'] = variable_get('panopoly_admin_link_description', FALSE);
    $form['#validate'][] = 'panopoly_admin_menu_validate';
  }
}

/**
 * Implementation of hook_module_implements_alter()
 */
function panopoly_admin_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'form_alter' || $hook == 'ctools_content_subtype_alter') {
    $group = $implementations['panopoly_admin'];
    unset($implementations['panopoly_admin']);
    $implementations['panopoly_admin'] = $group;
  }
}

/**
 * Submit function for adding pathauto settings
 */
function panopoly_admin_pathauto_submit($form, &$form_state) {
  $values = $form_state['values'];
  $autogenerate = TRUE;

  // If the submitted 'alias' is NOT empty then we potentially may not want to
  // auto-generate.
  if (!empty($values['path']['alias'])) {

    // If the submitted alias differs than the previous form default value then
    // the user is attempting to manually set it.
    if ($values['path']['alias'] != $form['path']['alias']['#default_value']) {
      $autogenerate = FALSE;
    }
    elseif (!empty($form['path']['pathauto']) && !$form['path']['pathauto']['#default_value']) {
      $autogenerate = FALSE;
    }
  }
  $form_state['values']['path']['pathauto'] = $autogenerate;
  $form_state['input']['path']['pathauto'] = $autogenerate;
}

/**
 * Validate function for adding menu validation
 */
function panopoly_admin_menu_validate($form, &$form_state) {
  if (!empty($form_state['input']['menu']['enabled']) && empty($form_state['input']['menu']['link_title'])) {
    form_set_error('link_title', t('Menu link title is required.'));
  }
}

/**
 * Implementation of hook_menu
 */
function panopoly_admin_menu() {

  // Panelizer "revert" page callback
  $items['admin/site/panelizer-delete/%/%'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'panopoly_admin_panelizer_delete_form',
      3,
      4,
    ),
    'access callback' => 'panopoly_admin_panelizer_revert_access',
    'access arguments' => array(
      3,
      4,
    ),
  );

  // Panels pane layout enable/disable page callback
  $items['admin/panopoly/panes/layout/%/%/%'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'panopoly_admin_switch_layout_action',
    'page arguments' => array(
      4,
      5,
      6,
    ),
    'access callback' => 'panopoly_admin_panels_layout_access',
  );

  // Add a local action link for the flexible layout builder
  $items['admin/panopoly/layouts/add-flexible'] = array(
    'title' => 'Add Flexible Layout',
    'description' => 'This will add a flexible layout to Panels',
    'page callback' => 'drupal_goto',
    'page arguments' => array(
      'admin/structure/panels/layouts/add-flexible',
    ),
    'type' => MENU_LOCAL_ACTION,
    'access arguments' => array(
      'administer page manager',
    ),
  );

  // Panels pane enable/disable page callback
  $items['admin/panopoly/panes/pane/%/%/%/%'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'panopoly_admin_switch_pane_action',
    'page arguments' => array(
      4,
      5,
      6,
      7,
    ),
    'access arguments' => array(
      'administer page manager',
    ),
  );

  // Add an administration page for Panopoly
  $items['admin/panopoly'] = array(
    'title' => 'Panopoly',
    'description' => 'Administer all things Panopoly.',
    'weight' => -8,
    'position' => 'left',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array(
      'access administration pages',
    ),
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
  );

  // Add an administration section for Panopoly settings
  $items['admin/panopoly/settings'] = array(
    'title' => 'Panopoly Settings',
    'description' => 'Configuration related to Panopoly',
    'weight' => 50,
    'position' => 'left',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
  );

  // Add settings pages for Panopoly and Panopoly Apps
  foreach (module_list() as $module) {
    $app_info = module_invoke($module, 'apps_app_info');
    if (!empty($app_info) && !empty($app_info['configure form'])) {
      $module_info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info');
      if (!empty($module_info['package']) && $module_info['package'] == 'Panopoly') {
        $items['admin/panopoly/settings/' . $module] = array(
          'title' => $module_info['name'],
          'description' => 'This is the configuration screen for ' . $module_info['name'],
          'page callback' => 'drupal_get_form',
          'page arguments' => array(
            $app_info['configure form'],
          ),
          'access arguments' => array(
            'administer site configuration',
          ),
        );
      }
      elseif (!empty($module_info['package']) && $module_info['package'] == 'Panopoly Apps') {
        $items['admin/panopoly/settings/' . $module] = array(
          'title' => $module_info['name'],
          'description' => 'This is the configuration screen for ' . $module_info['name'],
          'page callback' => 'drupal_get_form',
          'page arguments' => array(
            $app_info['configure form'],
          ),
          'access arguments' => array(
            'administer site configuration',
          ),
        );
        if (!empty($app_info['demo content module']) && !empty($app_info['demo content link path'])) {
          if (module_exists($app_info['demo content module'])) {
            $items[$app_info['demo content link path'] . '/disable_demo_content'] = array(
              'title' => 'Disable Demo Content',
              'description' => 'This will disable the demo content that is provided by this app.',
              'page callback' => 'drupal_get_form',
              'type' => MENU_LOCAL_ACTION,
              'page arguments' => array(
                'panopoly_admin_disable_demo_content_form',
                $app_info['demo content module'],
                $app_info['demo content link path'],
              ),
              'access arguments' => array(
                'administer apps',
              ),
            );
          }
        }
      }
    }
  }
  return $items;
}

/**
 * Access handler for Panelizer revert functionality
 */
function panopoly_admin_panelizer_revert_access($entity_type, $entity_id) {

  // Allow if the user can administer panelizer
  if (user_access('administer panelizer')) {
    return TRUE;
  }

  // Allow if the user can administer the specific panelizer item
  // TODO - do we also want to check ability to modify panelizer setting?
  $entities = entity_load($entity_type, array(
    $entity_id,
  ));
  if (entity_access('update', $entity_type, $entities[$entity_id])) {
    return TRUE;
  }

  // Otherwise not allowed
  return FALSE;
}

/**
 * Access handler for changing Panels layouts
 */
function panopoly_admin_panels_layout_access() {
  return user_access('administer page manager');
}

/**
 * Implementation of hook_menu_alter()
 */
function panopoly_admin_menu_alter(&$items) {

  // Set the description of the page library
  $items['admin/panopoly/pages']['description'] = 'This is the page library for the site. See your landing pages, page templates, and overriden page templates.';

  // Set the description of the layout library
  $items['admin/panopoly/layouts']['description'] = 'This is the layout library for the site. See your preset and custom layouts.';

  // Set the description of the pane library
  $items['admin/panopoly/panes']['description'] = 'This is the pane library for the site. See all of the panes you can add to your pages.';

  // Adjust the "Pages" page created by Panels to have a more specific permission set
  $items['admin/structure/pages']['access arguments'] = array(
    'administer page manager',
  );

  // Adjust the "Configuration" page to only show when the user can change the configuration options
  $items['admin/config']['access arguments'] = array(
    'administer site configuration',
  );
}

/**
 * Implementation of hook_link_alter()
 */
function panopoly_admin_menu_link_alter(&$item) {

  // Automatically set all of the settings elements to be children of the main parent element
  // Not entirely sure why the menu system doesn't do this for us.
  if (!empty($item['path']) && strpos($item['path'], 'panopoly/settings/')) {
    $parent_mlid = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path", array(
      ':path' => 'admin/panopoly/settings',
    ))
      ->fetchField();
    $item['plid'] = $parent_mlid;
  }
}

/**
 * Callback form to disable demo content for an app
 */
function panopoly_admin_disable_demo_content_form($form, &$form_state, $demomodule, $redirect) {
  $form = array();
  drupal_set_title('Disable Demo Content?');
  $form['redirect'] = array(
    '#type' => 'value',
    '#value' => $redirect,
  );
  $form['demomodule'] = array(
    '#type' => 'value',
    '#value' => $demomodule,
  );
  $form['submit'] = array(
    '#value' => t('Disable Demo Content'),
    '#type' => 'submit',
  );
  return $form;
}

/**
 * Submit handler for disabling demo content
 */
function panopoly_admin_disable_demo_content_form_submit($form, &$form_state) {
  module_disable(array(
    $form_state['values']['demomodule'],
  ));
  menu_rebuild();
  drupal_goto($form_state['values']['redirect']);
}

/**
 * Utility function for parsing basic entity info.
 */
function panopoly_admin_entity_parse_info($entity, $type) {
  $entity_info = array();
  switch ($type) {
    case 'node':
      $entity_info['title'] = $entity->title;
      $entity_info['type'] = 'node';
      $entity_info['bundle_type'] = $entity->type;
      $entity_info['id'] = $entity->nid;
      break;
    case 'user':
      $entity_info['title'] = $entity->name;
      $entity_info['type'] = 'user';
      $entity_info['bundle_type'] = 'user';
      $entity_info['id'] = $entity->uid;
      break;
    case 'taxonomy_term':
      $entity_info['title'] = $entity->name;
      $entity_info['type'] = 'taxonomy_term';
      $entity_info['bundle_type'] = $entity->vocabulary_machine_name;
      $entity_info['id'] = $entity->tid;
      break;
  }
  return $entity_info;
}

/**
 * Confirmation form for deleting a panelizer revision.
 */
function panopoly_admin_panelizer_delete_form($form, &$form_state, $entity_type, $entity_id) {
  $entities = entity_load($entity_type, array(
    $entity_id,
  ));
  if (!empty($entities)) {
    $entity = reset($entities);
  }
  $entity_info = panopoly_admin_entity_parse_info($entity, $entity_type);
  $form['#redirect'] = 'admin/site';
  $form['entity_type'] = array(
    '#type' => 'value',
    '#value' => $entity_info['type'],
  );
  $form['entity_id'] = array(
    '#type' => 'value',
    '#value' => $entity_info['id'],
  );
  $form['entity_title'] = array(
    '#type' => 'value',
    '#value' => $entity_info['title'],
  );
  return confirm_form($form, t('Are you sure you want to delete the overridden page template for %title?', array(
    '%title' => $entity_info['title'],
  )), 'admin/site');
}

/**
 * Submit function for deleting a panelizer revision.
 */
function panopoly_admin_panelizer_delete_form_submit($form, &$form_state) {
  $form_state['redirect'] = 'admin/panopoly/pages';
  db_delete('panelizer_entity')
    ->condition('entity_type', $form_state['values']['entity_type'])
    ->condition('entity_id', $form_state['values']['entity_id'])
    ->execute();
  drupal_set_message(t('The overridden page template for %title has been deleted.', array(
    '%title' => $form_state['values']['entity_title'],
  )));
}

/**
 * Helper function to identify advanced plugins
 */
function panopoly_admin_is_advanced_plugin($pane_label, $category_label) {

  // Specifically excluded categories
  $fixed_advanced_plugins = array(
    'View context',
    // support for views context
    'Page elements',
    // sitewide panes that don't work so well in $content region
    'Facet API',
    // default facet api options subsumed into "Search Facets" option
    'File',
    // support for file items that is just confusing
    'Fieldable_panels_pane',
    // duplicated fields for custom panes
    'Existing pages',
    // pages from pm existing pages module that will break the site
    // TODO: this should be added via an alter hook or something!
    'Panopoly Test Advanced',
  );

  // Specifically excluded panes
  $fixed_advanced_panes = array(
    'Panels pane',
    // default fieldable panels panes entity we don't need
    'Execute PHP',
    // sigh
    'Devel',
    // devel option for advanced users
    'Switch user',
    // devel option for advanced users
    'Theme switcher',
    // devel option for advanced users
    'User menu',
    // user menu
    'Development',
    // development menu
    'Management',
    // management menu
    'Navigation',
    // navigation menu
    '<em class="placeholder">User menu</em> menu tree',
    // user menu men tree
    '<em class="placeholder">Development</em> menu tree',
    // development menu tree
    '<em class="placeholder">Management</em> menu tree',
    // management menu tree
    '<em class="placeholder">Navigation</em> menu tree',
    // navigation menu tree
    'Manage Apps for Panopoly',
    // manage apps for panopoly block
    'Shortcuts',
    // shortcuts block
    'User login',
    // user login widget
    'Powered by Drupal',
    // powere by drupal widget
    'Search form',
    // search form widget
    'Syndicate',
    // syndicate widget
    'Recent content',
  );

  // Define this as an advanced plugin if it is in the advance category or pane list or has tokens
  return in_array($category_label, $fixed_advanced_plugins) || in_array($pane_label, $fixed_advanced_panes) || strpos($category_label, '(tokens)');
}

/**
 * Helper function to enable or disable layouts
 */
function panopoly_admin_switch_layout_action($status, $layout_name, $token) {
  $commands = array();
  $panels_page_allowed_layouts = unserialize(variable_get('panels_page_allowed_layouts', serialize('')));
  if ($token == drupal_get_token($layout_name) && $status == 'enable') {
    $panels_page_allowed_layouts->allowed_layout_settings[$layout_name] = TRUE;
    $commands[] = ajax_command_replace('#panopoly-admin-layout-response-' . $layout_name, _panopoly_admin_general_layout_get_status($layout_name, $status));
  }
  elseif ($token == drupal_get_token($layout_name) && $status == 'disable') {
    $panels_page_allowed_layouts->allowed_layout_settings[$layout_name] = FALSE;
    $commands[] = ajax_command_replace('#panopoly-admin-layout-response-' . $layout_name, _panopoly_admin_general_layout_get_status($layout_name, $status));
  }
  else {
    $commands[] = ajax_command_replace('#panopoly-admin-layout-response-' . $layout_name, 'Trouble!');
  }
  variable_set('panels_page_allowed_layouts', serialize($panels_page_allowed_layouts));
  print ajax_render($commands);
  drupal_exit();
}

/**
 * Helper function to enable or disable general panel panes
 */
function panopoly_admin_switch_pane_action($status, $category_name, $plugin_name, $token) {
  $commands = array();
  $panels_page_allowed_types = variable_get('panels_page_allowed_types', array());
  if ($token == drupal_get_token($plugin_name) && $status == 'enable') {
    $panels_page_allowed_types[$category_name . '-' . $plugin_name] = $category_name . '-' . $plugin_name;
    $commands[] = ajax_command_replace('#panopoly-admin-pane-response-' . $category_name . '-' . str_replace(':', '_', $plugin_name), _panopoly_admin_general_panes_get_status($plugin_name, $category_name, $status));
  }
  elseif ($token == drupal_get_token($plugin_name) && $status == 'disable') {
    $panels_page_allowed_types[$category_name . '-' . $plugin_name] = 0;
    $commands[] = ajax_command_replace('#panopoly-admin-pane-response-' . $category_name . '-' . str_replace(':', '_', $plugin_name), _panopoly_admin_general_panes_get_status($plugin_name, $category_name, $status));
  }
  else {
    $commands[] = ajax_command_replace('#panopoly-admin-pane-response-' . $category_name . '-' . str_replace(':', '_', $plugin_name), 'Trouble!');
  }
  variable_set('panels_page_allowed_types', $panels_page_allowed_types);
  print ajax_render($commands);
  drupal_exit();
}

/**
 * Helper function to get the layout status
 */
function _panopoly_admin_general_layout_get_status($layout_name, $status) {
  if ($status == 'enable') {
    $link = array(
      '#type' => 'link',
      '#title' => t('Disable?'),
      '#href' => 'admin/panopoly/panes/layout/disable/' . $layout_name . '/' . drupal_get_token($layout_name),
      '#ajax' => array(
        'wrapper' => 'panopoly-admin-layout-response-' . $layout_name,
        'method' => 'replace',
        'effect' => 'fade',
      ),
    );
    if (panopoly_admin_panels_layout_access()) {
      return '<div id="panopoly-admin-layout-response-' . $layout_name . '">' . t('Enabled') . ' (' . drupal_render($link) . ')</div>';
    }
    else {
      return '<div id="panopoly-admin-layout-response-' . $layout_name . '">' . t('Enabled') . '</div>';
    }
  }
  else {
    $link = array(
      '#type' => 'link',
      '#title' => t('Enable?'),
      '#href' => 'admin/panopoly/panes/layout/enable/' . $layout_name . '/' . drupal_get_token($layout_name),
      '#ajax' => array(
        'wrapper' => 'panopoly-admin-layout-response-' . $layout_name,
        'method' => 'replace',
        'effect' => 'fade',
      ),
    );
    if (panopoly_admin_panels_layout_access()) {
      return '<div id="panopoly-admin-layout-response-' . $layout_name . '">' . t('Disabled') . ' (' . drupal_render($link) . ')</div>';
    }
    else {
      return '<div id="panopoly-admin-layout-response-' . $layout_name . '">' . t('Disabled') . '</div>';
    }
  }
}

/**
 * Helper function to get the plugin status
 */
function _panopoly_admin_general_panes_get_status($plugin_name, $category_name, $status) {
  if ($status == 'enable') {
    $link = array(
      '#type' => 'link',
      '#title' => t('Disable'),
      '#href' => 'admin/panopoly/panes/pane/disable/' . $category_name . '/' . $plugin_name . '/' . drupal_get_token($plugin_name),
      '#ajax' => array(
        'wrapper' => 'panopoly-admin-pane-response-' . $category_name . '-' . str_replace(':', '_', $plugin_name),
        'method' => 'replace',
        'effect' => 'fade',
      ),
    );
    return '<div id="panopoly-admin-pane-response-' . $category_name . '-' . str_replace(':', '_', $plugin_name) . '">Enabled (' . drupal_render($link) . ')</div>';
  }
  else {
    $link = array(
      '#type' => 'link',
      '#title' => t('Enable'),
      '#href' => 'admin/panopoly/panes/pane/enable/' . $category_name . '/' . $plugin_name . '/' . drupal_get_token($plugin_name),
      '#ajax' => array(
        'wrapper' => 'panopoly-admin-pane-response-' . $category_name . '-' . str_replace(':', '_', $plugin_name),
        'method' => 'replace',
        'effect' => 'fade',
      ),
    );
    return '<div id="panopoly-admin-pane-response-' . $category_name . '-' . str_replace(':', '_', $plugin_name) . '">Disabled (' . drupal_render($link) . ')</div>';
  }
}

/**
 * Helper function to get the plugin type status
 */
function _panopoly_admin_plugin_type_get_status($plugin_type, $status) {
  if ($status == 'enable') {
    $link = array(
      '#type' => 'link',
      '#title' => t('Disable?'),
      '#href' => 'admin/panopoly/panes/type/disable/' . $plugin_type . '/' . drupal_get_token($plugin_type),
      '#ajax' => array(
        'wrapper' => 'panopoly-admin-type-response-' . $plugin_type,
        'method' => 'replace',
        'effect' => 'fade',
      ),
    );
    return '<div id="panopoly-admin-type-response-' . $plugin_type . '">Enabled (' . drupal_render($link) . ')</div>';
  }
  else {
    $link = array(
      '#type' => 'link',
      '#title' => t('Enable?'),
      '#href' => 'admin/panopoly/panes/type/enable/' . $plugin_type . '/' . drupal_get_token($plugin_type),
      '#ajax' => array(
        'wrapper' => 'panopoly-admin-type-response-' . $plugin_type,
        'method' => 'replace',
        'effect' => 'fade',
      ),
    );
    return '<div id="panopoly-admin-type-response-' . $plugin_type . '">Disabled (' . drupal_render($link) . ')</div>';
  }
}

Functions

Namesort descending Description
panopoly_admin_apps_app_info Implementation of hook_apps_app_info()
panopoly_admin_configure_form Configuration Form for Panopoly Admin
panopoly_admin_ctools_content_subtype_alter Implementation of hook_ctools_content_subtype_alter()
panopoly_admin_ctools_plugin_directory Implementation of hook_ctools_plugin_directory()
panopoly_admin_disable_demo_content_form Callback form to disable demo content for an app
panopoly_admin_disable_demo_content_form_submit Submit handler for disabling demo content
panopoly_admin_entity_parse_info Utility function for parsing basic entity info.
panopoly_admin_form_alter Implementation of hook_form_alter()
panopoly_admin_is_advanced_plugin Helper function to identify advanced plugins
panopoly_admin_menu Implementation of hook_menu
panopoly_admin_menu_alter Implementation of hook_menu_alter()
panopoly_admin_menu_link_alter Implementation of hook_link_alter()
panopoly_admin_menu_validate Validate function for adding menu validation
panopoly_admin_module_implements_alter Implementation of hook_module_implements_alter()
panopoly_admin_panelizer_delete_form Confirmation form for deleting a panelizer revision.
panopoly_admin_panelizer_delete_form_submit Submit function for deleting a panelizer revision.
panopoly_admin_panelizer_revert_access Access handler for Panelizer revert functionality
panopoly_admin_panels_layout_access Access handler for changing Panels layouts
panopoly_admin_panels_pane_content_alter Implements hook_panels_pane_content_alter().
panopoly_admin_pathauto_submit Submit function for adding pathauto settings
panopoly_admin_prepreprocess_panels_add_content_modal Preprocess the panels_add_content_modal() theme function.
panopoly_admin_switch_layout_action Helper function to enable or disable layouts
panopoly_admin_switch_pane_action Helper function to enable or disable general panel panes
panopoly_admin_theme_registry_alter Implements hook_theme_registry_alter().
_panopoly_admin_general_layout_get_status Helper function to get the layout status
_panopoly_admin_general_panes_get_status Helper function to get the plugin status
_panopoly_admin_plugin_type_get_status Helper function to get the plugin type status