function imagecache_ui_preset_form in ImageCache 5.2
Same name and namespace in other branches
- 6.2 imagecache_ui.pages.inc \imagecache_ui_preset_form()
1 string reference to 'imagecache_ui_preset_form'
File
- ./
imagecache_ui.module, line 223
Code
function imagecache_ui_preset_form($presetid) {
$preset = imagecache_preset($presetid, true);
if (!$preset) {
drupal_set_message(t('The specified preset was not found'), 'error');
drupal_goto('admin/build/imagecache');
}
$form = array();
$form['presetname'] = array(
'#type' => 'textfield',
'#size' => '64',
'#title' => t('Preset Namespace'),
'#default_value' => $preset['presetname'],
'#description' => t('The namespace is used in URLs for images to tell imagecache how to process an image. Please only use alphanumeric characters, underscores (_), and hyphens (-) for preset names.'),
'#validate' => array(
'imagecache_element_presetname_validate' => array(),
),
);
$form['presetid'] = array(
'#type' => 'value',
'#value' => $preset['presetid'],
);
$form['actions'] = array(
'#type' => 'fieldset',
'#title' => t('Actions'),
'#tree' => true,
'#theme' => 'imagecache_ui_preset_actions',
);
foreach ($preset['actions'] as $i => $action) {
// skip unknown actions...
if (!($definition = imagecache_action_definition($action['action']))) {
continue;
}
$action_name = t($definition['name']);
$action_form['name'] = array(
'#value' => $action_name,
);
$action_form['action'] = array(
'#type' => 'value',
'#value' => $action['action'],
);
$action_form['actionid'] = array(
'#type' => 'value',
'#value' => $action['actionid'],
);
$action_form['presetid'] = array(
'#type' => 'value',
'#value' => $action['presetid'],
);
$action_form['settings'] = array(
'#theme' => $action['action'],
'#value' => $action['data'],
);
$action_form['data'] = array(
'#type' => 'value',
'#value' => $action['data'],
);
$action_form['weight'] = array(
'#type' => 'weight',
'#default_value' => $action['weight'],
);
$action_form['configure'] = array(
'#value' => l(t('Configure'), 'admin/build/imagecache/preset/' . $action['presetid'] . '/action/' . $action['actionid']),
);
$action_form['remove'] = array(
'#value' => l(t('Delete'), 'admin/build/imagecache/preset/' . $action['presetid'] . '/action/' . $action['actionid'] . '/delete'),
);
$form['actions'][$i] = $action_form;
}
$form['actions']['new'] = array(
'#tree' => false,
'#type' => 'fieldset',
'#title' => t('New Actions'),
'#collapsible' => true,
'#collapsed' => true,
);
foreach (imagecache_action_definitions() as $action => $definition) {
$form['actions']['new'][] = array(
'#type' => 'markup',
'#prefix' => '<div>',
'#suffix' => '</div>',
'#value' => l(t('Add !action', array(
'!action' => $definition['name'],
)), 'admin/build/imagecache/preset/' . $preset['presetid'] . '/action/add/' . $action) . ' - ' . $definition['description'],
);
}
/**
@todo: 404/403 image per preset.
@todo: global 404/403 image.
$form['files'] = array(
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => true,
'#title' => t('Error Files'),
);
$form['files']['403']['file'] = array(
'#type' => 'file',
'#title' => t('403 Image'),
'#description' => t('Image that will be used when access is denied to the source image.'),
);
$path403 = imagecache/'. $preset['presetname'] .'/403.png';
if (file_exists($path403)) {
$url403 = imagecache_create_url($preset['presetname'], $path403);
$form['files']['403']['view'] = array(
'#value' => '<img src="'. $url403 .'">',
);
}
$form['files']['404'] = array(
'#type' => 'file',
'#title' => t('404 Image'),
'#description' => t('Image that will be used when the source image cannot be found.'),
);
*/
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Update Preset'),
);
// Display a preview image for this action. Put it below the submit button so
// users don't have to do a bunch of scrolling.
$preview_path = file_create_path('imagecache_sample.png');
if (!file_exists($preview_path)) {
// Copy of the image into the files directory so rather than generating it
// from the original so we don't end up creating subdirectories mirroring
// the path to the this module.
$preview_path = drupal_get_path('module', 'imagecache_ui') . '/sample.png';
file_copy($preview_path, 'imagecache_sample.png');
}
imagecache_image_flush($preview_path);
$imagecache_path = imagecache_create_url($preset['presetname'], $preview_path, TRUE);
$form['preview'] = array(
'#type' => 'item',
'#title' => t('Preview'),
'#value' => l($imagecache_path, $imagecache_path) . '<br />' . l("<img src='{$imagecache_path}' />", $imagecache_path, array(), NULL, NULL, FALSE, TRUE),
);
return $form;
}