In Drupal 7.23, human-readable labels have been added to image styles provided by the Image module, in addition to the existing machine name. Site builders will be able to define a human-readable label when creating or editing image styles, and these labels will be used in many places throughout the administrative interface.
As a result of this API change, there are a few changes module developers may want to make to image style code, but none of them are likely to be critical:
When displaying a list of image styles using the image_style_options() API function, the labels will automatically be displayed. However, they will be automatically sanitized via check_plain(), so if you are displaying the options in a select list (which has built-in check_plain() sanitization of its own) you may change your code to request that sanitization be skipped to avoid double-encoding.
Example select list (before):
$form['image_style'] = array( '#title' => t('Choose an image style'), '#type' => 'select', '#options' => image_style_options(FALSE), ... );
Example select list (after):
$form['image_style'] = array( '#title' => t('Choose an image style'), '#type' => 'select', // The PASS_THROUGH parameter is new, and is added here to prevent // image_style_options() from double-encoding the human-readable image style // name, since the form API will already sanitize options in a select list using // check_plain(). '#options' => image_style_options(FALSE, PASS_THROUGH), ... );
Example radios (before and after) - no code changes needed:
$form['image_style'] = array( '#title' => t('Choose an image style'), '#type' => 'radios', // The PASS_THROUGH parameter is not added in this case, since the form API // does not run radio button labels through check_plain(), and we therefore // want to allow image_style_options() to do so. '#options' => image_style_options(FALSE), ... );
Note that as a result of the changes to image_style_options(), any code which previously relied on the array values returned by this function being (coincidentally) equal to the image style machine names will need to be changed to check the array keys instead; the array keys returned by image_style_options() are the machine names, and the array values are the labels intended for display.
When printing the name of an image style in the user interface in other contexts, you may replace $style['name'] with $style['label'] to take advantage of the new human-readable name. As with any arbitrary user input, make sure to sanitize this when it is displayed (for example, using check_plain() or t()-placeholders).
$style = image_style_load('some_style'); drupal_set_message(t('The style %name was loaded.', array('%name' => $style['name'])));
$style = image_style_load('some_style'); drupal_set_message(t('The style %name was loaded.', array('%name' => $style['label'])));
- When saving an image style using image_style_save(), a 'label' key can be passed as part of the style array to set the human-readable label. (If not passed, the machine-readable name will be used as the human-readable name, as was the case before Drupal 7.23.)
The data structure of the forms defined by image_style_form() and image_style_add_form() has changed to accommodate the new human-readable label.
If you are heavily altering these forms in your code, you may want to examine the new structure.