Tab pictures are deleted after 6 hours, due to being marked temporary

Created on 7 October 2023, about 1 year ago
Updated 17 September 2024, 3 months ago

If you insert a picture into the tabs, it is not marked as being used in the system.

The /admin/content/files section will show 0 places and the file is marked as temporary and will be deleted 6 hours after the cron run.

πŸ› Bug report
Status

Postponed: needs info

Version

2.0

Component

User interface

Created by

πŸ‡·πŸ‡ΊRussia kolotunbobo

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

Comments & Activities

  • Issue created by @kolotunbobo
  • Status changed to Postponed: needs info about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for reporting this! Can you provide more information about how you are inserting the image into the tabs, such as enumerated steps to reproduce? On the surface, it's not clear to me how this module's code would be responsible for the problem described.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡΅πŸ‡­Philippines wilhansen

    I am able to replicate it:

    Drupal: 10.3.2
    bootstrap_horizontal_tabs version: 2.0.7

    Steps:

    1. Create a content type with a body field and horizontal tabs field.
    2. Set the full HTML editor to CKEditor 5.
    3. Create a new content, setting both body and horizontal tabs body field as Full HTML.
    4. Insert an image using CKEditor on both body and horizontal tabs field. (in the example, A is in the body, B is in the horizontal tabs.
    5. Save (published or not, it does not matter)
    6. Check the Files (/admin/content/files), the image uploaded in the horizontal tabs field is set to "Temporary" even though it's being used.

    Expected outcome:
    Both A and B are marked as "Permanent"

    Actual outcome:
    A is marked "Permanent" while B is marked "Temporary"

  • πŸ‡΅πŸ‡­Philippines wilhansen

    The bug is probably due to this field inheriting from FieldItemBase. In order for the editor module to recognize the uploaded files, the field should inherit from TextItemBase as stated in https://api.drupal.org/api/drupal/core%21modules%21editor%21editor.modul...

  • πŸ‡΅πŸ‡­Philippines wilhansen

    Related issue https://www.drupal.org/node/2732429 β†’
    Other modules (such as faqfield referencing the same issue) are having the same problems.

    I implemented the hack that faqfield did (https://git.drupalcode.org/project/faqfield/-/merge_requests/6/diffs?com...) and on BootStrapHorizontalTabs.php and it fixed this issue.

  • πŸ‡¨πŸ‡¦Canada hommesreponse

    @wilhansen could you let us know where inside BootStrapHorizontalTabs.php to apply the hack. I saw what they did in the faqfield module but couldn't quite figure out how it applies in this module. Forgive me for my ignorance.

    Thanks!

  • πŸ‡΅πŸ‡­Philippines wilhansen

    @hommesresponse here's the diff:

    diff --git a/docroot/modules/contrib/bootstrap_horizontal_tabs/src/Plugin/Field/FieldType/BootstrapHorizontalTabs.php b/docroot/modules/contrib/bootstrap_horizontal_tabs/src/Plugin/Field/FieldType/BootstrapHorizontalTabs.php
    index c587720ad..956a42342 100644
    --- a/docroot/modules/contrib/bootstrap_horizontal_tabs/src/Plugin/Field/FieldType/BootstrapHorizontalTabs.php
    +++ b/docroot/modules/contrib/bootstrap_horizontal_tabs/src/Plugin/Field/FieldType/BootstrapHorizontalTabs.php
    @@ -3,10 +3,10 @@
     namespace Drupal\bootstrap_horizontal_tabs\Plugin\Field\FieldType;
    
     use Drupal\Core\Field\FieldDefinitionInterface;
    -use Drupal\Core\Field\FieldItemBase;
     use Drupal\Core\Field\FieldStorageDefinitionInterface;
     use Drupal\Core\StringTranslation\TranslatableMarkup;
     use Drupal\Core\TypedData\DataDefinition;
    +use Drupal\text\Plugin\Field\FieldType\TextItemBase;
    
     /**
      * Plugin implementation of the 'bootstrap_horizontal_tabs' field type.
    @@ -19,12 +19,13 @@
      *   default_formatter = "bootstrap_horizontal_tabs"
      * )
      */
    -class BootstrapHorizontalTabs extends FieldItemBase {
    +class BootstrapHorizontalTabs extends TextItemBase {
    
       /**
        * {@inheritdoc}
        */
       public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    +    parent::propertyDefinitions($field_definition);
         // Prevent early t() calls by using the TranslatableMarkup.
         $properties['header'] = DataDefinition::create('string')
           ->setLabel(new TranslatableMarkup('Tab header'))
    @@ -104,4 +105,16 @@ public function getConstraints() {
         return $constraints;
       }
    
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setValue($values, $notify = TRUE) {
    +    // A hack inspired by faqfield: https://git.drupalcode.org/project/faqfield/-/merge_requests/6/diffs?commit_id=df1c965cb5656870b71db53658f400551cf88847
    +    // to hook this plugin with the editor.module in making images permanent.
    +    if (is_array($values) && isset($values['body_value'])) {
    +      $values['value'] = $values['body_value'];
    +    }
    +    parent::setValue($values, $notify);
    +  }
     }
  • πŸ‡¨πŸ‡¦Canada hommesreponse

    @wilhansen Thanks so much!

Production build 0.71.5 2024