function ImageDerivativeUtilities::styleOptions

Same name and namespace in other branches
  1. 11.x core/modules/image/src/ImageDerivativeUtilities.php \Drupal\image\ImageDerivativeUtilities::styleOptions()

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

Parameters

bool $include_empty: If TRUE a '- None -' option will be inserted in the options array.

Return value

string[] Array of image styles where the key is the machine name and the value is the label.

File

core/modules/image/src/ImageDerivativeUtilities.php, line 40

Class

ImageDerivativeUtilities
Image style flush and options utilities.

Namespace

Drupal\image

Code

public function styleOptions(bool $include_empty = TRUE) : array {
  $styles = ImageStyle::loadMultiple();
  $options = [];
  if ($include_empty && !empty($styles)) {
    $options[''] = $this->t('- None -');
  }
  foreach ($styles as $name => $style) {
    $options[$name] = $style->label();
  }
  if (empty($options)) {
    $options[''] = $this->t('No defined styles');
  }
  return $options;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.