Skip to content

Commit 0ee5f48

Browse files
committed
ElementArguments::EVENT_DEFINE_ARGUMENTS
Resolves #18062
1 parent 6560a70 commit 0ee5f48

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

CHANGELOG-WIP.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
- Added `craft\elements\User::isInGroups()`. ([#17989](https://github.com/craftcms/cms/discussions/17989))
5959
- Added `craft\elements\conditions\HintableConditionRuleTrait`. ([#17909](https://github.com/craftcms/cms/pull/17909))
6060
- Added `craft\events\DefineFieldActionsEvent`.
61+
- Added `craft\events\DefineGqlArgumentsEvent`.
6162
- Added `craft\events\RegisterElementCardAttributesEvent::$fieldLayout`. ([#17920](https://github.com/craftcms/cms/pull/17920))
6263
- Added `craft\fieldlayoutelements\BaseField::EVENT_DEFINE_ACTION_MENU_ITEMS`. ([#18037](https://github.com/craftcms/cms/issues/18037))
6364
- Added `craft\fields\BaseRelationField::VIEW_MODE_CARDS_GRID`.
@@ -66,6 +67,7 @@
6667
- Added `craft\fields\BaseRelationField::VIEW_MODE_LIST`.
6768
- Added `craft\fields\BaseRelationField::VIEW_MODE_THUMBS`.
6869
- Added `craft\fields\Matrix::VIEW_MODE_CARDS_GRID`.
70+
- Added `craft\gql\base\ElementArguments::EVENT_DEFINE_ARGUMENTS`. ([#18062](https://github.com/craftcms/cms/discussions/18062))
6971
- Added `craft\helpers\ElementHelper::loadProvisionalChanges()`. ([#17915](https://github.com/craftcms/cms/pull/17915))
7072
- Added `craft\models\EntryType::$uiLabelFormat`.
7173
- Added `craft\services\ElementSources::getFirstPage()`. ([#17779](https://github.com/craftcms/cms/pull/17779))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* @link https://craftcms.com/
4+
* @copyright Copyright (c) Pixel & Tonic, Inc.
5+
* @license https://craftcms.github.io/license/
6+
*/
7+
8+
namespace craft\events;
9+
10+
use craft\base\Event;
11+
12+
/**
13+
* DefineGqlArgumentsEvent class.
14+
*
15+
* @author Pixel & Tonic, Inc. <[email protected]>
16+
* @since 5.9.0
17+
*/
18+
class DefineGqlArgumentsEvent extends Event
19+
{
20+
/**
21+
* @var array<array|object> List of arguments
22+
*/
23+
public array $arguments = [];
24+
}

src/gql/base/ElementArguments.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace craft\gql\base;
99

10+
use craft\base\Event;
11+
use craft\events\DefineGqlArgumentsEvent;
1012
use craft\gql\GqlEntityRegistry;
1113
use craft\gql\types\input\criteria\AssetRelation;
1214
use craft\gql\types\input\criteria\CategoryRelation;
@@ -26,12 +28,18 @@
2628
*/
2729
abstract class ElementArguments extends Arguments
2830
{
31+
/**
32+
* @event DefineGqlArgumentsEvent The event that is triggered when arguments are being defined.
33+
* @since 5.9.0
34+
*/
35+
public const EVENT_DEFINE_ARGUMENTS = 'defineArguments';
36+
2937
/**
3038
* @inheritdoc
3139
*/
3240
public static function getArguments(): array
3341
{
34-
return array_merge(parent::getArguments(), static::getDraftArguments(), static::getRevisionArguments(), static::getStatusArguments(), [
42+
$arguments = array_merge(parent::getArguments(), static::getDraftArguments(), static::getRevisionArguments(), static::getStatusArguments(), [
3543
'site' => [
3644
'name' => 'site',
3745
'type' => Type::listOf(Type::string()),
@@ -193,6 +201,14 @@ public static function getArguments(): array
193201
'description' => 'Narrows the query results based on the unique identifier for an element-site relation.',
194202
],
195203
]);
204+
205+
if (Event::hasHandlers(self::class, self::EVENT_DEFINE_ARGUMENTS)) {
206+
$event = new DefineGqlArgumentsEvent(compact('arguments'));
207+
Event::trigger(self::class, self::EVENT_DEFINE_ARGUMENTS, $event);
208+
return $event->arguments;
209+
}
210+
211+
return $arguments;
196212
}
197213

198214
/**

0 commit comments

Comments
 (0)