Change record status: 
Project: 
Introduced in branch: 
7.x
Introduced in version: 
7.23
Description: 

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:

  1. When displaying a list of image styles using the image_style_options() API function, the labels will automatically be displayed. However, they will be sanitized for security reasons, so if you are displaying the options in a select list (which has built-in sanitization) you may change your code to request that sanitization be skipped and to avoid double-encoding.

    Example select list (before):

    <?php
      $form
    ['image_style'] = array(
       
    '#title' => t('Choose an image style'),
       
    '#type' => 'select',
       
    '#options' => image_style_options(FALSE),
        ...
      );
    ?>

    Example select list (after):

    <?php
      $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.
       
    '#options' => image_style_options(FALSE, PASS_THROUGH),
        ...
      );
    ?>

    Example radios (before and after) - no code changes needed:

    <?php
      $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 sanitize radio button labels, and we therefore want to allow
        // image_style_options() to sanitize them.
       
    '#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.

  2. 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).

    Before:

    <?php
      $style
    = image_style_load('some_style');
     
    drupal_set_message(t('The style %name was loaded.', array('%name' => $style['name'])));
    ?>

    After:

    <?php
      $style
    = image_style_load('some_style');
     
    drupal_set_message(t('The style %name was loaded.', array('%name' => $style['label'])));
    ?>
  3. 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.)
  4. 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.

Impacts: 
Site builders, administrators, editors
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

Este Drupal é realmente um Show !!!
Aproveitem galera !

José Carlos da Costa Júnior
Coordenador de T.I.
Alfenas-MG