Skip to content

Commit

Permalink
v4 bby
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Apr 20, 2023
1 parent 248a5aa commit c4b7616
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 47 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "ether/utility-belt",
"description": "A collection of things we use on every Craft CMS site",
"version": "0.0.6",
"type": "craft-plugin",
"license": "GPL-3.0-or-later",
"minimum-stability": "dev",
"require": {
"craftcms/cms": "^3.7",
"craftcms/cms": "^4",
"ether/logs": "*"
},
"autoload": {
Expand Down
18 changes: 9 additions & 9 deletions src/UtilityBelt.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class UtilityBelt extends Plugin
{

public function init ()
public function init (): void
{
$this->setComponents([
'livePreview' => LivePreview::class,
Expand Down Expand Up @@ -95,21 +95,21 @@ public function init ()
// Events
// =========================================================================

public function onAfterUninstallPlugin (PluginEvent $event)
public function onAfterUninstallPlugin (PluginEvent $event): void
{
if ($event->plugin->getHandle() !== $this->getHandle()) return;

Craft::$app->getPlugins()->uninstallPlugin('logs');
}

public function onAfterInstallPlugin (PluginEvent $event)
public function onAfterInstallPlugin (PluginEvent $event): void
{
if ($event->plugin->getHandle() !== $this->getHandle()) return;

Craft::$app->getPlugins()->installPlugin('logs');
}

public function onAfterExecuteGqlQuery (ExecuteGqlQueryEvent $event)
public function onAfterExecuteGqlQuery (ExecuteGqlQueryEvent $event): void
{
// Make absolute internal URLs relative
$res = Json::encode($event->result);
Expand All @@ -121,7 +121,7 @@ public function onAfterExecuteGqlQuery (ExecuteGqlQueryEvent $event)
$event->result = Json::decode($res);
}

public function onDefineGqlTypeFields (DefineGqlTypeFieldsEvent $event)
public function onDefineGqlTypeFields (DefineGqlTypeFieldsEvent $event): void
{
if ($event->typeName === 'AssetInterface')
{
Expand All @@ -141,17 +141,17 @@ public function onDefineGqlTypeFields (DefineGqlTypeFieldsEvent $event)
}
}

public function onRegisterWidgetTypes (RegisterComponentTypesEvent $event)
public function onRegisterWidgetTypes (RegisterComponentTypesEvent $event): void
{
$event->types[] = TwigWidget::class;
}

public function onRegisterFieldTypes (RegisterComponentTypesEvent $event)
public function onRegisterFieldTypes (RegisterComponentTypesEvent $event): void
{
$event->types[] = LinkField::class;
}

public function onAfterElementSave (ModelEvent $event)
public function onAfterElementSave (ModelEvent $event): void
{
/** @var Element $element */
$element = $event->sender;
Expand All @@ -164,4 +164,4 @@ public function onAfterElementSave (ModelEvent $event)
]));
}

}
}
12 changes: 5 additions & 7 deletions src/fields/LinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function beforeElementSave (ElementInterface $element, bool $isNew): bool
return parent::beforeElementSave($element, $isNew);
}

public function afterElementSave (ElementInterface $element, bool $isNew)
public function afterElementSave (ElementInterface $element, bool $isNew): void
{
parent::afterElementSave($element, $isNew);

Expand Down Expand Up @@ -236,12 +236,10 @@ public function afterElementSave (ElementInterface $element, bool $isNew)
->execute();
}

public function beforeApplyDelete (): bool
public function beforeApplyDelete (): void
{
parent::beforeApplyDelete();
$this->_dropDbMeta();

return true;
}

public function afterSave (bool $isNew): void
Expand All @@ -260,7 +258,7 @@ public function afterSave (bool $isNew): void
// Helpers
// =========================================================================

public function precacheForElement (ElementInterface $source, ElementInterface $target)
public function precacheForElement (ElementInterface $source, ElementInterface $target): void
{
$elements = Craft::$app->getElements();

Expand Down Expand Up @@ -396,7 +394,7 @@ private function _getContentTable (): ?array
return null;
}

private function _dropDbMeta ()
private function _dropDbMeta (): void
{
$tbl = $this->_getContentTable();
if (empty($tbl)) return;
Expand All @@ -418,7 +416,7 @@ private function _dropDbMeta ()
->execute();
}

private function _addDbMeta ()
private function _addDbMeta (): void
{
$tbl = $this->_getContentTable();
if (empty($tbl)) return;
Expand Down
6 changes: 3 additions & 3 deletions src/jobs/RegenerateLinkCacheJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class RegenerateLinkCacheJob extends BaseJob
public string $elementType;
public int $targetId;

public $description = 'Regenerating Link Cache';
public ?string $description = 'Regenerating Link Cache';

public function execute ($queue)
public function execute ($queue): void
{
$target = $this->elementType::findOne(['id' => $this->targetId]);
$fieldsService = Craft::$app->getFields();
Expand Down Expand Up @@ -65,4 +65,4 @@ public function execute ($queue)
}
}

}
}
9 changes: 4 additions & 5 deletions src/jobs/RevalidateJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ protected function defaultDescription (): string
return 'Revalidating Front-end';
}

