From 40fca9890ed7649e3de8ab737ba0576aa23f135d Mon Sep 17 00:00:00 2001 From: vnali <55586085+vnali@users.noreply.github.com> Date: Sat, 12 Feb 2022 22:24:59 +0330 Subject: [PATCH] fixed https://github.com/ethercreative/tags/issues/21 and https://github.com/ethercreative/tags/issues/18 for custom element types, Craft manages and invalidates element index cache on adding or editing an element. but for tag element, when you add or edit a tag via element index page or even tag field on entry page, Craft is not aware of this plugin's tag element type so this PR invalidate element type cache for this plugin on after save tag event --- src/TagManager.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/TagManager.php b/src/TagManager.php index 37faa05..b463db1 100644 --- a/src/TagManager.php +++ b/src/TagManager.php @@ -13,6 +13,8 @@ use craft\base\Model; use craft\base\Plugin; use craft\elements\actions\Edit; +use craft\elements\Tag as CraftTagElement; +use craft\events\ModelEvent; use craft\events\RegisterCpNavItemsEvent; use craft\events\RegisterElementActionsEvent; use craft\events\RegisterUrlRulesEvent; @@ -82,7 +84,14 @@ public function init () [$this, 'onRegisterIgnoredTypes'] ); } - + + Event::on( + CraftTagElement::class, + CraftTagElement::EVENT_AFTER_SAVE, + function (ModelEvent $event) { + Craft::$app->elements->invalidateCachesForElementType(Tag::class); + } + ); } // Craft @@ -179,4 +188,4 @@ public function onRegisterIgnoredTypes (RegisterIgnoredTypesEvent $event) $event->types[] = Tag::class; } -} \ No newline at end of file +}