Index: modules/image/image.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/image/image.admin.inc,v retrieving revision 1.17 diff -u -p -r1.17 image.admin.inc --- modules/image/image.admin.inc 3 Jan 2010 21:01:04 -0000 1.17 +++ modules/image/image.admin.inc 27 Mar 2010 22:53:51 -0000 @@ -36,7 +36,7 @@ function image_style_list() { * @see image_style_name_validate() */ function image_style_form($form, &$form_state, $style) { - $title = t('Edit %name style', array('%name' => $style['name'])); + $title = t('Edit style %name', array('%name' => $style['name'])); drupal_set_title($title, PASS_THROUGH); // Adjust this form for styles that must be overridden to edit. @@ -46,6 +46,21 @@ function image_style_form($form, &$form_ drupal_set_message(t('This image style is currently being provided by a module. Click the "Override defaults" button to change its settings.'), 'warning'); } + // Build settings for machine readable name generation. + $js_settings = array( + 'type' => 'setting', + 'data' => array( + 'machineReadableValue' => array( + 'label' => array( + 'text' => t('Machine name'), + 'target' => 'name', + 'searchPattern' => '[^a-z0-9\\-_]+', + 'replaceToken' => '_', + ), + ), + ), + ); + $form_state['image_style'] = $style; $form['#tree'] = TRUE; $form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array('preprocess' => FALSE); @@ -62,7 +77,7 @@ function image_style_form($form, &$form_ if ($style['storage'] & IMAGE_STORAGE_MODULE) { $form['name'] = array( '#type' => 'item', - '#title' => t('Image style name'), + '#title' => t('Image style machine readable name'), '#markup' => $style['name'], '#description' => t('This image style is being provided by %module module and may not be renamed.', array('%module' => $style['module'])), ); @@ -70,12 +85,33 @@ function image_style_form($form, &$form_ else { $form['name'] = array( '#type' => 'textfield', - '#size' => '64', - '#title' => t('Image style name'), + '#title' => t('Image style machine readable name'), '#default_value' => $style['name'], - '#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'), + '#description' => t('The machine readable name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'), '#element_validate' => array('image_style_name_validate'), '#required' => TRUE, + '#attached' => array( + 'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings), + ), + ); + } + // Allow the real name of the style to be changed, but only if this style is + // editable (overridden default style or custom style). + if ($editable) { + $form['label'] = array( + '#type' => 'textfield', + '#title' => t('Image style display name'), + '#default_value' => $style['label'], + '#description' => t('Enter the display name for this preset. This name is used in listings of image styles.'), + '#field_suffix' => '  ', + ); + } + else { + $form['label'] = array( + '#type' => 'item', + '#title' => t('Image style display name'), + '#markup' => $style['label'], + '#description' => t('This image style is being provided by %module module and may not be renamed.', array('%module' => $style['module'])), ); } @@ -201,6 +237,9 @@ function image_style_form_submit($form, if (isset($form_state['values']['name']) && $style['name'] != $form_state['values']['name']) { $style['name'] = $form_state['values']['name']; } + if (isset($form_state['values']['label']) && $style['label'] != $form_state['values']['label']) { + $style['label'] = $form_state['values']['label']; + } // Update image effect weights. if (!empty($form_state['values']['effects'])) { @@ -228,14 +267,38 @@ function image_style_form_submit($form, * @see image_style_name_validate() */ function image_style_add_form($form, &$form_state) { + // Build settings for machine readable name generation. + $js_settings = array( + 'type' => 'setting', + 'data' => array( + 'machineReadableValue' => array( + 'label' => array( + 'text' => t('Machine readable name'), + 'target' => 'name', + 'searchPattern' => '[^a-z0-9\\-_]+', + 'replaceToken' => '_', + ), + ), + ), + ); + $form['name'] = array( '#type' => 'textfield', - '#size' => '64', - '#title' => t('Style name'), + '#title' => t('Image style machine readable name'), '#default_value' => '', '#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'), '#element_validate' => array('image_style_name_validate'), '#required' => TRUE, + '#attached' => array( + 'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings), + ), + ); + $form['label'] = array( + '#type' => 'textfield', + '#title' => t('Image style display name'), + '#default_value' => '', + '#description' => t('Enter the display name for this preset. This name is used in listings of image styles.'), + '#field_suffix' => '  ', ); $form['submit'] = array( @@ -250,7 +313,10 @@ function image_style_add_form($form, &$f * Submit handler for adding a new image style. */ function image_style_add_form_submit($form, &$form_state) { - $style = array('name' => $form_state['values']['name']); + $style = array( + 'name' => $form_state['values']['name'], + 'label' => $form_state['values']['label'], + ); $style = image_style_save($style); drupal_set_message(t('Style %name was created.', array('%name' => $style['name']))); $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name']; @@ -639,7 +705,7 @@ function theme_image_style_list($variabl $rows = array(); foreach ($styles as $style) { $row = array(); - $row[] = l($style['name'], 'admin/config/media/image-styles/edit/' . $style['name']); + $row[] = l($style['label'], 'admin/config/media/image-styles/edit/' . $style['name']); $link_attributes = array( 'attributes' => array( 'class' => array('image-style-link'), Index: modules/image/image.field.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/image/image.field.inc,v retrieving revision 1.19 diff -u -p -r1.19 image.field.inc --- modules/image/image.field.inc 27 Mar 2010 05:52:50 -0000 1.19 +++ modules/image/image.field.inc 27 Mar 2010 22:53:51 -0000 @@ -435,15 +435,15 @@ function image_field_formatter_info() { foreach (image_styles() as $style) { $formatters['image__' . $style['name']] = array( - 'label' => t('Image "@style"', array('@style' => $style['name'])), + 'label' => t('Image "@style"', array('@style' => $style['label'])), 'field types' => array('image'), ); $formatters['image_link_content__' . $style['name']] = array( - 'label' => t('Image "@style" linked to content', array('@style' => $style['name'])), + 'label' => t('Image "@style" linked to content', array('@style' => $style['label'])), 'field types' => array('image'), ); $formatters['image_link_file__' . $style['name']] = array( - 'label' => t('Image "@style" linked to file', array('@style' => $style['name'])), + 'label' => t('Image "@style" linked to file', array('@style' => $style['label'])), 'field types' => array('image'), ); } Index: modules/image/image.install =================================================================== RCS file: /cvs/drupal/drupal/modules/image/image.install,v retrieving revision 1.5 diff -u -p -r1.5 image.install --- modules/image/image.install 26 Mar 2010 12:28:06 -0000 1.5 +++ modules/image/image.install 27 Mar 2010 22:53:52 -0000 @@ -43,11 +43,18 @@ function image_schema() { 'not null' => TRUE, ), 'name' => array( - 'description' => 'The style name.', + 'description' => 'The machine readable name of the style.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), + 'label' => array( + 'description' => 'The style name.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + 'default' => '', + ), ), 'primary key' => array('isid'), 'indexes' => array( Index: modules/image/image.module =================================================================== RCS file: /cvs/drupal/drupal/modules/image/image.module,v retrieving revision 1.35 diff -u -p -r1.35 image.module --- modules/image/image.module 21 Mar 2010 20:36:10 -0000 1.35 +++ modules/image/image.module 27 Mar 2010 22:53:53 -0000 @@ -321,6 +321,8 @@ function image_image_default_styles() { $styles = array(); $styles['thumbnail'] = array( + 'name' => 'thumbnail', + 'label' => 'Thumbnail (100x100)', 'effects' => array( array( 'name' => 'image_scale', @@ -331,6 +333,8 @@ function image_image_default_styles() { ); $styles['medium'] = array( + 'name' => 'medium', + 'label' => 'Medium (220x220)', 'effects' => array( array( 'name' => 'image_scale', @@ -341,6 +345,8 @@ function image_image_default_styles() { ); $styles['large'] = array( + 'name' => 'large', + 'label' => 'Large (640x640)', 'effects' => array( array( 'name' => 'image_scale', @@ -392,6 +398,7 @@ function image_styles() { $module_styles = module_invoke($module, 'image_default_styles'); foreach ($module_styles as $style_name => $style) { $style['name'] = $style_name; + $style['label'] = ($style['label'] == '') ? $style['name'] : $style['label']; $style['module'] = $module; $style['storage'] = IMAGE_STORAGE_DEFAULT; foreach ($style['effects'] as $ieid => $effect) { @@ -407,12 +414,15 @@ function image_styles() { // Select all the user-defined styles. $user_styles = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC)) ->fields('image_styles') + ->orderBy('label') ->orderBy('name') ->execute() ->fetchAllAssoc('name', PDO::FETCH_ASSOC); // Allow the user styles to override the module styles. foreach ($user_styles as $style_name => $style) { + $style['name'] = $style_name; + $style['label'] = ($style['label'] == '') ? $style['name'] : $style['label']; $style['module'] = NULL; $style['storage'] = IMAGE_STORAGE_NORMAL; $style['effects'] = image_style_effects($style); @@ -469,6 +479,9 @@ function image_style_load($name = NULL, // Restrict to the specific type of flag. This bitwise operation basically // states "if the storage is X, then allow". if (isset($style) && (!isset($include) || ($style['storage'] & (int) $include))) { + if (empty($style['label'])) { + $style['label'] = $style['name']; + } return $style; } @@ -569,7 +582,9 @@ function image_style_options($include_em if ($include_empty && !empty($styles)) { $options[''] = t(''); } - $options = array_merge($options, drupal_map_assoc(array_keys($styles))); + foreach ($styles as $name => $style) { + $options[$name] = $style['label']; + } if (empty($options)) { $options[''] = t('No defined styles'); }