View source
<?php
function dynamic_background_panels_permission() {
return array(
'configure panels dynamic background' => array(
'title' => t('Configure panels dynamic background'),
),
);
}
function dynamic_background_panels_menu() {
$items = array();
$items['admin/config/user-interface/backgrounds/panels'] = array(
'title' => 'Panels',
'description' => 'Configure dynamic background penels',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'dynamic_background_panels_admin_form',
),
'access arguments' => array(
'configure panels dynamic background',
),
'type' => MENU_LOCAL_TASK,
'weight' => -10,
);
return $items;
}
function dynamic_background_panels_admin_form() {
$form = array(
'#tree' => TRUE,
);
$form += dynamic_background_image_style_form('dynamic_background_panels_image_style');
$form += dynamic_background_css_behaviour_form('dynamic_background_panels_css');
return system_settings_form($form);
}
function dynamic_background_panels_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'panels_panel_context_edit_settings') {
$form['conf']['dynamic_background'] = array(
'#type' => 'fieldset',
'#title' => t('Dynamic background'),
'#description' => t('To used this feature, you have to setup custom CSS at dynamic background administratio page.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
$image_id = NULL;
if (isset($form_state['handler']->conf['dynamic_background'])) {
foreach ($form_state['handler']->conf['dynamic_background'] as $id => $value) {
if (isset($value['selected']) && $value['selected']) {
$image_id = $id;
break;
}
}
}
$form['conf']['dynamic_background'] += dynamic_background_image_selector_form($image_id);
$form['#submit'][] = 'dynamic_background_panels_conf_submit_handler';
}
}
function dynamic_background_panels_conf_submit_handler(&$form, &$form_state) {
if (isset($form_state['values']['dynamic_background'])) {
$form_state['handler']->conf['dynamic_background'] = $form_state['values']['dynamic_background'];
}
}
function dynamic_background_panels_dynamic_background_css($vars) {
$image_id = NULL;
if ($pm_page = page_manager_get_current_page()) {
if (isset($pm_page['handler']->conf['dynamic_background'])) {
foreach ($pm_page['handler']->conf['dynamic_background'] as $id => $value) {
if ($value['selected']) {
$image_id = $id;
break;
}
}
}
}
if (!is_null($image_id)) {
$backgrounds = variable_get('dynamic_background_images', array());
if (isset($backgrounds[$image_id]['picture'])) {
$image_style = variable_get('dynamic_background_panels_image_style', FALSE);
return array(
'image' => $backgrounds[$image_id]['picture'],
'configuration' => variable_get('dynamic_background_panels_css', array()),
'image_style' => $image_style ? $image_style['style'] : FALSE,
);
}
}
}
function dynamic_background_panels_dynamic_background_weight() {
return array(
'weight' => -45,
);
}