Skip to content

[Image gallery] Write inherited hotspot data to query table when saving parent#18855

Merged
robertSt7 merged 2 commits intopimcore:12.3from
BlackbitDevs:bugfix/image-gallery-inherited-data
Jan 27, 2026
Merged

[Image gallery] Write inherited hotspot data to query table when saving parent#18855
robertSt7 merged 2 commits intopimcore:12.3from
BlackbitDevs:bugfix/image-gallery-inherited-data

Conversation

@BlackbitDevs
Copy link
Copy Markdown
Contributor

@BlackbitDevs BlackbitDevs commented Nov 27, 2025

Steps to reproduce bug:

  1. Create data object class Test, enable inheritance, add an image gallery field named images
  2. Create Test object /parent
  3. Create Test object /parent/child (so that it inherits data from /parent)
  4. Assign an image to the image gallery field of /parent, add a hotspot, save

Expected behaviour:
Image gallery data gets inherited to the child object, thus in database table object_query_Test the column images__hotspots there is the same data for /parent and /parent/child

Actual behaviour:
Column images__hotspots only gets filled for /parent but not for /parent/child.
After saving the child, images__hotspots is the same for both objects.

Cause:
The place which is responsible for writing inherited data for the child objects to the query tables is

$o['children'] = $this->buildTree($result['id'], $fields, null, $params);
if (!empty($this->fields)) {
foreach ($this->fields as $fieldname) {
foreach ($o['children'] as $c) {
$this->getIdsToUpdateForValuefields($c, $fieldname);
}
$this->updateQueryTable($oo_id, $this->fieldIds[$fieldname], $fieldname);
// not needed anymore
unset($this->fieldIds[$fieldname]);
}
}

Here getIdsToUpdateForValuefields() does not recognize the child column to be empty. There are multiple quirks here:

  1. In
    $value = $currentNode['values'][$fieldname] ?? null;
    if ($this->fieldDefinitions[$fieldname]->isEmpty($value)) {

    $fieldname is images__hotspots and so value is only the content of this column, not all columns which belong to image gallery data. But $this->fieldDefinitions[$fieldname] is a Pimcore\Model\DataObject\ClassDefinition\Data\ImageGallery object. So the actual $value does not match what ImageGallery::isEmpty() usually expects to get (a Pimcore\Model\DataObject\Data\ImageGallery object or null).
  2. $value is the string "a:0:{}" because when saving an image gallery without hotspots, an empty array gets serialized in
    $this->getName() . '__hotspots' => Serialize::serialize($hotspots),
    and stored in database.

So one way to solve the problem would be to add a check for $data === "a:0:{}" in

public function isEmpty(mixed $data): bool
{
if (empty($data)) {
return true;
}
but this only hides the quirks from above (nobody would immediately see how the string a:0:{} can get here).

For this reason I decided for a different approach: When saving an image gallery without hotspots, we store null in the database. This way the ImageGallery::isEmpty() will return true and thus the image gallery data in the query table gets updated when the parent gets saved.

@github-actions
Copy link
Copy Markdown

Review Checklist

  • Target branch (11.5 for bug fixes, others 12.x)
  • Tests (if it's testable code, there should be a test for it - get help)
  • Docs (every functionality needs to be documented, see here)
  • Migration incl. install.sql (e.g. if the database schema changes, ...)
  • Upgrade notes (deprecations, important information, migration hints, ...)
  • Label
  • Milestone

@sonarqubecloud
Copy link
Copy Markdown

@kingjia90 kingjia90 changed the base branch from 12.2 to 12.3 January 21, 2026 13:17
@kingjia90 kingjia90 self-assigned this Jan 21, 2026
@kingjia90 kingjia90 added this to the 12.3.2 milestone Jan 21, 2026
@kingjia90 kingjia90 removed their assignment Jan 21, 2026
@robertSt7 robertSt7 self-assigned this Jan 27, 2026
@robertSt7 robertSt7 merged commit 0b9f4a9 into pimcore:12.3 Jan 27, 2026
5 of 13 checks passed
@robertSt7
Copy link
Copy Markdown
Contributor

@BlackbitDevs Thanks for fixing the hotspot inheritance

@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants