Skip to content

Commit 8bdbc32

Browse files
chore: Tidy up plugin metadata
1 parent d8cb296 commit 8bdbc32

File tree

6 files changed

+69
-106
lines changed

6 files changed

+69
-106
lines changed

composer.json

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,45 @@
11
{
2-
"name": "fostercommerce/entry-type-rules",
3-
"description": "A Craft plugin that allows you to set rules on number of entry types in a Craft section and/or limit who can include entry type entries based on their user group.",
4-
"type": "craft-plugin",
5-
"version": "3.0.0",
6-
"keywords": [
7-
"craft",
8-
"cms",
9-
"craftcms",
10-
"craft-plugin",
11-
"entry type",
12-
"rules"
13-
],
14-
"support": {
15-
"docs": "https://github.com/FosterCommerce/entry-type-rules/blob/main/README.md",
16-
"issues": "https://github.com/FosterCommerce/entry-type-rules/issues"
17-
},
18-
"license": "proprietary",
19-
"authors": [
20-
{
21-
"name": "Foster Commerce",
22-
"homepage": "https://fostercommerce.com"
23-
}
24-
],
25-
"require": {
26-
"php": "^8.2",
27-
"craftcms/cms": "^5.0"
28-
},
29-
"autoload": {
30-
"psr-4": {
31-
"fostercommerce\\entrytyperules\\": "src/"
32-
}
33-
},
34-
"extra": {
35-
"name": "Entry Type Rules",
36-
"handle": "entry-type-rules",
37-
"developer": "Foster Commerce",
38-
"developerUrl": "https://fostercommerce.com",
39-
"documentationUrl": "https://github.com/FosterCommerce/entry-type-rules/blob/main/README.md",
40-
"changelogUrl": "https://raw.githubusercontent.com/FosterCommerce/entry-type-rules/main/CHANGELOG.md",
41-
"components": {
42-
"entryTypeRulesService": "fostercommerce\\entrytyperules\\services\\EntryTypeRulesService"
43-
},
44-
"class": "fostercommerce\\entrytyperules\\EntryTypeRules"
45-
},
46-
"require-dev": {
2+
"name": "fostercommerce/entry-type-rules",
3+
"description": "A Craft plugin that allows you to set rules on number of entry types in a Craft section and/or limit who can include entry type entries based on their user group.",
4+
"type": "craft-plugin",
5+
"version": "3.0.0",
6+
"keywords": [
7+
"craft",
8+
"cms",
9+
"craftcms",
10+
"craft-plugin",
11+
"entry type",
12+
"rules"
13+
],
14+
"support": {
15+
"docs": "https://github.com/FosterCommerce/entry-type-rules/blob/main/README.md",
16+
"issues": "https://github.com/FosterCommerce/entry-type-rules/issues"
17+
},
18+
"license": "proprietary",
19+
"authors": [
20+
{
21+
"name": "Foster Commerce",
22+
"homepage": "https://fostercommerce.com"
23+
}
24+
],
25+
"require": {
26+
"php": "^8.2",
27+
"craftcms/cms": "^5.0"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"fostercommerce\\entrytyperules\\": "src/"
32+
}
33+
},
34+
"extra": {
35+
"name": "Entry Type Rules",
36+
"handle": "entry-type-rules",
37+
"developer": "Foster Commerce",
38+
"developerUrl": "https://fostercommerce.com",
39+
"documentationUrl": "https://github.com/FosterCommerce/entry-type-rules/blob/main/README.md",
40+
"changelogUrl": "https://raw.githubusercontent.com/FosterCommerce/entry-type-rules/main/CHANGELOG.md"
41+
},
42+
"require-dev": {
4743
"roave/security-advisories": "dev-latest",
4844
"craftcms/generator": "^2.1",
4945
"fostercommerce/rector": "dev-main",
@@ -59,10 +55,10 @@
5955
"rector": "rector process --config rector.php",
6056
"rector-dry-run": "rector process --dry-run --config rector.php"
6157
},
62-
"config": {
63-
"allow-plugins": {
64-
"yiisoft/yii2-composer": true,
65-
"craftcms/plugin-installer": true
66-
}
67-
}
58+
"config": {
59+
"allow-plugins": {
60+
"yiisoft/yii2-composer": true,
61+
"craftcms/plugin-installer": true
62+
}
63+
}
6864
}
Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
use craft\base\Element;
77
use craft\base\Model;
88

9-
use craft\base\Plugin;
9+
use craft\base\Plugin as BasePlugin;
1010
use craft\elements\Entry;
1111
use craft\events\DefineHtmlEvent;
12+
use craft\web\Controller;
1213
use craft\web\View;
1314
use fostercommerce\entrytyperules\assetbundles\entrytyperules\EntryTypeRulesAsset;
1415
use fostercommerce\entrytyperules\models\Settings;
15-
use fostercommerce\entrytyperules\services\EntryTypeRulesService as EntryTypeRulesServiceService;
16+
use fostercommerce\entrytyperules\services\Service;
1617
use yii\base\Event;
1718
use yii\base\InvalidConfigException;
1819

