Commit 3e6ecf4a authored by profix898's avatar profix898
Browse files

- task: some updates to the block settings

parent 16bb732a
...@@ -73,6 +73,21 @@ function _gallery_block_map($refresh = FALSE) { ...@@ -73,6 +73,21 @@ function _gallery_block_map($refresh = FALSE) {
return $block_map; return $block_map;
} }
/**
* Function _gallery_block_options().
*/
function _gallery_block_options(&$type_map, &$param_map) {
$g2_blocks = gallery_get_blocks();
$type_map = $g2_blocks['imageblock']['ImageBlock']['vars']['blocks']['choices'];
$param_map = array(
'heading' => t('Heading'),
'title' => t('Title'),
'date' => t('Date'),
'views' => t('View Count'),
'owner' => t('Item owner')
);
}
/** /**
* Function _gallery_block_block(). * Function _gallery_block_block().
*/ */
......
...@@ -66,18 +66,28 @@ function _gallery_block_admin_block($delta) { ...@@ -66,18 +66,28 @@ function _gallery_block_admin_block($delta) {
'#title' => t('Block type'), '#title' => t('Block type'),
'#default_value' => $block_type, '#default_value' => $block_type,
'#options' => $block_list, '#options' => $block_list,
'#description' => t('Select the Gallery2 block to be used in this Drupal block. In previous versions only '#description' => t('Select the Gallery2 block to be displayed in this Drupal block. In previous versions only
\'ImageBlock\' was available, but now you can embed any Gallery2 block in Drupal.'), \'ImageBlock\' was available, but now you can embed any Gallery2 block in Drupal.'),
); );
// Block specific settings // Block specific settings
$form[$block_type] = array( if ($param_form = _gallery_block_admin_block_params($delta, $plugin, $plugin_block)) {
'#type' => 'fieldset', $form[$block_type] = array(
'#title' => t('%block settings', array('%block' => $plugin_block)), '#type' => 'fieldset',
'#collapsible' => FALSE, '#title' => t('%block settings', array('%block' => $plugin_block)),
'#collapsed' => FALSE, '#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form[$block_type][] = $param_form;
}
// Save/Edit button
$form['element'] = array('#type' => 'value', '#value' => 'gallery_block_'. $delta .'_');
$form['update_btn'] = array(
'#type' => 'submit',
'#value' => t('Save and Edit'),
'#submit' => array('_gallery_block_admin_update')
); );
$form[$block_type][] = _gallery_block_admin_block_params($delta, $plugin, $plugin_block);
return $form; return $form;
} }
...@@ -93,7 +103,7 @@ function _gallery_block_admin_description($element) { ...@@ -93,7 +103,7 @@ function _gallery_block_admin_description($element) {
\'Cache per user\' (default). If you dont have per-user permissions configured in your gallery you \'Cache per user\' (default). If you dont have per-user permissions configured in your gallery you
can improve performance by setting to \'Cache per role\'.'); can improve performance by setting to \'Cache per role\'.');
default: default:
return ''; return '- description -';
} }
} }
...@@ -102,11 +112,14 @@ function _gallery_block_admin_description($element) { ...@@ -102,11 +112,14 @@ function _gallery_block_admin_description($element) {
*/ */
function _gallery_block_admin_block_params($delta, $plugin, $plugin_block) { function _gallery_block_admin_block_params($delta, $plugin, $plugin_block) {
$g2_blocks = gallery_get_blocks(); $g2_blocks = gallery_get_blocks();
// Image block specific settings
if ($plugin_block == 'ImageBlock') { if ($plugin_block == 'ImageBlock') {
// Image block specific settings return _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blocks);
_gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blocks, $form);
} }
else {
// Block specific settings
if (isset($g2_blocks[$plugin][$plugin_block]['vars'])) {
// Generate a Drupal form element for each G2 block variable // Generate a Drupal form element for each G2 block variable
foreach ($g2_blocks[$plugin][$plugin_block]['vars'] as $parameter => $options) { foreach ($g2_blocks[$plugin][$plugin_block]['vars'] as $parameter => $options) {
$block = strtolower($plugin_block .'_'. $parameter); $block = strtolower($plugin_block .'_'. $parameter);
...@@ -134,15 +147,16 @@ function _gallery_block_admin_block_params($delta, $plugin, $plugin_block) { ...@@ -134,15 +147,16 @@ function _gallery_block_admin_block_params($delta, $plugin, $plugin_block) {
default: default:
} }
} }
return $form;
} }
return $form; return FALSE;
} }
/** /**
* Function _gallery_block_admin_imageblock(). * Function _gallery_block_admin_imageblock().
*/ */
function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blocks, &$form) { function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blocks) {
$plugin_status = gallery_plugin_status(array('imageblock', 'imageframe')); $plugin_status = gallery_plugin_status(array('imageblock', 'imageframe'));
$form['imageblock']['#description'] = t('The Gallery Image/Grid Block requires the Gallery2 Image Block plugin $form['imageblock']['#description'] = t('The Gallery Image/Grid Block requires the Gallery2 Image Block plugin
(!imageblock_status) and optionally the Gallery2 Image Frame plugin (!imageblock_status) and optionally the Gallery2 Image Frame plugin
...@@ -172,6 +186,7 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo ...@@ -172,6 +186,7 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo
'#description' => t('Select the number of rows in the grid.'), '#description' => t('Select the number of rows in the grid.'),
); );
_gallery_block_options($type_map, $param_map);
$form[$element .'_block_block'] = array( $form[$element .'_block_block'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Image types'), '#title' => t('Image types'),
...@@ -186,7 +201,7 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo ...@@ -186,7 +201,7 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo
'#type' => 'select', '#type' => 'select',
'#title' => '', '#title' => '',
'#default_value' => isset($gallery_block_block[$i]) ? $gallery_block_block[$i] : NULL, '#default_value' => isset($gallery_block_block[$i]) ? $gallery_block_block[$i] : NULL,
'#options' => array_merge(array(NULL => t('None')), $g2_blocks[$plugin][$plugin_block]['vars']['blocks']['choices']), '#options' => array_merge(array(NULL => t('None')), $type_map),
); );
} }
...@@ -205,13 +220,7 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo ...@@ -205,13 +220,7 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#title' => t('Image data'), '#title' => t('Image data'),
'#default_value' => variable_get($element .'_block_show', array('title', 'heading')), '#default_value' => variable_get($element .'_block_show', array('title', 'heading')),
'#options' => array( '#options' => $param_map,
'title' => t('Title'),
'date' => t('Date'),
'views' => t('View Count'),
'owner' => t('Item owner'),
'heading' => t('Heading')
),
'#description' => t('Choose the item metadata you would like to display.'), '#description' => t('Choose the item metadata you would like to display.'),
); );
...@@ -280,12 +289,6 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo ...@@ -280,12 +289,6 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo
to link somewhere else instead.'), to link somewhere else instead.'),
); );
$form['element'] = array('#type' => 'value', '#value' => $element);
$form['update_btn'] = array(
'#type' => 'submit',
'#value' => t('Save and Edit'),
'#submit' => array('_gallery_block_admin_update')
);
return $form; return $form;
} }
...@@ -302,17 +305,19 @@ function _gallery_block_admin_update($form, &$form_state) { ...@@ -302,17 +305,19 @@ function _gallery_block_admin_update($form, &$form_state) {
function _gallery_block_admin_save($delta, $values) { function _gallery_block_admin_save($delta, $values) {
$element = $values['element']; $element = $values['element'];
unset($values['element']); unset($values['element']);
// Validate variable values
if (isset($values[$element .'_size'])) {
if (!is_numeric($values[$element .'_size']) || $values[$element .'_size'] < 10) {
$values[$element .'_size'] = 10;
drupal_set_message(t('Image size must be a number greater than ten pixels.
(The value has been updated to \'10\' for your convenience.)'), 'error');
}
}
// Save variables // Save variables
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
if (strpos($key, $element) == 0) { $pos = strpos($key, $element);
if ($pos !== FALSE && $pos == 0) {
// Validate _size variable
if ($key == $element .'imageblock_size') {
if (!is_numeric($value) || $value < 10) {
$value = 10;
drupal_set_message(t('Image size must be a number greater than ten pixels.
(The value has been updated to \'10\' for your convenience.)'), 'error');
}
}
//
if (is_array($value)) { if (is_array($value)) {
$value = array_values(array_filter($value)); $value = array_values(array_filter($value));
} }
......
...@@ -292,6 +292,7 @@ function _gallery_settings_filter() { ...@@ -292,6 +292,7 @@ function _gallery_settings_filter() {
$image_frames = gallery_get_image_frames(); $image_frames = gallery_get_image_frames();
_gallery_block_options($type_map, $param_map); _gallery_block_options($type_map, $param_map);
$type_map['specificItem'] = t('Specific item');
if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) { if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {
$form['filter']['gallery_filter_prefix'] = array( $form['filter']['gallery_filter_prefix'] = array(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment