- Issue created by @kolotunbobo
- Status changed to Postponed: needs info
about 1 year ago 10:54pm 12 October 2023 - πΊπΈ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.
- π΅πPhilippines wilhansen
I am able to replicate it:
Drupal: 10.3.2
bootstrap_horizontal_tabs version: 2.0.7Steps:
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); + } }