Disappearing Background Images

Created on 3 August 2022, over 2 years ago
Updated 13 November 2023, about 1 year ago

I'm encountering a weird bug,
After about 24 hours or so, all created background images just disappear.

When I check the files directory, the images are not there.
When I check the upload field, it is empty.
This happened to me a couple of times.

Here are my settings:

bg_image:
    plugin: background_image
    label: Background Image
    method: css
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇹🇹Trinidad and Tobago frazras

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇪🇸Spain Carlitus

    I have the same problem, @frazras did you solved this?

  • 🇪🇸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.
Production build 0.71.5 2024