4

I'm able to get a list of fields using

$fields = array_keys(\Drupal::entityManager()->getFieldDefinitions('node', 'ce_meeting'));

But is there a way to get a list of Image Styles instead? Something similar to

$fields = array_keys(\Drupal::entityManager()->getImageStyles());

to spit out an array

['thumbnail','original','medium','large','small']

Is there a function to display a list of available image styles?

10

use

use Drupal\image\Entity\ImageStyle;

and load all image style with

$styles = ImageStyle::loadMultiple();

Also you can use entity_load_multiple with

 styles = \Drupal::entityTypeManager()->getStorage('image_style')->loadMultiple();
4

You can get a list of all image styles with an entity query:

$image_styles = \Drupal::entityQuery('image_style')
        ->execute();

If you query the config entity image_style, you get an array with a list of available image styles.

If you use loadMultiple() on the config entity, you get an array with the loaded config objects. Use this, if you need the configurations.

If you only need a list, use entity query, because this is faster.

1

If you'd like to get it with Drush on the CLI, use:

drush ev "print_r(array_keys(\Drupal::entityTypeManager()->getStorage('image_style')->loadMultiple()));"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.