-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathElementInterface.php
More file actions
1954 lines (1767 loc) · 63.4 KB
/
ElementInterface.php
File metadata and controls
1954 lines (1767 loc) · 63.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\base;
use craft\behaviors\CustomFieldBehavior;
use craft\elements\conditions\ElementConditionInterface;
use craft\elements\db\EagerLoadPlan;
use craft\elements\db\ElementQueryInterface;
use craft\elements\ElementCollection;
use craft\elements\User;
use craft\enums\AttributeStatus;
use craft\errors\InvalidFieldException;
use craft\models\FieldLayout;
use craft\models\Site;
use craft\web\twig\AllowedInSandbox;
use GraphQL\Type\Definition\Type;
use Twig\Markup;
use yii\base\InvalidConfigException;
use yii\base\NotSupportedException;
use yii\web\Response;
/**
* ElementInterface defines the common interface to be implemented by element classes.
* A class implementing this interface should also use [[ElementTrait]].
*
* @mixin ElementTrait
* @mixin CustomFieldBehavior
* @mixin Component
* @phpstan-require-extends Element
* @phpstan-type EagerLoadingMapItem array{elementType?:class-string<ElementInterface>,source:int,target:int}
* @phpstan-type EagerLoadingMap array{elementType?:class-string<ElementInterface>,map:EagerLoadingMapItem[],criteria?:array,createElement?:callable}
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 3.0.0
*/
#[AllowedInSandbox]
interface ElementInterface extends
ComponentInterface,
Chippable,
CpEditable,
Thumbable,
Statusable,
Actionable
{
/**
* Returns the lowercase version of [[displayName()]].
*
* @return string
* @since 3.3.17
*/
public static function lowerDisplayName(): string;
/**
* Returns the plural version of [[displayName()]].
*
* @return string
* @since 3.2.0
*/
public static function pluralDisplayName(): string;
/**
* Returns the plural, lowercase version of [[displayName()]].
*
* @return string
* @since 3.3.17
*/
public static function pluralLowerDisplayName(): string;
/**
* Returns the handle that should be used to refer to this element type from reference tags.
*
* @return string|null The reference handle, or null if the element type doesn’t support reference tags
*/
public static function refHandle(): ?string;
/**
* Returns whether element indexes should show the “Drafts” status option.
*
* @return bool
* @since 5.0.0
*/
public static function hasDrafts(): bool;
/**
* Returns whether Craft should keep track of attribute and custom field changes made to this element type,
* including when the last time they were changed, and who was logged-in at the time.
*
* @return bool Whether to track changes made to elements of this type.
* @see getDirtyAttributes()
* @see getDirtyFields()
* @since 3.4.0
*/
public static function trackChanges(): bool;
/**
* Returns whether elements of this type have traditional titles.
*
* @return bool Whether elements of this type have traditional titles.
*/
public static function hasTitles(): bool;
/**
* Returns whether element indexes should include a thumbnail view by default.
*
* @return bool
* @since 5.0.0
*/
public static function hasThumbs(): bool;
/**
* Returns whether elements of this type can have their own slugs and URIs.
*
* Note that individual elements must also return a URI format from [[getUriFormat()]] if they are to actually get a URI.
*
* @return bool Whether elements of this type can have their own slugs and URIs.
* @see getUriFormat()
*/
public static function hasUris(): bool;
/**
* Returns whether elements of this type store content on a per-site basis.
*
* If this returns `true`, the element’s [[getSupportedSites()]] method will
* be responsible for defining which sites its content should be stored in.
*
* @return bool Whether elements of this type store data on a per-site basis.
*/
public static function isLocalized(): bool;
/**
* Returns whether elements of this type have statuses.
*
* If this returns `true`, the element index template will show a Status menu by default, and your elements will
* get status indicator icons next to them.
* Use [[statuses()]] to customize which statuses the elements might have.
*
* @return bool Whether elements of this type have statuses.
* @see statuses()
*/
public static function hasStatuses(): bool;
/**
* Creates an [[ElementQueryInterface]] instance for query purpose.
*
* The returned [[ElementQueryInterface]] instance can be further customized by calling
* methods defined in [[ElementQueryInterface]] before `one()` or `all()` is called to return
* populated [[ElementInterface]] instances. For example,
*
* ```php
* // Find the entry whose ID is 5
* $entry = Entry::find()->id(5)->one();
* // Find all assets and order them by their filename:
* $assets = Asset::find()
* ->orderBy('filename')
* ->all();
* ```
*
* If you want to define custom criteria parameters for your elements, you can do so by overriding
* this method and returning a custom query class. For example,
*
* ```php
* class Product extends Element
* {
* public static function find(): ElementQueryInterface
* {
* // use ProductQuery instead of the default ElementQuery
* return new ProductQuery(get_called_class());
* }
* }
* ```
*
* You can also set default criteria parameters on the ElementQuery if you don’t have a need for
* a custom query class. For example,
*
* ```php
* class Customer extends ActiveRecord
* {
* public static function find(): ElementQueryInterface
* {
* return parent::find()->limit(50);
* }
* }
* ```
*
* @return ElementQueryInterface The newly created [[ElementQueryInterface]] instance.
*/
public static function find(): ElementQueryInterface;
/**
* Returns a single element instance by a primary key or a set of element criteria parameters.
*
* The method accepts:
*
* - an int: query by a single ID value and return the corresponding element (or null if not found).
* - an array of name-value pairs: query by a set of parameter values and return the first element
* matching all of them (or null if not found).
*
* Note that this method will automatically call the `one()` method and return an
* [[ElementInterface|\craft\base\Element]] instance. For example,
*
* ```php
* // find a single entry whose ID is 10
* $entry = Entry::findOne(10);
* // the above code is equivalent to:
* $entry = Entry::find->id(10)->one();
* // find the first user whose email ends in "example.com"
* $user = User::findOne(['email' => '*example.com']);
* // the above code is equivalent to:
* $user = User::find()->email('*example.com')->one();
* ```
*
* @param mixed $criteria The element ID or a set of element criteria parameters
* @return static|null Element instance matching the condition, or null if nothing matches.
*/
public static function findOne(mixed $criteria = null): ?static;
/**
* Returns a list of elements that match the specified ID(s) or a set of element criteria parameters.
*
* The method accepts:
*
* - an int: query by a single ID value and return an array containing the corresponding element
* (or an empty array if not found).
* - an array of integers: query by a list of ID values and return the corresponding elements (or an
* empty array if none was found).
* Note that an empty array will result in an empty result as it will be interpreted as a search for
* primary keys and not an empty set of element criteria parameters.
* - an array of name-value pairs: query by a set of parameter values and return an array of elements
* matching all of them (or an empty array if none was found).
*
* Note that this method will automatically call the `all()` method and return an array of
* [[ElementInterface|\craft\base\Element]] instances. For example,
*
* ```php
* // find the entries whose ID is 10
* $entries = Entry::findAll(10);
* // the above code is equivalent to:
* $entries = Entry::find()->id(10)->all();
* // find the entries whose ID is 10, 11 or 12.
* $entries = Entry::findAll([10, 11, 12]);
* // the above code is equivalent to:
* $entries = Entry::find()->id([10, 11, 12]])->all();
* // find users whose email ends in "example.com"
* $users = User::findAll(['email' => '*example.com']);
* // the above code is equivalent to:
* $users = User::find()->email('*example.com')->all();
* ```
*
* @param mixed $criteria The element ID, an array of IDs, or a set of element criteria parameters
* @return static[] an array of Element instances, or an empty array if nothing matches.
*/
public static function findAll(mixed $criteria = null): array;
/**
* Returns an element condition for the element type.
*
* @return ElementConditionInterface
* @since 4.0.0
*/
public static function createCondition(): ElementConditionInterface;
/**
* Returns whether the element type’s sources can be split into multiple pages.
*
* @return bool
* @since 5.9.0
*/
public static function multiPageSources(): bool;
/**
* Returns the source definitions that elements of this type may belong to.
*
* This defines what will show up in the source list on element indexes and element selector modals.
*
* Each item in the array should be set to an array that has the following keys:
* - **`page`** – The source’s page label. (Optional)
* - **`key`** – The source’s key. This is the string that will be passed into the $source argument of [[actions()]],
* [[indexHtml()]], and [[defaultTableAttributes()]].
* - **`label`** – The human-facing label of the source.
* - **`status`** – The status color that should be shown beside the source label. Possible values include `green`,
* `orange`, `red`, `yellow`, `pink`, `purple`, `blue`, `turquoise`, `light`, `grey`, `black`, and `white`. (Optional)
* - **`badgeCount`** – The badge count that should be displayed alongside the label. (Optional)
* - **`badgeLabel`** – The badge count label that should be provided for screen readers. (Optional)
* - **`sites`** – An array of site IDs or UUIDs that the source should be shown for, on multi-site element indexes.
* (Optional; by default the source will be shown for all sites.)
* - **`criteria`** – An array of element criteria parameters that the source should use when the source is selected.
* (Optional)
* - **`data`** – An array of `data-X` attributes that should be set on the source’s `<a>` tag in the source list’s,
* HTML, where each key is the name of the attribute (without the “data-” prefix), and each value is the value of
* the attribute. (Optional)
* - **`defaultSort`** – A string identifying the sort attribute that should be selected by default, or an array where
* the first value identifies the sort attribute, and the second determines which direction to sort by. (Optional)
* - **`defaultFilter`** – An element condition instance or config, which should be used by default when the source
* is first selected.
* - **`hasThumbs`** – A bool that defines whether this source supports Thumbs View. (Use your element’s
* [[getThumbUrl()]] method to define your elements’ thumb URL.) (Optional)
* - **`structureId`** – The ID of the Structure that contains the elements in this source. If set, Structure View
* will be available to this source. (Optional)
* - **`newChildUrl`** – The URL that should be loaded when a user selects the “New child” menu option on an
* element in this source while it is in Structure View. (Optional)
* - **`nested`** – An array of sources that are nested within this one. Each nested source can have the same keys
* as top-level sources.
*
* ::: tip
* Element types that extend [[\craft\base\Element]] should override [[\craft\base\Element::defineSources()]]
* instead of this method.
* :::
*
* @param string $context The context ('index', 'modal', 'field', or 'settings').
* @return array The sources.
*/
public static function sources(string $context): array;
/**
* Returns a source definition by a given source key/path and context.
*
* @param string $sourceKey
* @param string|null $context
* @return array|null
* @since 4.4.0
*/
public static function findSource(string $sourceKey, ?string $context): ?array;
/**
* Returns the source path for a given source key, step key, and context.
*
* @param string $sourceKey
* @param string $stepKey
* @param string|null $context
* @return array[]|null
* @since 4.4.12
*/
public static function sourcePath(string $sourceKey, string $stepKey, ?string $context): ?array;
/**
* Returns all the field layouts associated with elements from the given source.
*
* This is used to determine which custom fields should be included in the element index sort menu,
* and other things.
*
* @param string|null $source The selected source’s key, or `null` if all known field layouts should be returned
* @return FieldLayout[]
* @since 3.5.0
*/
public static function fieldLayouts(?string $source): array;
/**
* Modifies a custom source’s config, before it’s returned by [[craft\services\ElementSources::getSources()]]
*
* @param array $config
* @return array
* @since 4.5.0
*/
public static function modifyCustomSource(array $config): array;
/**
* Returns the available [bulk element actions](https://craftcms.com/docs/5.x/extend/element-actions.html)
* for a given source.
*
* The actions can be represented by their fully qualified class name, a config array with the class name
* set to a `type` key, or by an instantiated element action object.
*
* ::: tip
* Element types that extend [[\craft\base\Element]] should override [[\craft\base\Element::defineActions()]]
* instead of this method.
* :::
*
* @param string $source The selected source’s key.
* @return array The available bulk element actions.
* @phpstan-return array<ElementActionInterface|class-string<ElementActionInterface>|array{type:class-string<ElementActionInterface>}>
*/
public static function actions(string $source): array;
/**
* Returns the available export options for a given source.
*
* The exporters can be represented by their fully qualified class name, a config array with the class name
* set to a `type` key, or by an instantiated element exporter object.
*
* ::: tip
* Element types that extend [[\craft\base\Element]] should override [[\craft\base\Element::defineExporters()]]
* instead of this method.
* :::
*
* @param string $source The selected source’s key.
* @return array The available element exporters.
* @since 3.4.0
*/
public static function exporters(string $source): array;
/**
* Defines which element attributes should be searchable.
*
* This method should return an array of attribute names that can be accessed on your elements.
* [[\craft\services\Search]] will call this method when it is indexing keywords for one of your elements,
* and for each attribute it returns, it will fetch the corresponding property’s value on the element.
* For example, if your elements have a “color” attribute which you want to be indexed, this method could return:
*
* ```php
* return ['color'];
* ```
*
* Not only will the “color” attribute’s values start getting indexed, but users will also be able to search
* directly against that attribute’s values using this search syntax:
*
* color:blue
*
* There is no need for this method to worry about the ‘title’ or ‘slug’ attributes, or custom field handles;
* those are indexed automatically.
*
* ::: tip
* Element types that extend [[\craft\base\Element]] should override
* [[\craft\base\Element::defineSearchableAttributes()]] instead of this method.
* :::
*
* @return string[] The element attributes that should be searchable
*/
public static function searchableAttributes(): array;
/**
* Returns the base attributes that should be applied when bulk-duplicating elements of this type.
*
* @return array
* @since 5.7.0
*/
public static function baseBulkDuplicateAttributes(): array;
/**
* Returns the element index HTML.
*
* @param ElementQueryInterface $elementQuery
* @param int[]|null $disabledElementIds
* @param array $viewState
* @param string|null $sourceKey
* @param string|null $context
* @param bool $includeContainer
* @param bool $selectable
* @param bool $sortable
* @return string The element index HTML
*/
public static function indexHtml(
ElementQueryInterface $elementQuery,
?array $disabledElementIds,
array $viewState,
?string $sourceKey,
?string $context,
bool $includeContainer,
bool $selectable,
bool $sortable,
): string;
/**
* Returns the total number of elements that will be shown on an element index, for the given element query.
*
* @param ElementQueryInterface $elementQuery
* @param string|null $sourceKey
* @return int
* @since 4.4.0
*/
public static function indexElementCount(ElementQueryInterface $elementQuery, ?string $sourceKey): int;
/**
* Returns the sort options for the element type.
*
* This method should return an array, where each item is a sub-array with the following keys:
*
* - `label` – The sort option label
* - `orderBy` – An array, comma-delimited string, or a callback function that defines the columns to order the query by. If set to a callback
* function, the function will be passed two arguments: `$dir` (either `SORT_ASC` or `SORT_DESC`) and `$db` (a [[\craft\db\Connection]] object),
* and it should return an array of column names or an [[\yii\db\ExpressionInterface]] object.
* - `attribute` _(optional)_ – The [[tableAttributes()|table attribute]] name that this option is associated
* with (required if `orderBy` is an array or more than one column name)
* - `defaultDir` _(optional)_ – The default sort direction that should be used when sorting by this option
* (set to either `asc` or `desc`). Defaults to `asc` if not specified.
*
* ```php
* return [
* [
* 'label' => Craft::t('app', 'Attribute Label'),
* 'orderBy' => 'columnName',
* 'attribute' => 'attributeName',
* 'defaultDir' => 'asc',
* ],
* ];
* ```
*
* A shorthand syntax is also supported, if there is no corresponding table attribute, or the table attribute
* has the exact same name as the column.
*
* ```php
* return [
* 'columnName' => Craft::t('app', 'Attribute Label'),
* ];
* ```
*
* Note that this method will only get called once for the entire index; not each time that a new source is
* selected.
*
* @return array The attributes that elements can be sorted by
*/
public static function sortOptions(): array;
/**
* Returns the view modes available for the element type.
*
* This method should return an array, where each item is a sub-array with the following keys:
*
* - `mode` – Name of the view mode
* - `title` – How this mode should be described to the user
* - `icon` – Icon representing this view mode
* - `availableOnMobile` - Whether the view mode is available on mobile devices (defaults to `true`)
* - `structuresOnly` – Whether the view mode should only be available for structured sources (defaults to `false`)
*
* ```php
* return [
* [
* 'mode' => 'table',
* 'title' => Craft::t('app', 'Display in a table'),
* 'icon' => 'list',
* 'availableOnMobile' => false,
* ],
* ];
* ```
*
* @return array The view modes.
* @since 5.5.0
*/
public static function indexViewModes(): array;
/**
* Defines all of the available columns that can be shown in table views.
*
* This method should return an array whose keys represent element attribute names, and whose values make
* up the table’s column headers.
*
* @return array The table attributes.
*/
public static function tableAttributes(): array;
/**
* Returns the list of table attribute keys that should be shown by default.
*
* This method should return an array where each element in the array maps to one of the keys of the array returned
* by [[tableAttributes()]].
*
* @param string $source The selected source’s key
* @return string[] The table attribute keys
*/
public static function defaultTableAttributes(string $source): array;
/**
* Defines all the available attributes that can be shown in card views.
*
* This method should return an array whose keys represent element attribute names, and whose values make
* up the table’s column headers.
*
* @param FieldLayout|null $fieldLayout
* @since 5.9.0
* @return array The card attributes.
*
* @since 5.5.0
*/
public static function cardAttributes(?FieldLayout $fieldLayout = null): array;
/**
* Returns the list of card attribute keys that should be shown by default, if the field layout hasn't been customised.
*
* This method should return an array where each element in the array maps to one of the keys of the array returned
* by [[cardAttributes()]].
*
* @return string[] The card attribute keys
* @since 5.5.0
*/
public static function defaultCardAttributes(): array;
/**
* Return HTML for the attribute in the card preview.
*
* @param array $attribute
* @return mixed
* @since 5.5.0
*/
public static function attributePreviewHtml(array $attribute): mixed;
/**
* Returns an array that maps source-to-target element IDs based on the given sub-property handle.
*
* This method aids in the eager-loading of elements when performing an element query. The returned array should
* contain the following keys:
* - `map` – an array defining source-target element mappings
* - `elementType` *(optional)* – the fully qualified class name of the element type that should be eager-loaded,
* if each target element is of the same element type
* - `criteria` *(optional)* – any criteria parameters that should be applied to the element query when fetching the
* eager-loaded elements
* - `createElement` *(optional)* - an element factory function, which will be passed the element query, the current
* query result data, and the first source element that the result was eager-loaded for
*
* Each mapping listed in `map` should be an array with the following keys:
* - `source` – the source element ID
* - `target` – the target element ID
* - `elementType` *(optional)* – the target element type (only checked for if the top-level array doesn’t specify
* an `elementType` key)
*
* ```php
* use craft\base\ElementInterface;
* use craft\db\Query;
*
* public static function eagerLoadingMap(array $sourceElements, string $handle)
* {
* switch ($handle) {
* case 'author':
* $bookIds = array_map(fn(ElementInterface $element) => $element->id, $sourceElements);
* $map = (new Query)
* ->select(['source' => 'id', 'target' => 'authorId'])
* ->from('{{%books}}')
* ->where(['id' => $bookIds)
* ->all();
* return [
* 'elementType' => \my\plugin\Author::class,
* 'map' => $map,
* ];
* case 'bookClubs':
* $bookIds = array_map(fn(ElementInterface $element) => $element->id, $sourceElements);
* $map = (new Query)
* ->select(['source' => 'bookId', 'target' => 'clubId'])
* ->from('{{%bookclub_books}}')
* ->where(['bookId' => $bookIds)
* ->all();
* return [
* 'elementType' => \my\plugin\BookClub::class,
* 'map' => $map,
* ];
* default:
* return parent::eagerLoadMap($sourceElements, $handle);
* }
* }
* ```
*
* Alternatively, the method can return an array of multiple sets of mappings, each with their own nested `map`,
* `elementType`, `criteria`, and `createElement` keys.
*
* @param self[] $sourceElements An array of the source elements
* @param string $handle The property handle used to identify which target elements should be included in the map
* @return EagerLoadingMap|EagerLoadingMap[]|null|false The eager-loading element ID mappings, false if no mappings
* exist, or null if the result should be ignored
*/
public static function eagerLoadingMap(array $sourceElements, string $handle): array|null|false;
/**
* Returns the base GraphQL type name that represents elements of this type.
*
* @return Type
* @since 5.7.0
*/
public static function baseGqlType(): Type;
/**
* Returns the GraphQL scopes required by element’s context.
*
* @param mixed $context The element’s context, such as a volume, entry type or Matrix block type.
* @return array
* @since 3.3.0
*/
public static function gqlScopesByContext(mixed $context): array;
/**
* Returns whether this is a draft.
*
* @return bool
* @since 3.2.0
*/
public function getIsDraft(): bool;
/**
* Returns whether this is a revision.
*
* @return bool
* @since 3.2.0
*/
public function getIsRevision(): bool;
/**
* Returns whether this is the canonical element.
*
* @return bool
* @since 3.7.0
*/
public function getIsCanonical(): bool;
/**
* Returns whether this is a derivative element, such as a draft or revision.
*
* @return bool
* @since 3.7.0
*/
public function getIsDerivative(): bool;
/**
* Returns the canonical version of the element.
*
* If this is a draft or revision, the canonical element will be returned.
*
* @param bool $anySite Whether the canonical element can be retrieved in any site
* @return self
* @since 3.7.0
*/
public function getCanonical(bool $anySite = false): self;
/**
* Sets the canonical version of the element.
*
* @param self $element
* @since 3.7.0
*/
public function setCanonical(self $element): void;
/**
* Returns the element’s canonical ID.
*
* If this is a draft or revision, the canonical element’s ID will be returned.
*
* @return int|null
* @since 3.7.0
*/
public function getCanonicalId(): ?int;
/**
* Sets the element’s canonical ID.
*
* @param int|null $canonicalId
* @since 3.7.0
*/
public function setCanonicalId(?int $canonicalId): void;
/**
* Returns the element’s canonical UUID.
*
* If this is a draft or revision, the canonical element’s UUID will be returned.
*
* @return string|null
* @since 3.7.11
*/
public function getCanonicalUid(): ?string;
/**
* Returns whether the element is an unpublished draft.
*
* @return bool
* @since 3.6.0
*/
public function getIsUnpublishedDraft(): bool;
/**
* Merges changes from the canonical element into this one.
*
* @see \craft\services\Elements::mergeCanonicalChanges()
* @since 3.7.0
*/
public function mergeCanonicalChanges(): void;
/**
* Returns the field layout used by this element.
*
* @return FieldLayout|null
*/
public function getFieldLayout(): ?FieldLayout;
/**
* Returns the site the element is associated with.
*
* @return Site
*/
public function getSite(): Site;
/**
* Returns the language of the element.
*
* @return string
* @since 3.5.0
*/
public function getLanguage(): string;
/**
* Returns the sites this element is associated with.
*
* The function can either return an array of site IDs, or an array of sub-arrays,
* each with the following keys:
*
* - `siteId` (integer) - The site ID
* - `propagate` (boolean) – Whether the element should be propagated to this site on save (`true` by default)
* - `enabledByDefault` (boolean) – Whether the element should be enabled in this site by default
* (`true` by default)
*
* @return array
*/
public function getSupportedSites(): array;
/**
* Returns the URI format used to generate this element’s URI.
*
* Note that element types that can have URIs must return `true` from [[hasUris()]].
*
* @return string|null
* @see hasUris()
* @see getRoute()
*/
public function getUriFormat(): ?string;
/**
* Returns the search keywords for a given search attribute.
*
* @param string $attribute
* @return string
*/
public function getSearchKeywords(string $attribute): string;
/**
* Returns the route that should be used when the element’s URI is requested.
*
* ::: tip
* Element types that extend [[\craft\base\Element]] should override [[\craft\base\Element::route()]]
* instead of this method.
* :::
*
* @return mixed The route that the request should use, or null if no special action should be taken
*/
public function getRoute(): mixed;
/**
* Returns whether this element represents the site homepage.
*
* @return bool
* @since 3.3.6
*/
public function getIsHomepage(): bool;
/**
* Returns the element’s full URL.
*
* @return string|null
*/
public function getUrl(): ?string;
/**
* Returns an anchor pre-filled with this element’s URL and title.
*
* @return Markup|null
*/
public function getLink(): ?Markup;
/**
* Returns the breadcrumbs that lead up to the element.
*
* @return array
* @since 5.0.0
*/
public function getCrumbs(): array;
/**
* Defines what the element should be called within the control panel.
*
* @param string|null $label
* @since 3.6.3
*/
public function setUiLabel(?string $label): void;
/**
* Returns any path segment labels that should be prepended to the element’s UI label.
*
* @return string[]
* @since 4.4.0
*/
public function getUiLabelPath(): array;
/**
* Defines any path segment labels that should be prepended to the element’s UI label.
*
* @param string[] $path
* @since 4.4.0
*/
public function setUiLabelPath(array $path): void;
/**
* Returns the label HTML for element chips.
*
* @return string
* @since 5.0.0
*/
public function getChipLabelHtml(): string;
/**
* Returns whether chips and cards for this element should include a status indicator.
*
* @return bool
* @since 5.4.0
*/
public function showStatusIndicator(): bool;
/**
* Returns the titlebar label for element cards.
*
* @return string|null
* @since 5.7.0
*/
public function getCardTitle(): ?string;
/**
* Returns the body HTML for element cards.
*
* @return string|null
* @since 5.0.0
*/
public function getCardBodyHtml(): ?string;
/**
* Returns the reference string to this element.
*
* @return string|null
*/
public function getRef(): ?string;
/**
* Creates a new element (without saving it) based on this one.
*
* This will be called by the “Save and add another” action on the element’s edit page.
*
* Note that permissions don’t need to be considered here. The created element’s [[canSave()]] method will be called before saving.
*
* @return self|null
*/
public function createAnother(): ?self;
/**
* Returns whether the given user is authorized to view this element’s edit page.
*
* If they can view but not [[canSave()|save]], the edit form will either render statically,
* or be restricted to only saving changes as a draft, depending on [[canCreateDrafts()]].
*
* @param User $user
* @return bool
* @since 4.0.0
*/
public function canView(User $user): bool;
/**
* Returns whether the given user is authorized to save this element in its current form.
*
* This will only be called if the element can be [[canView()|viewed]].
*
* @param User $user
* @return bool
* @since 4.0.0
*/
public function canSave(User $user): bool;
/**
* Returns whether the given user is authorized to duplicate this element.
*
* This will only be called if the element can be [[canView()|viewed]] and/or [[canSave()|saved]].
*
* @param User $user
* @return bool
* @since 4.0.0
*/
public function canDuplicate(User $user): bool;
/**
* Returns whether the given user is authorized to duplicate this element as an unpublished draft.
*
* @param User $user
* @return bool
* @since 5.0.0
*/
public function canDuplicateAsDraft(User $user): bool;
/**
* Returns whether the given user is authorized to copy this element, to be duplicated elsewhere.
*
* @param User $user
* @return bool
* @since 5.7.0
*/
public function canCopy(User $user): bool;
/**
* Returns whether the given user is authorized to delete this element.
*
* This will only be called if the element can be [[canView()|viewed]] and/or [[canSave()|saved]].
*
* @param User $user
* @return bool
* @since 4.0.0
*/
public function canDelete(User $user): bool;
/**