Skip to content

Commit

Permalink
Add SEO install / field create
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Apr 21, 2023
1 parent 79d8f08 commit 7aefa1a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"minimum-stability": "dev",
"require": {
"craftcms/cms": "^4",
"ether/logs": "*"
"ether/logs": "*",
"ether/seo": "*"
},
"autoload": {
"psr-4": {
Expand Down
23 changes: 23 additions & 0 deletions src/UtilityBelt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,14 +101,35 @@ 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
{
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
Expand Down

0 comments on commit 7aefa1a

Please sign in to comment.