1 image.module image_style_options($include_empty = TRUE, $output = CHECK_PLAIN)

Get an array of image styles suitable for using as select list options.

Parameters

$include_empty: If TRUE a <none> option will be inserted in the options array.

$output: Optional flag determining how the options will be sanitized on output. Leave this at the default (CHECK_PLAIN) if you are using the output of this function directly in an HTML context, such as for checkbox or radio button labels, and do not plan to sanitize it on your own. If using the output of this function as select list options (its primary use case), you should instead set this flag to PASS_THROUGH to avoid double-escaping of the output (the form API sanitizes select list options by default).

Return value

Array of image styles with the machine name as key and the label as value.:

File

core/modules/image/image.module, line 659
Exposes global functionality for creating image styles.

Code

function image_style_options($include_empty = TRUE, $output = CHECK_PLAIN) {
  $styles = image_styles();
  $options = array();
  if ($include_empty && !empty($styles)) {
    $options[''] = t('<none>');
  }
  foreach ($styles as $name => $style) {
    $options[$name] = ($output == PASS_THROUGH) ? $style['label'] : check_plain($style['label']);
  }

  // Use the array concatenation operator '+' here instead of array_merge(),
  // because the latter loses the datatype of the array keys, turning
  // associative string keys into numeric ones without warning.
  $options = $options + backdrop_map_assoc(array_keys($styles));
  if (empty($options)) {
    $options[''] = t('No defined styles');
  }
  return $options;
}