From 7aefa1a8ea438c1dcd08b0c5960bd918553aa980 Mon Sep 17 00:00:00 2001 From: Tam Date: Fri, 21 Apr 2023 16:34:04 +0100 Subject: [PATCH] Add SEO install / field create --- CHANGELOG.md | 4 ++++ README.md | 5 +++++ composer.json | 3 ++- src/UtilityBelt.php | 23 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b79a136..637d9d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.0 - 2023-04-21 +### Added +- Add SEO install / field create + ## 4.0.2 - 2023-04-21 ### Fixed - Fix incorrect func arg diff --git a/README.md b/README.md index 81a91d8..759c529 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ A collection of things we use on every Craft CMS site ## Features + +### SEO + +Automatically installs [ether/seo](https://github.com/ether/seo) and creates a default SEO field. + ### Logs Automatically installs [ether/logs](https://github.com/ether/logs). diff --git a/composer.json b/composer.json index e1b1b26..85d01b1 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "minimum-stability": "dev", "require": { "craftcms/cms": "^4", - "ether/logs": "*" + "ether/logs": "*", + "ether/seo": "*" }, "autoload": { "psr-4": { diff --git a/src/UtilityBelt.php b/src/UtilityBelt.php index 6df373b..54ca8ae 100644 --- a/src/UtilityBelt.php +++ b/src/UtilityBelt.php @@ -15,10 +15,12 @@ use craft\helpers\App; use craft\helpers\ElementHelper; use craft\helpers\Json; +use craft\records\FieldGroup; use craft\services\Dashboard; use craft\services\Fields; use craft\services\Gql; use craft\services\Plugins; +use ether\seo\fields\SeoField; use ether\utilitybelt\fields\LinkField; use ether\utilitybelt\jobs\RegenerateLinkCacheJob; use ether\utilitybelt\services\LivePreview; @@ -99,7 +101,14 @@ public function onAfterUninstallPlugin (PluginEvent $event): void { if ($event->plugin->getHandle() !== $this->getHandle()) return; + try { + $fields = Craft::$app->getFields(); + $fields->deleteFieldById($fields->getFieldByHandle('seo')->id); + $fields->deleteGroupById(FieldGroup::findOne(['name' => 'SEO'])->id); + } /** @noinspection PhpStatementHasEmptyBodyInspection */ finally {} + Craft::$app->getPlugins()->uninstallPlugin('logs'); + Craft::$app->getPlugins()->uninstallPlugin('seo'); } public function onAfterInstallPlugin (PluginEvent $event): void @@ -107,6 +116,20 @@ public function onAfterInstallPlugin (PluginEvent $event): void if ($event->plugin->getHandle() !== $this->getHandle()) return; Craft::$app->getPlugins()->installPlugin('logs'); + Craft::$app->getPlugins()->installPlugin('seo'); + + $fields = Craft::$app->getFields(); + + $group = new \craft\models\FieldGroup(['name' => 'SEO']); + $fields->saveGroup($group); + + $seoField = $fields->createField([ + 'type' => SeoField::class, + 'name' => 'SEO', + 'handle' => 'seo', + 'groupId' => $group->id, + ]); + $fields->saveField($seoField); } public function onAfterExecuteGqlQuery (ExecuteGqlQueryEvent $event): void