View source
<?php
include_once 'panopoly_admin.features.inc';
function panopoly_admin_apps_app_info() {
return array(
'configure form' => 'panopoly_admin_configure_form',
);
}
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);
}
function panopoly_admin_ctools_plugin_directory($module, $plugin) {
return 'plugins/' . $plugin;
}
function panopoly_admin_panels_pane_content_alter($content, $pane, $args, $context) {
$pane->title = isset($content->title) ? $content->title : NULL;
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 = '';
}
}
}
}
function panopoly_admin_theme_registry_alter(&$registry) {
if (isset($registry['panels_add_content_modal'])) {
$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');
}
}
}
function panopoly_admin_prepreprocess_panels_add_content_modal(&$vars) {
if (!variable_get('panopoly_admin_advanced_plugins', FALSE)) {
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 (empty($vars['categories'][$category_name]['content'])) {
unset($vars['categories'][$category_name]);
}
}
}
}
function panopoly_admin_ctools_content_subtype_alter(&$subtype, &$plugin) {
$category_label = is_string($subtype['category']) ? $subtype['category'] : $subtype['category'][0];
if ($category_label == 'Miscellaneous') {
$subtype['category'] = 'Blocks';
}
}
function panopoly_admin_form_alter(&$form, &$form_state, $form_id) {
global $base_url;
if (isset($form['title']['#title'])) {
$form['title']['#title_display'] = 'invisible';
$form['title']['#attributes']['placeholder'] = $form['title']['#title'];
}
if (isset($form['#entity_type']) && $form['#entity_type'] == 'node') {
if (isset($form['path']) && isset($form['path']['alias'])) {
unset($form['path']['#type']);
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;
$form['path']['alias']['#attributes'] = array(
'placeholder' => '<' . t('magically generated') . '>',
);
$form['path']['alias']['#states'] = array();
$form['#submit'][] = 'panopoly_admin_pathauto_submit';
}
}
if (isset($form['body']['#type']) && $form['body']['#type'] == 'container') {
$form['body']['#attributes']['class'][] = 'clearfix';
}
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') {
$form['body']['#attributes']['class'][] = 'panopoly-admin-hide-body-label';
}
else {
$form['body'][LANGUAGE_NONE][0]['#title_display'] = 'invisible';
}
}
if (isset($form['options']) && !variable_get('panopoly_admin_front_page_and_sticky', 0)) {
$form['options']['promote']['#access'] = FALSE;
$form['options']['sticky']['#access'] = FALSE;
}
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;
if (module_exists('date_popup_authored')) {
$form['author']['date']['#title_display'] = 'invisible';
$form['author']['date']['#size'] = 20;
}
}
}
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']);
}
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'],
);
}
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';
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;
}
}
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']);
}
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';
}
}
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;
}
}
function panopoly_admin_pathauto_submit($form, &$form_state) {
$values = $form_state['values'];
$autogenerate = TRUE;
if (!empty($values['path']['alias'])) {
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;
}
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.'));
}
}
function panopoly_admin_menu() {
$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,
),
);
$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',
);
$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',
),
);
$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',
),
);
$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'),
);
$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'),
);
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;
}
function panopoly_admin_panelizer_revert_access($entity_type, $entity_id) {
if (user_access('administer panelizer')) {
return TRUE;
}
$entities = entity_load($entity_type, array(
$entity_id,
));
if (entity_access('update', $entity_type, $entities[$entity_id])) {
return TRUE;
}
return FALSE;
}
function panopoly_admin_panels_layout_access() {
return user_access('administer page manager');
}
function panopoly_admin_menu_alter(&$items) {
$items['admin/panopoly/pages']['description'] = 'This is the page library for the site. See your landing pages, page templates, and overriden page templates.';
$items['admin/panopoly/layouts']['description'] = 'This is the layout library for the site. See your preset and custom layouts.';
$items['admin/panopoly/panes']['description'] = 'This is the pane library for the site. See all of the panes you can add to your pages.';
$items['admin/structure/pages']['access arguments'] = array(
'administer page manager',
);
$items['admin/config']['access arguments'] = array(
'administer site configuration',
);
}
function panopoly_admin_menu_link_alter(&$item) {
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;
}
}
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;
}
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']);
}
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;
}
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');
}
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'],
)));
}
function panopoly_admin_is_advanced_plugin($pane_label, $category_label) {
$fixed_advanced_plugins = array(
'View context',
'Page elements',
'Facet API',
'File',
'Fieldable_panels_pane',
'Existing pages',
'Panopoly Test Advanced',
);
$fixed_advanced_panes = array(
'Panels pane',
'Execute PHP',
'Devel',
'Switch user',
'Theme switcher',
'User menu',
'Development',
'Management',
'Navigation',
'<em class="placeholder">User menu</em> menu tree',
'<em class="placeholder">Development</em> menu tree',
'<em class="placeholder">Management</em> menu tree',
'<em class="placeholder">Navigation</em> menu tree',
'Manage Apps for Panopoly',
'Shortcuts',
'User login',
'Powered by Drupal',
'Search form',
'Syndicate',
'Recent content',
);
return in_array($category_label, $fixed_advanced_plugins) || in_array($pane_label, $fixed_advanced_panes) || strpos($category_label, '(tokens)');
}
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();
}
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();
}
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>';
}
}
}
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>';
}
}
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>';
}
}