'textfield', '#size' => '64', '#title' => t('Preset Namespace'), '#default_value' => '', '#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.'), '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Create New Preset'), ); return $form; } function imagecache_ui_preset_add_form_validate($form, &$form_state) { $values = $form_state['values']; // Check for duplicates foreach (imagecache_presets() as $preset) { if ($values['presetname'] == $preset['presetname']) { form_set_error('presetname', t('The namespace you have chosen is already in use.')); break; } } // Check for illegal characters in preset names if (preg_match('/[^0-9a-zA-Z_\-]/', $values['presetname'])) { form_set_error('presetname', t('Please only use alphanumeric characters, underscores (_), and hyphens (-) for preset names.')); } } function imagecache_ui_preset_add_form_submit($form, &$form_state) { $preset = array('presetname' => $form_state['values']['presetname']); $preset = imagecache_preset_save($preset); drupal_set_message(t('Preset %name (ID: @id) was created.', array('%name' => $preset['presetname'], '@id' => $preset['presetid']))); $form_state['redirect'] = 'admin/build/imagecache/'. $preset['presetid']; } function imagecache_ui_preset_delete_form($form_state, $preset = array()) { if (empty($preset)) { drupal_set_message(t('The specified preset was not found'), 'error'); drupal_goto('admin/build/imagecache'); } $form = array(); $form['presetid'] = array('#type' => 'value', '#value' => $preset['presetid']); return confirm_form( $form, t('Are you sure you want to delete the preset %preset?', array('%preset' => $preset['presetname']) ), 'admin/build/imagecache', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } function imagecache_ui_preset_delete_form_submit($form, &$form_state) { $preset = imagecache_preset($form_state['values']['presetid']); imagecache_preset_delete($preset); drupal_set_message(t('Preset %name (ID: @id) was deleted.', array('%name' => $preset['presetname'], '@id' => $preset['presetid']))); $form_state['redirect'] = 'admin/build/imagecache'; } function imagecache_ui_preset_flush_form(&$form_state, $preset = array()) { if (empty($preset)) { drupal_set_message(t('The specified preset was not found'), 'error'); $form_state['redirect'] = 'admin/build/imagecache'; } $form = array(); $form['presetid'] = array('#type' => 'value', '#value' => $preset['presetid']); return confirm_form( $form, t('Are you sure you want to flush the preset %preset?', array('%preset' => $preset['presetname']) ), 'admin/build/imagecache', t('This action cannot be undone.'), t('Flush'), t('Cancel') ); } function imagecache_ui_preset_flush_form_submit($form, &$form_state) { $preset = imagecache_preset($form_state['values']['presetid']); imagecache_preset_flush($preset); drupal_set_message(t('Preset %name (ID: @id) was flushed.', array('%name' => $preset['presetname'], '@id' => $preset['presetid']))); $form_state['redirect'] = 'admin/build/imagecache'; } /** * Imagecache preset export form. */ function imagecache_ui_preset_export_form(&$form_state, $preset = array()) { if (empty($preset)) { drupal_set_message(t('The specified preset was not found'), 'error'); $form_state['redirect'] = 'admin/build/imagecache'; } if (isset($preset['presetid'])) { unset($preset['presetid']); } if (isset($preset['storage'])) { unset($preset['storage']); } foreach ($preset['actions'] as $id => $action) { unset($preset['actions'][$id]['actionid']); unset($preset['actions'][$id]['presetid']); } $exported = '$presets = array();'; $exported .= "\n"; $exported .= '$presets[\''. $preset['presetname'] .'\'] = '; $exported .= var_export($preset, TRUE) .';'; $rows = substr_count($exported, "\n") + 1; $form = array(); $form['export'] = array( '#type' => 'textarea', '#default_value' => $exported, '#rows' => $rows, '#resizable' => FALSE, ); return $form; } function imagecache_ui_preset_form($form_state, $preset = array()) { if (empty($preset)) { drupal_set_message(t('The specified preset was not found.'), 'error'); drupal_goto('admin/build/imagecache'); } $form = array(); // @TODO: for some reason, simply setting '#disabled' on the normal presetname // textfield fails to pass the values successfully to the submit handler. if ($preset['storage'] === IMAGECACHE_STORAGE_DEFAULT) { $form['presetname'] = array( '#type' => 'value', '#value' => $preset['presetname'], ); $form['presetname_display'] = array( '#type' => 'textfield', '#size' => '64', '#title' => t('Preset Namespace'), '#default_value' => $preset['presetname'], '#disabled' => TRUE, ); } else { $form['presetname'] = array( '#type' => 'textfield', '#size' => '64', '#title' => t('Preset Namespace'), '#default_value' => $preset['presetname'], '#description' => t('The namespace is used in URL\'s 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'], '#access' => $preset['storage'] !== IMAGECACHE_STORAGE_DEFAULT, ); $action_form['configure'] = array( '#value' => l(t('Configure'), 'admin/build/imagecache/'. $action['presetid'] .'/'. $action['actionid'] ), '#access' => $preset['storage'] !== IMAGECACHE_STORAGE_DEFAULT, ); $action_form['remove'] = array( '#value' => l(t('Delete'), 'admin/build/imagecache/'. $action['presetid'] .'/'. $action['actionid'] .'/delete'), '#access' => $preset['storage'] !== IMAGECACHE_STORAGE_DEFAULT, ); $form['actions'][$i] = $action_form; } $form['actions']['new'] = array( '#tree' => FALSE, '#type' => 'fieldset', '#title' => t('New Actions'), '#collapsible' => TRUE, '#collapsed' => count($preset['actions']) > 0, '#access' => $preset['storage'] !== IMAGECACHE_STORAGE_DEFAULT, ); foreach (imagecache_action_definitions() as $action => $definition) { $form['actions']['new'][] = array( '#type' => 'markup', '#prefix' => '