Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/EventRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function registerUpdateEvents()
Event::on(Structures::class, Structures::EVENT_AFTER_MOVE_ELEMENT, function ($event) {
static::handleUpdateEvent($event);
});
Event::on( Entries::class, Entries::EVENT_AFTER_SAVE_SECTION, function ($event) {
Event::on(Entries::class, Entries::EVENT_AFTER_SAVE_SECTION, function ($event) {
static::handleUpdateEvent($event);
});
}
Expand Down Expand Up @@ -85,7 +85,16 @@ public static function registerFrontendEvents()
Plugin::getInstance()->getTagCollection()->add($event->element->handle);
}

// Add to collection
// Nested elements inherit the root owner's entry tag
$rootOwner = $event->element->getRootOwner();
if ($rootOwner !== null && $rootOwner !== $event->element) {
Plugin::getInstance()->getTagCollection()->add(
Plugin::TAG_PREFIX_ELEMENT . $rootOwner->getId()
);
Comment on lines +88 to +93
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says “root owner's entry tag”, but the code is adding an element tag using the element prefix (TAG_PREFIX_ELEMENT) and the owner’s ID. Please adjust the wording to avoid confusion about what tag format is being emitted (and that the root owner may not always be an Entry).

Copilot uses AI. Check for mistakes.
return;
}
Comment on lines +88 to +95
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this early-return path, tags are added via TagCollection::add() but TagCollection uniqueness is only enforced by addTagsFromElement() (which calls unique()). This can introduce duplicate root-owner tags when multiple nested elements are populated, inflating the tag header and increasing the chance of truncation. Consider ensuring the collection is de-duplicated after adding the root-owner tag (e.g., expose a public unique/dedup method or add a dedicated addUnique helper).

Copilot uses AI. Check for mistakes.

// Add top-level element tags to the collection
Plugin::getInstance()->getTagCollection()->addTagsFromElement($event->row);
});

Expand Down Expand Up @@ -137,7 +146,6 @@ public static function registerFrontendEvents()
});
}


public static function registerCpEvents()
{
// Register cache purge checkbox
Expand All @@ -157,7 +165,6 @@ function (RegisterCacheOptionsEvent $event) {
);
}


public static function registerFallback()
{

Expand Down Expand Up @@ -202,15 +209,13 @@ public static function registerFallback()
});
}


/**
* @param \yii\base\Event $event
*/
protected static function handleUpdateEvent(Event $event)
{
$tags = [];


if ($event instanceof ElementEvent) {

// Prevent purge on updates of drafts or revisions
Expand All @@ -223,16 +228,11 @@ protected static function handleUpdateEvent(Event $event)
return;
}

// For nested elements (blocks), purge the root owner's tags
// For nested elements (blocks), purge only the root owner's entry tag
$rootOwner = $event->element->getRootOwner();
if ($rootOwner !== $event->element) {
if (isset($rootOwner->sectionId)) {
$tags[] = Plugin::TAG_PREFIX_SECTION . $rootOwner->sectionId;
}
if ($rootOwner !== null && $rootOwner !== $event->element) {
$tags[] = Plugin::TAG_PREFIX_ELEMENT . $rootOwner->getId();
}

if (Plugin::getInstance()->getSettings()->isCachableElement(get_class($event->element))) {
} elseif (Plugin::getInstance()->getSettings()->isCachableElement(get_class($event->element))) {
Comment on lines +231 to +235
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment describes purging the “root owner's entry tag”, but the tag being purged is an element-ID tag (TAG_PREFIX_ELEMENT + ID). Consider updating the comment to reflect the actual tag format and avoid implying it is entry-specific.

Copilot uses AI. Check for mistakes.
if ($event->element instanceof \craft\elements\GlobalSet && is_string($event->element->handle)) {
$tags[] = $event->element->handle;
} elseif ($event->element instanceof \craft\elements\Asset && $event->isNew) {
Expand Down