Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added entrify event #13391

Open
wants to merge 4 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/console/controllers/EntrifyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use craft\elements\Entry;
use craft\elements\Tag;
use craft\elements\User;
use craft\events\EntrifyCategoriesEvent;
use craft\events\EntrifyGlobalSetEvent;
use craft\events\EntrifyTagsEvent;
use craft\events\SectionEvent;
use craft\fields\Categories;
use craft\fields\Entries;
Expand All @@ -39,6 +42,12 @@
*/
class EntrifyController extends Controller
{
// Events
// -------------------------------------------------------------------------
public const EVENT_ENTRIFY_CATEGORIES = 'onEntrifyCategories';
public const EVENT_ENTRIFY_TAGS = 'onEntrifyTags';
public const EVENT_ENTRIFY_GLOBAL_SET = 'onEntrifyGlobalSet';

/**
* @var string|null The section handle that entries should be saved in
*/
Expand Down Expand Up @@ -244,6 +253,7 @@ public function actionCategories(string $categoryGroup): int
"deletePeerCategoryDrafts:$categoryGroup->uid" => "deletePeerEntryDrafts:$section->uid",
], $sectionCreated);

$fieldsConverted = false;
if (!$projectConfigService->readOnly) {
if (!$categoryGroup->dateDeleted && $this->confirm("Delete the “{$categoryGroup}” category group?", true)) {
$this->do('Deleting category group', function() use ($categoryGroup) {
Expand Down Expand Up @@ -278,6 +288,7 @@ public function actionCategories(string $categoryGroup): int

$this->success(sprintf('Categories %s converted.', $total === 1 ? 'field' : 'fields'));
$projectConfigChanged = true;
$fieldsConverted = true;
}
}
}
Expand All @@ -286,6 +297,19 @@ public function actionCategories(string $categoryGroup): int
$this->_deployTip('categories', $categoryGroup->handle);
}

// Fire a 'onEntrifyCategories' event
if ($this->hasEventHandlers(self::EVENT_ENTRIFY_CATEGORIES)) {
$event = new EntrifyCategoriesEvent([
'categoryGroup' => $categoryGroup,
'section' => $section,
'entryType' => $entryType,
'fieldsConverted' => $fieldsConverted,
'fields' => $fields ?? null,
]);

$this->trigger(self::EVENT_ENTRIFY_CATEGORIES, $event);
}

return ExitCode::OK;
}

Expand Down Expand Up @@ -384,6 +408,7 @@ public function actionTags(string $tagGroup): int

$this->success('Tags converted.');

$fieldsConverted = false;
if (!$projectConfigService->readOnly) {
if (!$tagGroup->dateDeleted && $this->confirm("Delete the “{$tagGroup}” tag group?", true)) {
$this->do('Deleting tag group', function() use ($tagGroup) {
Expand Down Expand Up @@ -417,6 +442,7 @@ public function actionTags(string $tagGroup): int

$this->success(sprintf('Tags %s converted.', $total === 1 ? 'field' : 'fields'));
$projectConfigChanged = true;
$fieldsConverted = true;
}
}
}
Expand All @@ -425,6 +451,19 @@ public function actionTags(string $tagGroup): int
$this->_deployTip('tags', $tagGroup->handle);
}

// Fire a 'onEntrifyTags' event
if ($this->hasEventHandlers(self::EVENT_ENTRIFY_TAGS)) {
$event = new EntrifyTagsEvent([
'tagGroup' => $tagGroup,
'section' => $section,
'entryType' => $entryType,
'fieldsConverted' => $fieldsConverted,
'fields' => $fields ?? null,
]);

$this->trigger(self::EVENT_ENTRIFY_TAGS, $event);
}

return ExitCode::OK;
}

Expand Down Expand Up @@ -539,6 +578,17 @@ public function actionGlobalSet(string $globalSet): int
$this->_deployTip('global-set', $globalSet->handle);
}

// Fire a 'onEntrifyTags' event
if ($this->hasEventHandlers(self::EVENT_ENTRIFY_GLOBAL_SET)) {
$event = new EntrifyGlobalSetEvent([
'globalSet' => $globalSet,
'section' => $section,
'entryType' => $entryType,
]);

$this->trigger(self::EVENT_ENTRIFY_GLOBAL_SET, $event);
}

return ExitCode::OK;
}

Expand Down
47 changes: 47 additions & 0 deletions src/events/EntrifyCategoriesEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\events;

use craft\models\CategoryGroup;
use craft\models\EntryType;
use craft\models\Section;
use yii\base\Event;

/**
* Entrify categories event class.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 4.4.16
*/
class EntrifyCategoriesEvent extends Event
{
/**
* @var CategoryGroup Category group being entrified
*/
public CategoryGroup $categoryGroup;

/**
* @var Section Section used for entrification
*/
public Section $section;

/**
* @var EntryType Entry type used for entrification
*/
public EntryType $entryType;

/**
* @var bool Whether fields were entrified
*/
public bool $fieldsConverted;

/**
* @var array The array of fields that were entrified
*/
public array $fields = [];
}
37 changes: 37 additions & 0 deletions src/events/EntrifyGlobalSetEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\events;

use craft\elements\GlobalSet;
use craft\models\EntryType;
use craft\models\Section;
use yii\base\Event;

/**
* Entrify global set event class.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 4.4.16
*/
class EntrifyGlobalSetEvent extends Event
{
/**
* @var GlobalSet Global set being entrified
*/
public GlobalSet $globalSet;

/**
* @var Section Section used for entrification
*/
public Section $section;

/**
* @var EntryType Entry type used for entrification
*/
public EntryType $entryType;
}
47 changes: 47 additions & 0 deletions src/events/EntrifyTagsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\events;

use craft\models\EntryType;
use craft\models\Section;
use craft\models\TagGroup;
use yii\base\Event;

/**
* Entrify tags event class.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 4.4.16
*/
class EntrifyTagsEvent extends Event
{
/**
* @var TagGroup Tag group being entrified
*/
public TagGroup $tagGroup;

/**
* @var Section Section used for entrification
*/
public Section $section;

/**
* @var EntryType Entry type used for entrification
*/
public EntryType $entryType;

/**
* @var bool Whether fields were entrified
*/
public bool $fieldsConverted;

/**
* @var array The array of fields that were entrified
*/
public array $fields = [];
}