public function execute ($queue): bool
public function execute ($queue): void
{
// Skip if localhost
// if (str_contains(getenv('FRONTEND_URL'), 'local'))
// return true;
$frontendUrl = getenv('FRONTEND_URL');
if (empty($frontendUrl) || str_contains($frontendUrl, 'local'))
return;

$this->uris = array_unique($this->uris);

Expand Down Expand Up @@ -62,8 +63,6 @@ public function execute ($queue): bool
}
}
}

return true;
}

}
4 changes: 2 additions & 2 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Install extends Migration
{

public function safeUp ()
public function safeUp (): void
{
// Revalidator
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -49,4 +49,4 @@ public function safeDown (): bool
return true;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class m220406_093529_create_link_element_table extends Migration
/**
* @inheritdoc
*/
public function safeUp()
public function safeUp(): void
{
$this->createTable(LinkField::TABLE, [
'fieldId' => $this->integer(11),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class m220407_102710_add_urlSuffix_column_to_content extends Migration
/**
* @inheritdoc
*/
public function safeUp()
public function safeUp(): void
{
$fieldsService = Craft::$app->getFields();
$fieldIds = (new Query())
Expand Down
6 changes: 3 additions & 3 deletions src/services/LivePreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class LivePreview extends Component
{

public function init ()
public function init (): void
{
parent::init();

Expand Down Expand Up @@ -50,7 +50,7 @@ public function init ()
}
}

public function onSectionInit (Event $event)
public function onSectionInit (Event $event): void
{
/** @var Section $section */
$section = $event->sender;
Expand All @@ -64,4 +64,4 @@ public function onSectionInit (Event $event)
];
}

}
}
18 changes: 9 additions & 9 deletions src/services/Revalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Revalidator extends Component

public static $tableName = '{{%b_revalidate_jobs}}';

public function init ()
public function init (): void
{
parent::init();

Expand All @@ -54,7 +54,7 @@ public function init ()
);
}

public function onAfterElementSave (ModelEvent $event)
public function onAfterElementSave (ModelEvent $event): void
{
/** @var Element $element */
$element = $event->sender;
Expand All @@ -65,12 +65,12 @@ public function onAfterElementSave (ModelEvent $event)
$this->push($element);
}

public function onAfterRenderTemplate (TemplateEvent $event)
public function onAfterRenderTemplate (TemplateEvent $event): void
{
$this->injectAdditionalUrisTable($event);
}

public function onAfterSectionSave (SectionEvent $event)
public function onAfterSectionSave (SectionEvent $event): void
{
if (!empty($event->section))
$this->saveAdditionalURIs($event->section->uid);
Expand All @@ -84,7 +84,7 @@ public function onAfterSectionSave (SectionEvent $event)
* @return void
* @throws SiteNotFoundException|TemplateLoaderException
*/
public function injectAdditionalUrisTable (TemplateEvent $event)
public function injectAdditionalUrisTable (TemplateEvent $event): void
{
if ($event->template !== 'settings/sections/_edit')
return;
Expand Down Expand Up @@ -157,7 +157,7 @@ public function getAdditionalURIs (string $sectionUid, bool $asRows = false): ar
* @throws InvalidConfigException
* @throws NotSupportedException
*/
public function saveAdditionalURIs (string $sectionUid)
public function saveAdditionalURIs (string $sectionUid): void
{
$request = Craft::$app->getRequest();

Expand Down Expand Up @@ -188,7 +188,7 @@ public function saveAdditionalURIs (string $sectionUid)
* @return void
* @throws Exception|\yii\base\Exception
*/
public function push (Element $element)
public function push (Element $element): void
{
/** @var RevalidateJob $job */
[$id, $job] = $this->getJob();
Expand Down Expand Up @@ -248,7 +248,7 @@ private function getJob (): ?array
* @return void
* @throws Exception
*/
private function storeJobId (int $id)
private function storeJobId (int $id): void
{
Craft::$app->getDb()->createCommand()
->insert(self::$tableName, ['jobId' => $id], false)
Expand All @@ -264,7 +264,7 @@ private function storeJobId (int $id)
* @return void
* @throws Exception
*/
private function updateJob (int $id, RevalidateJob $job)
private function updateJob (int $id, RevalidateJob $job): void
{
$job = Craft::$app->getQueue()->serializer->serialize($job);

Expand Down
4 changes: 2 additions & 2 deletions src/web/assets/link/LinkFieldAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class LinkFieldAsset extends AssetBundle
{

public function init ()
public function init (): void
{
$this->sourcePath = __DIR__;

Expand All @@ -17,4 +17,4 @@ public function init ()
parent::init();
}

}
}
6 changes: 3 additions & 3 deletions src/widgets/TwigWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function displayName (): string
return 'Twig';
}

public function getSettingsHtml ()
public function getSettingsHtml (): ?string
{
return Craft::$app->getView()->renderTemplate(
'utility-belt/widgets/twig-settings',
Expand All @@ -30,7 +30,7 @@ public function getTitle (): string
return $this->title ?? parent::getTitle();
}

public function getBodyHtml ()
public function getBodyHtml (): ?string
{
if (empty($this->template))
return '';
Expand All @@ -44,4 +44,4 @@ public function getBodyHtml ()
return $markup;
}

}
}

0 comments on commit c4b7616

Please sign in to comment.