Skip to content

Commit

Permalink
Partial Craft 5 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed May 1, 2024
1 parent dbe85f4 commit 74127f9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"license": "GPL-3.0-or-later",
"minimum-stability": "dev",
"require": {
"craftcms/cms": "^4",
"ether/logs": "*",
"craftcms/cms": "^5",
"ether/seo": "*"
},
"autoload": {
Expand Down
28 changes: 13 additions & 15 deletions src/UtilityBelt.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,28 @@ public function onAfterUninstallPlugin (PluginEvent $event): void
try {
$fields = Craft::$app->getFields();
$fields->deleteFieldById($fields->getFieldByHandle('seo')->id);
$fields->deleteGroupById(FieldGroup::findOne(['name' => '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);
// $group = new \craft\models\FieldGroup(['name' => 'SEO']);
// $fields->saveGroup($group);

$seoField = $fields->createField([
'type' => SeoField::class,
'name' => 'SEO',
'handle' => 'seo',
'groupId' => $group->id,
// 'groupId' => $group->id,
]);
$fields->saveField($seoField);
}
Expand Down Expand Up @@ -171,20 +169,20 @@ public function onRegisterWidgetTypes (RegisterComponentTypesEvent $event): void

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

public function onAfterElementSave (ModelEvent $event): void
{
/** @var Element $element */
$element = $event->sender;

if (ElementHelper::isDraftOrRevision($element)) return;

Craft::$app->getQueue()->push(new RegenerateLinkCacheJob([
'elementType' => $element::class,
'targetId' => $element->id,
]));
// $element = $event->sender;
//
// if (ElementHelper::isDraftOrRevision($element)) return;
//
// Craft::$app->getQueue()->push(new RegenerateLinkCacheJob([
// 'elementType' => $element::class,
// 'targetId' => $element->id,
// ]));
}

}
6 changes: 3 additions & 3 deletions src/fields/LinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function isValueEmpty ($value, ElementInterface $element): bool
return (bool) $value?->isEmpty();
}

protected function inputHtml ($value, ElementInterface $element = null): string
protected function inputHtml ($value, ?ElementInterface $element, bool $inline): string
{
$view = Craft::$app->getView();
$view->registerAssetBundle(LinkFieldAsset::class, View::POS_END);
Expand Down Expand Up @@ -329,7 +329,7 @@ public function getColumnName (string $handle, string $fieldHandle, string $pref
{
return join('_', array_filter([
'field',
$this->columnPrefix,
// $this->columnPrefix,
$prefix,
$fieldHandle,
$handle,
Expand All @@ -345,7 +345,7 @@ private function _getElementIdColumnName (string $handle, string $prefix = null)
private function _getContentTable (): ?array
{
if ($this->context === 'global')
return [Table::CONTENT, null];
return [Table::ELEMENTS_SITES, null];

if (str_starts_with($this->context, 'matrixBlockType'))
{
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/RevalidateJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function execute ($queue): void

if (!empty($this->sectionUid))
{
$section = Craft::$app->getSections()->getSectionByUid($this->sectionUid);
$section = Craft::$app->getEntries()->getSectionByUid($this->sectionUid);
$entriesInSection = Entry::find()->sectionId($section->id)->count();

$urisWithTemplates = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/services/LivePreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function onSectionInit (Event $event): void
$section->previewTargets = [
[
'label' => 'Preview',
'urlFormat' => '{{ getenv(\'FRONTEND_URL\') }}/api/preview?uid={canonicalUid}&x-craft-live-preview=1&site={site.handle}',
'urlFormat' => '{site.baseUrl}/api/preview?uid={canonicalUid}&x-craft-live-preview=1&site={site.handle}',
'refresh' => true,
]
];
Expand Down
12 changes: 6 additions & 6 deletions src/services/Revalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use craft\events\TemplateEvent;
use craft\helpers\Cp;
use craft\helpers\ElementHelper;
use craft\services\Sections;
use craft\services\Entries;
use craft\web\twig\TemplateLoaderException;
use craft\web\View;
use ether\utilitybelt\jobs\RevalidateAssetJob;
Expand Down Expand Up @@ -52,8 +52,8 @@ public function init (): void
);

Event::on(
Sections::class,
Sections::EVENT_BEFORE_SAVE_SECTION,
Entries::class,
Entries::EVENT_BEFORE_SAVE_SECTION,
[$this, 'onBeforeSectionSave']
);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public function injectAdditionalUrisTable (TemplateEvent $event): void
'siteId' => Craft::$app->getSites()->getCurrentSite()->id,
]);
} else {
$sectionUid = Craft::$app->getSections()->getSectionById($sectionId)->uid;
$sectionUid = Craft::$app->getEntries()->getSectionById($sectionId)->uid;
$markup = Cp::editableTableFieldHtml([
'label' => 'Additional Revalidate URIs',
'instructions' => 'Any additional URIs that need to be revalidated when this entry changes (i.e. indexes)',
Expand Down Expand Up @@ -282,9 +282,9 @@ private function push (Element $element): array

if (!empty($uri)) $uris[] = $uri;

if ($element instanceof Entry)
if ($element instanceof Entry && $element->sectionId)
{
$sectionUid = Craft::$app->getSections()->getSectionById($element->sectionId)->uid;
$sectionUid = Craft::$app->getEntries()->getSectionById($element->sectionId)->uid;

foreach ($this->getAdditionalURIs($sectionUid) as $uri)
$uris[] = $uri;
Expand Down

0 comments on commit 74127f9

Please sign in to comment.