Skip to content

Commit

Permalink
chore: Tidy up plugin metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnynotsolucky committed Sep 25, 2024
1 parent d8cb296 commit 8bdbc32
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 106 deletions.
98 changes: 47 additions & 51 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
{
"name": "fostercommerce/entry-type-rules",
"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.",
"type": "craft-plugin",
"version": "3.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"entry type",
"rules"
],
"support": {
"docs": "https://github.com/FosterCommerce/entry-type-rules/blob/main/README.md",
"issues": "https://github.com/FosterCommerce/entry-type-rules/issues"
},
"license": "proprietary",
"authors": [
{
"name": "Foster Commerce",
"homepage": "https://fostercommerce.com"
}
],
"require": {
"php": "^8.2",
"craftcms/cms": "^5.0"
},
"autoload": {
"psr-4": {
"fostercommerce\\entrytyperules\\": "src/"
}
},
"extra": {
"name": "Entry Type Rules",
"handle": "entry-type-rules",
"developer": "Foster Commerce",
"developerUrl": "https://fostercommerce.com",
"documentationUrl": "https://github.com/FosterCommerce/entry-type-rules/blob/main/README.md",
"changelogUrl": "https://raw.githubusercontent.com/FosterCommerce/entry-type-rules/main/CHANGELOG.md",
"components": {
"entryTypeRulesService": "fostercommerce\\entrytyperules\\services\\EntryTypeRulesService"
},
"class": "fostercommerce\\entrytyperules\\EntryTypeRules"
},
"require-dev": {
"name": "fostercommerce/entry-type-rules",
"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.",
"type": "craft-plugin",
"version": "3.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"entry type",
"rules"
],
"support": {
"docs": "https://github.com/FosterCommerce/entry-type-rules/blob/main/README.md",
"issues": "https://github.com/FosterCommerce/entry-type-rules/issues"
},
"license": "proprietary",
"authors": [
{
"name": "Foster Commerce",
"homepage": "https://fostercommerce.com"
}
],
"require": {
"php": "^8.2",
"craftcms/cms": "^5.0"
},
"autoload": {
"psr-4": {
"fostercommerce\\entrytyperules\\": "src/"
}
},
"extra": {
"name": "Entry Type Rules",
"handle": "entry-type-rules",
"developer": "Foster Commerce",
"developerUrl": "https://fostercommerce.com",
"documentationUrl": "https://github.com/FosterCommerce/entry-type-rules/blob/main/README.md",
"changelogUrl": "https://raw.githubusercontent.com/FosterCommerce/entry-type-rules/main/CHANGELOG.md"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"craftcms/generator": "^2.1",
"fostercommerce/rector": "dev-main",
Expand All @@ -59,10 +55,10 @@
"rector": "rector process --config rector.php",
"rector-dry-run": "rector process --dry-run --config rector.php"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
}
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
}
}
52 changes: 10 additions & 42 deletions src/EntryTypeRules.php → src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
use craft\base\Element;
use craft\base\Model;

use craft\base\Plugin;
use craft\base\Plugin as BasePlugin;
use craft\elements\Entry;
use craft\events\DefineHtmlEvent;
use craft\web\Controller;
use craft\web\View;
use fostercommerce\entrytyperules\assetbundles\entrytyperules\EntryTypeRulesAsset;
use fostercommerce\entrytyperules\models\Settings;
use fostercommerce\entrytyperules\services\EntryTypeRulesService as EntryTypeRulesServiceService;
use fostercommerce\entrytyperules\services\Service;
use yii\base\Event;
use yii\base\InvalidConfigException;

/**
* @property EntryTypeRulesServiceService $entryTypeRulesService
* @property Service $service
* @property Settings $settings
* @method Settings getSettings()
*/
class EntryTypeRules extends Plugin
class Plugin extends BasePlugin
{
public bool $hasCpSettings = true;

Expand All @@ -32,8 +33,10 @@ public function init(): void
{
parent::init();

Craft::setAlias('@plugin', $this->getBasePath());
//
$this->setComponents([
'service' => Service::class,
]);

Event::on(
Element::class,
Element::EVENT_DEFINE_SIDEBAR_HTML,
Expand All @@ -57,48 +60,13 @@ function (DefineHtmlEvent $event): void {
}
}
);

/**
* Logging in Craft involves using one of the following methods:
*
* Craft::trace(): record a message to trace how a piece of code runs. This is mainly for development use.
* Craft::info(): record a message that conveys some useful information.
* Craft::warning(): record a warning message that indicates something unexpected has happened.
* Craft::error(): record a fatal error that should be investigated as soon as possible.
*
* Unless `devMode` is on, only Craft::warning() & Craft::error() will log to `craft/storage/logs/web.log`
*
* It's recommended that you pass in the magic constant `__METHOD__` as the second parameter, which sets
* the category to the method (prefixed with the fully qualified class name) where the constant appears.
*
* To enable the Yii debug toolbar, go to your user account in the AdminCP and check the
* [] Show the debug toolbar on the front end & [] Show the debug toolbar on the Control Panel
*
* http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html
*/
Craft::info(
Craft::t(
'entry-type-rules',
'{name} plugin loaded',
[
'name' => $this->name,
]
),
__METHOD__
);
}

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

/** @var \craft\web\Controller $controller */
/** @var Controller $controller */
$controller = Craft::$app->controller;
return $controller->renderTemplate(
'entry-type-rules/settings',
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use craft\web\Application;
use craft\web\Controller;
use craft\web\User;
use fostercommerce\entrytyperules\EntryTypeRules;
use fostercommerce\entrytyperules\Plugin;

/**
* Default Controller
Expand Down Expand Up @@ -75,8 +75,8 @@ public function actionIndex(): mixed
/** @var User $user */
$user = Craft::$app->getUser();

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

Expand Down
7 changes: 3 additions & 4 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use craft\errors\MissingComponentException;
use craft\web\Controller;
use craft\web\Request;
use fostercommerce\entrytyperules\EntryTypeRules;
use fostercommerce\entrytyperules\models\Settings;
use fostercommerce\shipstationconnect\Plugin;
use fostercommerce\entrytyperules\Plugin;
use yii\base\InvalidConfigException;
use yii\web\BadRequestHttpException;
use yii\web\MethodNotAllowedHttpException;
Expand All @@ -35,8 +34,8 @@ public function actionSaveSettings(): Response
/** @var Request $request */
$request = Craft::$app->getRequest();

/** @var EntryTypeRules $plugin */
$plugin = EntryTypeRules::getInstance();
/** @var Plugin $plugin */
$plugin = Plugin::getInstance();

$settings = new Settings([
'sections' => $request->getBodyParam('sections'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use craft\base\Component;
use craft\elements\Entry;
use craft\web\User;
use fostercommerce\entrytyperules\EntryTypeRules;
use fostercommerce\entrytyperules\models\Settings;
use fostercommerce\entrytyperules\Plugin;

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

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

// Get all the entry types for this section into an array
$sectionEntryTypes = Craft::$app->getEntries()->getEntryTypesBySectionId($sectionId);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/ExampleUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Codeception\Test\Unit;
use UnitTester;
use Craft;
use fostercommerce\entrytyperules\EntryTypeRules;
use fostercommerce\entrytyperules\Plugin;

/**
* ExampleUnitTest
Expand Down Expand Up @@ -46,8 +46,8 @@ class ExampleUnitTest extends Unit
public function testPluginInstance()
{
$this->assertInstanceOf(
EntryTypeRules::class,
EntryTypeRules::$plugin
Plugin::class,
Plugin::$plugin
);
}

Expand Down

0 comments on commit 8bdbc32

Please sign in to comment.