- 🇪🇸Spain Carlitus
The problem, as @frazras comments, is that the function submitConfigurationForm never triggers but neither of this plugin nor of others of the style options.
Finally I have done it in a not very optimal way, but the only one I have seen.
From a hook_node_update I go through all the paragraphs looking for the style options that has the backgroun image and I do the same thing that should be done in the submitConfigurationForm.
This is my code in case someone wants to use it or improve it:
use Drupal\Core\Entity\EntityInterface; use Drupal\file\Entity\File; use Drupal\paragraphs\ParagraphInterface; function omitsis_modular_node_update(Drupal\Core\Entity\EntityInterface $entity) { if ('modular_page' == $entity->bundle()) { if ($entity->hasField('field_paragraphs')) { foreach ($entity->field_paragraphs as $paragraph) { $paragraph = $paragraph->entity; $style_options = om_getStyleOptions($paragraph); foreach ($style_options as $key => $value) { if ('background_image' == $key) { $fid = $value['fid'][0]; $file = File::load($fid); $file->setPermanent(); $file->save(); } } } } } } function om_getStyleOptions(ParagraphInterface $paragraph): array { $style_options = []; if ($behaviors = $paragraph->getAllBehaviorSettings()) { if (!empty($behaviors['style_options'])) { $style_options = $behaviors['style_options']; } } return $style_options; }
- First commit to issue fork.