1920
/**
20-
* @property EntryTypeRulesServiceService $entryTypeRulesService
21+
* @property Service $service
2122
* @property Settings $settings
2223
* @method Settings getSettings()
2324
*/
24-
class EntryTypeRules extends Plugin
25+
class Plugin extends BasePlugin
2526
{
2627
public bool $hasCpSettings = true;
2728

@@ -32,8 +33,10 @@ public function init(): void
3233
{
3334
parent::init();
3435

35-
Craft::setAlias('@plugin', $this->getBasePath());
36-
//
36+
$this->setComponents([
37+
'service' => Service::class,
38+
]);
39+
3740
Event::on(
3841
Element::class,
3942
Element::EVENT_DEFINE_SIDEBAR_HTML,
@@ -57,48 +60,13 @@ function (DefineHtmlEvent $event): void {
5760
}
5861
}
5962
);
60-
61-
/**
62-
* Logging in Craft involves using one of the following methods:
63-
*
64-
* Craft::trace(): record a message to trace how a piece of code runs. This is mainly for development use.
65-
* Craft::info(): record a message that conveys some useful information.
66-
* Craft::warning(): record a warning message that indicates something unexpected has happened.
67-
* Craft::error(): record a fatal error that should be investigated as soon as possible.
68-
*
69-
* Unless `devMode` is on, only Craft::warning() & Craft::error() will log to `craft/storage/logs/web.log`
70-
*
71-
* It's recommended that you pass in the magic constant `__METHOD__` as the second parameter, which sets
72-
* the category to the method (prefixed with the fully qualified class name) where the constant appears.
73-
*
74-
* To enable the Yii debug toolbar, go to your user account in the AdminCP and check the
75-
* [] Show the debug toolbar on the front end & [] Show the debug toolbar on the Control Panel
76-
*
77-
* http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html
78-
*/
79-
Craft::info(
80-
Craft::t(
81-
'entry-type-rules',
82-
'{name} plugin loaded',
83-
[
84-
'name' => $this->name,
85-
]
86-
),
87-
__METHOD__
88-
);
8963
}
9064

91-
/**
92-
* Intercepts the plugin settings page response so we can check the config override file
93-
* (if it exists) and so we can process the Post response in our own settings controller method
94-
* instead of using the general Craft settings HTML method to render the settings page.
95-
* @inheritdoc
96-
*/
9765
public function getSettingsResponse(): mixed
9866
{
9967
$overrides = Craft::$app->getConfig()->getConfigFromFile($this->handle);
10068

101-
/** @var \craft\web\Controller $controller */
69+
/** @var Controller $controller */
10270
$controller = Craft::$app->controller;
10371
return $controller->renderTemplate(
10472
'entry-type-rules/settings',

src/controllers/DefaultController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use craft\web\Application;
1818
use craft\web\Controller;
1919
use craft\web\User;
20-
use fostercommerce\entrytyperules\EntryTypeRules;
20+
use fostercommerce\entrytyperules\Plugin;
2121

2222
/**
2323
* Default Controller
@@ -75,8 +75,8 @@ public function actionIndex(): mixed
7575
/** @var User $user */
7676
$user = Craft::$app->getUser();
7777

78-
$result['lockedEntryTypes'] = EntryTypeRules::getInstance()
79-
?->entryTypeRulesService
78+
$result['lockedEntryTypes'] = Plugin::getInstance()
79+
?->service
8080
->getLockedEntryTypes($sectionId, $user);
8181
}
8282

src/controllers/SettingsController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
use craft\errors\MissingComponentException;
88
use craft\web\Controller;
99
use craft\web\Request;
10-
use fostercommerce\entrytyperules\EntryTypeRules;
1110
use fostercommerce\entrytyperules\models\Settings;
12-
use fostercommerce\shipstationconnect\Plugin;
11+
use fostercommerce\entrytyperules\Plugin;
1312
use yii\base\InvalidConfigException;
1413
use yii\web\BadRequestHttpException;
1514
use yii\web\MethodNotAllowedHttpException;
@@ -35,8 +34,8 @@ public function actionSaveSettings(): Response
3534
/** @var Request $request */
3635
$request = Craft::$app->getRequest();
3736

38-
/** @var EntryTypeRules $plugin */
39-
$plugin = EntryTypeRules::getInstance();
37+
/** @var Plugin $plugin */
38+
$plugin = Plugin::getInstance();
4039

4140
$settings = new Settings([
4241
'sections' => $request->getBodyParam('sections'),
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use craft\base\Component;
88
use craft\elements\Entry;
99
use craft\web\User;
10-
use fostercommerce\entrytyperules\EntryTypeRules;
1110
use fostercommerce\entrytyperules\models\Settings;
11+
use fostercommerce\entrytyperules\Plugin;
1212

13-
class EntryTypeRulesService extends Component
13+
class Service extends Component
1414
{
1515
/**
1616
* @return array<int, int>
@@ -23,7 +23,7 @@ public function getLockedEntryTypes(int $sectionId, User $user): array
2323

2424
// Get the plugins settings
2525
/** @var Settings $settings */
26-
$settings = EntryTypeRules::getInstance()?->getSettings();
26+
$settings = Plugin::getInstance()?->getSettings();
2727

2828
// Get all the entry types for this section into an array
2929
$sectionEntryTypes = Craft::$app->getEntries()->getEntryTypesBySectionId($sectionId);

tests/unit/ExampleUnitTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Codeception\Test\Unit;
1515
use UnitTester;
1616
use Craft;
17-
use fostercommerce\entrytyperules\EntryTypeRules;
17+
use fostercommerce\entrytyperules\Plugin;
1818

1919
/**
2020
* ExampleUnitTest
@@ -46,8 +46,8 @@ class ExampleUnitTest extends Unit
4646
public function testPluginInstance()
4747
{
4848
$this->assertInstanceOf(
49-
EntryTypeRules::class,
50-
EntryTypeRules::$plugin
49+
Plugin::class,
50+
Plugin::$plugin
5151
);
5252
}
5353

0 commit comments

Comments
 (0)