From 4dbd08118c7b3b55752f38694beef58cfa21a3f4 Mon Sep 17 00:00:00 2001 From: Jeroen Lammerts Date: Fri, 4 Nov 2022 10:40:30 +0100 Subject: [PATCH 1/4] Add CraftCMS ^4.0.0 compatibility --- CHANGELOG.md | 8 +- README.html | 1079 ------------------------------ README.md | 8 +- composer.json | 9 +- src/Searchit.php | 13 +- src/models/ElementFilter.php | 4 +- src/services/ElementFilters.php | 2 +- src/translations/en/searchit.php | 2 +- 8 files changed, 22 insertions(+), 1103 deletions(-) delete mode 100644 README.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fa78be..e34e514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Searchit Changelog -> Configure powerful custom filters for an enhanced search experience in the Craft CMS control panel for [Craft 3](http://craftcms.com) +> Configure powerful custom filters for an enhanced search experience in the Craft CMS control panel for [Craft 4](http://craftcms.com) + +## 2.0.0 - 2022-11-04 + +### Added + +* Added - CraftCMS ^4.0.0 compatibility. ## 1.0.8 - 2019-05-16 diff --git a/README.html b/README.html deleted file mode 100644 index 79e33a9..0000000 --- a/README.html +++ /dev/null @@ -1,1079 +0,0 @@ -README

Searchit

- -

Searchit plugin for Craft CMS 3

-

Configure powerful custom filters for enhanced search in the Craft CP.

-

This plugin gives your CP users an extensive tool for searching/ filtering entries, categories, assets and users in the CP.

-

Uses and extends the Craft CP element search

-

Examples

-

You have two ways to setup filters. Manually or dynamically.

-

Assets

-
-
- -

Entries

-
-
- -

Categories

-
-
- -

Tip: As with the regular Craft Search, if you suspect that your search indexes don’t have the latest and greatest data, you can have Craft rebuild them with the Rebuild Search Indexes tool in Settings.

-

Brought to you by Fruit Studios

\ No newline at end of file diff --git a/README.md b/README.md index 5406a21..667c9dd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -

Searchit

+

Searchit

-# Searchit plugin for Craft CMS 3 +# Searchit plugin for Craft CMS 4.x Configure powerful custom filters for an enhanced search experience in the Craft CMS control panel. Harness the power of twig and element queries to create endless filtering options. Keep your clients happy! @@ -11,7 +11,7 @@ See it in action... ## Requirements -This plugin requires Craft CMS 3.1.2 or later. +This plugin requires Craft CMS 4.0.0 or later. ## Installation @@ -151,7 +151,7 @@ Support for Commerce coming very soon #### Useful Resources Craft CMS Search Documentation [Docs](https://docs.craftcms.com/v3/searching.html) -As with the regular Craft Search, if you suspect that your search indexes don’t have the latest and greatest data, you can have Craft rebuild them with the Rebuild Search Indexes tool in Settings. [Docs](https://docs.craftcms.com/v3/searching.html#rebuilding-your-search-indexes) +As with the regular Craft Search, if you suspect that your search indexes don’t have the latest and greatest data, you can have Craft rebuild them with the Rebuild Search Indexes tool in Settings. [Docs](https://craftcms.com/docs/4.x/searching.html#rebuilding-your-search-indexes) Brought to you by [FRUIT](https://fruitstudios.co.uk) diff --git a/composer.json b/composer.json index 4f2cfbc..a8304c1 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,6 @@ "name": "fruitstudios/searchit", "description": "Configure powerful custom filters for an enhanced search experience in the Craft CMS control panel.", "type": "craft-plugin", - "version": "1.0.8", "keywords": [ "craft", "cms", @@ -16,8 +15,8 @@ "elements" ], "support": { - "docs": "https://github.com/fruitstudios/craft-searchit/blob/master/README.md", - "issues": "https://github.com/fruitstudios/craft-searchit/issues" + "docs": "https://github.com/presseddigital/searchit/blob/master/README.md", + "issues": "https://github.com/presseddigital/searchit/issues" }, "license": "proprietary", "authors": [ @@ -27,7 +26,7 @@ } ], "require": { - "craftcms/cms": "^3.1.2" + "craftcms/cms": "^4.0.0" }, "autoload": { "psr-4": { @@ -39,7 +38,7 @@ "handle": "searchit", "hasCpSettings": true, "hasCpSection": false, - "changelogUrl": "https://raw.githubusercontent.com/fruitstudios/craft-searchit/master/CHANGELOG.md", + "changelogUrl": "https://raw.githubusercontent.com/presseddigital/searchit/master/CHANGELOG.md", "class": "fruitstudios\\searchit\\Searchit" } } diff --git a/src/Searchit.php b/src/Searchit.php index 1a0a748..c2be77b 100644 --- a/src/Searchit.php +++ b/src/Searchit.php @@ -1,6 +1,6 @@ $this->name]), __METHOD__); } - public function beforeInstall(): bool - { - return true; - } - public function afterInstallPlugin(PluginEvent $event) { $isCpRequest = Craft::$app->getRequest()->isCpRequest; @@ -116,7 +111,7 @@ public function afterInstallPlugin(PluginEvent $event) } } - public function getSettingsResponse() + public function getSettingsResponse(): mixed { return Craft::$app->controller->redirect(UrlHelper::cpUrl('searchit/settings')); } @@ -190,7 +185,7 @@ public function initElementFilters() // Protected Methods // ========================================================================= - protected function createSettingsModel() + protected function createSettingsModel(): ?craft\base\Model { return new Settings(); } diff --git a/src/models/ElementFilter.php b/src/models/ElementFilter.php index 462757f..a8b0c16 100644 --- a/src/models/ElementFilter.php +++ b/src/models/ElementFilter.php @@ -191,12 +191,10 @@ public function getOptions() public function getPreview() { - return Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'select', [ + return Craft::$app->getView()->renderObjectTemplate('_includes/forms', 'select', [ [ 'options' => $this->getOptions(), ] ]); } - - } diff --git a/src/services/ElementFilters.php b/src/services/ElementFilters.php index 583fe87..3cb3ad3 100644 --- a/src/services/ElementFilters.php +++ b/src/services/ElementFilters.php @@ -132,7 +132,7 @@ public function getSupportedSources(string $elementType) 'handle' => self::GLOBAL_SOURCE_HANDLE, ]; - $allSources = Craft::$app->getElementIndexes()->getSources($elementType); + $allSources = Craft::$app->getElementSources()->getSources($elementType); if($allSources) { foreach ($allSources as $source) diff --git a/src/translations/en/searchit.php b/src/translations/en/searchit.php index 5f5caac..859f0c8 100644 --- a/src/translations/en/searchit.php +++ b/src/translations/en/searchit.php @@ -1,6 +1,6 @@ Date: Fri, 4 Nov 2022 11:05:26 +0100 Subject: [PATCH 2/4] Fix deprecated methods, added typehints and missing imports --- src/controllers/ElementFiltersController.php | 5 ++--- src/models/ElementFilter.php | 2 ++ src/services/ElementFilters.php | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/ElementFiltersController.php b/src/controllers/ElementFiltersController.php index db47ee2..cbdf4ac 100644 --- a/src/controllers/ElementFiltersController.php +++ b/src/controllers/ElementFiltersController.php @@ -8,9 +8,8 @@ use Craft; use craft\web\Controller; -use craft\helpers\StringHelper; use craft\helpers\Json; - +use yii\web\HttpException; use yii\web\Response; class ElementFiltersController extends Controller @@ -141,7 +140,7 @@ public function actionDelete(): Response { return $this->asJson(['success' => true]); } - return $this->asErrorJson(Craft::t('searchit', 'Could not delete element filter')); + return $this->asFailure(Craft::t('searchit', 'Could not delete element filter')); } public function actionReorder(): Response diff --git a/src/models/ElementFilter.php b/src/models/ElementFilter.php index a8b0c16..2c6c191 100644 --- a/src/models/ElementFilter.php +++ b/src/models/ElementFilter.php @@ -37,6 +37,7 @@ public function rules(): array public function validateSettings() { + /** @var craft\web\View $view */ $view = Craft::$app->getView(); $currentTemplateMode = $view->getTemplateMode(); $view->setTemplateMode($view::TEMPLATE_MODE_SITE); @@ -167,6 +168,7 @@ public function getOptions() break; case 'dynamic': + /** @var craft\web\View $view */ $view = Craft::$app->getView(); $currentTemplateMode = $view->getTemplateMode(); $view->setTemplateMode($view::TEMPLATE_MODE_SITE); diff --git a/src/services/ElementFilters.php b/src/services/ElementFilters.php index 3cb3ad3..720e91e 100644 --- a/src/services/ElementFilters.php +++ b/src/services/ElementFilters.php @@ -20,6 +20,7 @@ use craft\commerce\elements\Product; use craft\commerce\Plugin as CommercePlugin; +use Exception; class ElementFilters extends Component { From ecc0e699ff315eaf6b8008a78afbbaf4511a8f6b Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Thu, 15 Jun 2023 17:01:08 +0200 Subject: [PATCH 3/4] update js to show filtering in Craft v4 Fix layout bug in Craft v4 Plugin Preview and js fault in "normal" entry filter view --- src/web/assets/searchit/build/js/ElementFilters.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/web/assets/searchit/build/js/ElementFilters.js b/src/web/assets/searchit/build/js/ElementFilters.js index a62d81f..b0140f2 100644 --- a/src/web/assets/searchit/build/js/ElementFilters.js +++ b/src/web/assets/searchit/build/js/ElementFilters.js @@ -2,7 +2,7 @@ var ElementFilters = (function() { "use strict"; var defaults = { - debug: false, + debug: false, attributes: { id: 'data-element-filters-id', filters: 'data-element-filters', @@ -41,7 +41,7 @@ var ElementFilters = (function() { // DOM Elements dom.toolbar = elementIndex.$toolbar[0]; - dom.search = elementIndex.$search[0].closest('.search'); + dom.search = elementIndex.$search[0].parentNode.querySelector('.search'); // Listeners dom.toolbar.addEventListener('change', filterHandler, false); @@ -172,7 +172,7 @@ var ElementFilters = (function() { var filters = getElementFilters(elementIndex.elementType, elementIndex.sourceKey); if(filters) { - dom.search.parentNode.insertBefore(filters, dom.search); + dom.search.parentNode.parentNode.insertBefore(filters, dom.search.parentNode); } } } @@ -183,7 +183,7 @@ var ElementFilters = (function() { var filters = getElementFilters(dom.preview.getAttribute('data-type'), dom.preview.getAttribute('data-source')); if(filters) { - dom.search.parentNode.insertBefore(filters, dom.search); + dom.search.parentNode.parentNode.insertBefore(filters, dom.search.parentNode); } } } From 28064b185857799ba5987e32d05a85a93772d0a5 Mon Sep 17 00:00:00 2001 From: Jeffrey Zant Date: Wed, 5 Mar 2025 13:27:46 +0100 Subject: [PATCH 4/4] fix spaces -> tabs --- src/web/assets/searchit/build/js/ElementFilters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/assets/searchit/build/js/ElementFilters.js b/src/web/assets/searchit/build/js/ElementFilters.js index b0140f2..e9eb358 100644 --- a/src/web/assets/searchit/build/js/ElementFilters.js +++ b/src/web/assets/searchit/build/js/ElementFilters.js @@ -2,7 +2,7 @@ var ElementFilters = (function() { "use strict"; var defaults = { - debug: false, + debug: false, attributes: { id: 'data-element-filters-id', filters: 'data-element-filters',