cde93fc2e9359fbbcdca479bd99933519c007df8
[yaffs-website] / web / core / modules / image / image.post_update.php
1 <?php
2
3 /**
4  * @file
5  * Post-update functions for Image.
6  */
7
8 use Drupal\Core\Config\Entity\ConfigEntityUpdater;
9 use Drupal\Core\Entity\Entity\EntityViewDisplay;
10 use Drupal\Core\Entity\Entity\EntityFormDisplay;
11
12 /**
13  * Saves the image style dependencies into form and view display entities.
14  */
15 function image_post_update_image_style_dependencies() {
16   // Merge view and form displays. Use array_values() to avoid key collisions.
17   $displays = array_merge(array_values(EntityViewDisplay::loadMultiple()), array_values(EntityFormDisplay::loadMultiple()));
18   /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface[] $displays */
19   foreach ($displays as $display) {
20     // Re-save each config entity to add missed dependencies.
21     $display->save();
22   }
23 }
24
25 /**
26  * Add 'anchor' setting to 'Scale and crop' effects.
27  */
28 function image_post_update_scale_and_crop_effect_add_anchor(&$sandbox = NULL) {
29   \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'image_style', function ($image_style) {
30     /** @var \Drupal\image\ImageStyleInterface $image_style */
31     $effects = $image_style->getEffects();
32     foreach ($effects as $effect) {
33       if ($effect->getPluginId() === 'image_scale_and_crop') {
34         return TRUE;
35       }
36     }
37     return FALSE;
38   });
39 }