Skip to content

Commit 0317f4c

Browse files
committed
Merge branch '5.x' into 6.x
# Conflicts: # CHANGELOG.md # src/Fields/Blueprint.php # src/Fields/Fieldset.php # src/Globals/GlobalSet.php # src/Http/Controllers/CP/Assets/BrowserController.php # src/Taxonomies/Taxonomy.php # tests/Data/Assets/AssetQueryBuilderTest.php # tests/Data/Taxonomies/TermQueryBuilderTest.php
2 parents c1cf984 + 88dd005 commit 0317f4c

28 files changed

+410
-25
lines changed

src/Assets/Asset.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ public function hasDuration()
11371137

11381138
public function getQueryableValue(string $field)
11391139
{
1140-
if (method_exists($this, $method = Str::camel($field))) {
1140+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
11411141
return $this->{$method}();
11421142
}
11431143

@@ -1150,6 +1150,17 @@ public function getQueryableValue(string $field)
11501150
return $field->fieldtype()->toQueryableValue($value);
11511151
}
11521152

1153+
private function queryableMethods(): array
1154+
{
1155+
return [
1156+
'absoluteUrl', 'apiUrl', 'basename', 'blueprint', 'containerId', 'containerHandle', 'dimensions',
1157+
'duration', 'editUrl', 'exists', 'extension', 'filename', 'folder', 'guessedExtension',
1158+
'hasDimensions', 'hasDuration', 'height', 'id', 'isAudio', 'isImage', 'isMedia', 'isPdf',
1159+
'isPreviewable', 'isSvg', 'isVideo', 'lastModified', 'mimeType', 'orientation', 'path', 'pdfUrl',
1160+
'ratio', 'reference', 'size', 'thumbnailUrl', 'title', 'url', 'width',
1161+
];
1162+
}
1163+
11531164
public function getCurrentDirtyStateAttributes(): array
11541165
{
11551166
return array_merge([

src/Assets/AssetContainer.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Statamic\Contracts\Assets\AssetContainer as AssetContainerContract;
88
use Statamic\Contracts\Data\Augmentable;
99
use Statamic\Contracts\Data\Augmented;
10+
use Statamic\Contracts\Query\ContainsQueryableValues;
1011
use Statamic\Data\ExistsAsFile;
1112
use Statamic\Data\HasAugmentedInstance;
1213
use Statamic\Events\AssetContainerBlueprintFound;
@@ -27,9 +28,10 @@
2728
use Statamic\Facades\Stache;
2829
use Statamic\Facades\URL;
2930
use Statamic\Support\Arr;
31+
use Statamic\Support\Str;
3032
use Statamic\Support\Traits\FluentlyGetsAndSets;
3133

32-
class AssetContainer implements Arrayable, ArrayAccess, AssetContainerContract, Augmentable
34+
class AssetContainer implements Arrayable, ArrayAccess, AssetContainerContract, Augmentable, ContainsQueryableValues
3335
{
3436
use ExistsAsFile, FluentlyGetsAndSets, HasAugmentedInstance;
3537

@@ -604,6 +606,24 @@ public static function __callStatic($method, $parameters)
604606
return Facades\AssetContainer::{$method}(...$parameters);
605607
}
606608

609+
public function getQueryableValue(string $field)
610+
{
611+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
612+
return $this->{$method}();
613+
}
614+
615+
return null;
616+
}
617+
618+
private function queryableMethods(): array
619+
{
620+
return [
621+
'absoluteUrl', 'accessible', 'allowDownloading', 'allowMoving', 'allowRenaming', 'allowUploads',
622+
'blueprint', 'createFolders', 'diskHandle', 'diskPath', 'editUrl', 'handle', 'hasSearchIndex',
623+
'id', 'path', 'private', 'searchIndex', 'showUrl', 'sortDirection', 'sortField', 'title', 'url',
624+
];
625+
}
626+
607627
public function __toString()
608628
{
609629
return $this->handle();

src/Assets/AssetFolder.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
use League\Flysystem\PathTraversalDetected;
77
use Statamic\Assets\AssetUploader as Uploader;
88
use Statamic\Contracts\Assets\AssetFolder as Contract;
9+
use Statamic\Contracts\Query\ContainsQueryableValues;
910
use Statamic\Events\AssetFolderDeleted;
1011
use Statamic\Events\AssetFolderSaved;
1112
use Statamic\Facades\AssetContainer;
1213
use Statamic\Facades\Path;
1314
use Statamic\Support\Str;
1415
use Statamic\Support\Traits\FluentlyGetsAndSets;
1516

16-
class AssetFolder implements Arrayable, Contract
17+
class AssetFolder implements Arrayable, ContainsQueryableValues, Contract
1718
{
1819
use FluentlyGetsAndSets;
1920

@@ -237,4 +238,20 @@ public function toArray()
237238
'basename' => (string) $this->basename(),
238239
];
239240
}
241+
242+
public function getQueryableValue(string $field)
243+
{
244+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
245+
return $this->{$method}();
246+
}
247+
248+
return null;
249+
}
250+
251+
private function queryableMethods(): array
252+
{
253+
return [
254+
'basename', 'count', 'lastModified', 'path', 'resolvedPath', 'size', 'title',
255+
];
256+
}
240257
}

src/Auth/User.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ protected function getComputedCallbacks()
476476

477477
public function getQueryableValue(string $field)
478478
{
479-
if (method_exists($this, $method = Str::camel($field))) {
479+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
480480
return $this->{$method}();
481481
}
482482

@@ -488,4 +488,13 @@ public function getQueryableValue(string $field)
488488

489489
return $field->fieldtype()->toQueryableValue($value);
490490
}
491+
492+
private function queryableMethods(): array
493+
{
494+
return [
495+
'apiUrl', 'avatar', 'blueprint', 'editUrl', 'email', 'gravatarUrl', 'groups', 'hasAvatarField',
496+
'id', 'initials', 'isSuper', 'isTaxonomizable', 'lastLogin', 'name', 'path', 'preferredLocale',
497+
'preferredTheme', 'reference', 'roles', 'title',
498+
];
499+
}
491500
}

src/Entries/Collection.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use InvalidArgumentException;
88
use Statamic\Contracts\Data\Augmentable as AugmentableContract;
99
use Statamic\Contracts\Entries\Collection as Contract;
10+
use Statamic\Contracts\Query\ContainsQueryableValues;
1011
use Statamic\Data\ContainsCascadingData;
1112
use Statamic\Data\ExistsAsFile;
1213
use Statamic\Data\HasAugmentedData;
@@ -35,7 +36,7 @@
3536

3637
use function Statamic\trans as __;
3738

38-
class Collection implements Arrayable, ArrayAccess, AugmentableContract, Contract
39+
class Collection implements Arrayable, ArrayAccess, AugmentableContract, ContainsQueryableValues, Contract
3940
{
4041
use ContainsCascadingData, ExistsAsFile, FluentlyGetsAndSets, HasAugmentedData, HasDirtyState;
4142

@@ -967,6 +968,24 @@ public function augmentedArrayData()
967968
];
968969
}
969970

971+
public function getQueryableValue(string $field)
972+
{
973+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
974+
return $this->{$method}();
975+
}
976+
977+
return null;
978+
}
979+
980+
private function queryableMethods(): array
981+
{
982+
return [
983+
'dated', 'defaultPublishState', 'editUrl', 'handle', 'hasStructure', 'id', 'layout', 'mount',
984+
'orderable', 'path', 'requiresSlugs', 'revisionsEnabled', 'sites', 'sortDirection', 'sortField',
985+
'structureHandle', 'taxonomies', 'template', 'title', 'url', 'uri',
986+
];
987+
}
988+
970989
public function getCurrentDirtyStateAttributes(): array
971990
{
972991
return $this->fileData();

src/Entries/Entry.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ public function getQueryableValue(string $field)
11391139
Blink::store('entry-uris')->forget($this->id());
11401140
}
11411141

1142-
if (method_exists($this, $method = Str::camel($field))) {
1142+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
11431143
return $this->{$method}();
11441144
}
11451145

@@ -1152,6 +1152,16 @@ public function getQueryableValue(string $field)
11521152
return $field->fieldtype()->toQueryableValue($value);
11531153
}
11541154

1155+
private function queryableMethods(): array
1156+
{
1157+
return [
1158+
'apiUrl', 'blueprint', 'collection', 'collectionHandle', 'date', 'editUrl', 'hasDate', 'hasExplicitDate', 'hasOrigin',
1159+
'hasSeconds', 'hasStructure', 'hasTime', 'id', 'isRedirect', 'isRoot', 'lastModified', 'lastModifiedBy',
1160+
'layout', 'locale', 'order', 'path', 'private', 'published', 'redirectUrl', 'reference', 'site', 'sites', 'slug',
1161+
'status', 'template', 'uri', 'url', 'urlWithoutRedirect',
1162+
];
1163+
}
1164+
11551165
public function getSearchValue(string $field)
11561166
{
11571167
return method_exists($this, $field) ? $this->$field() : $this->value($field);

src/Fields/Blueprint.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Statamic\CommandPalette\Category;
1111
use Statamic\CommandPalette\Link;
1212
use Statamic\Contracts\Data\Augmentable;
13+
use Statamic\Contracts\Query\ContainsQueryableValues;
1314
use Statamic\Contracts\Query\QueryableValue;
1415
use Statamic\CP\Column;
1516
use Statamic\CP\Columns;
@@ -33,7 +34,7 @@
3334

3435
use function Statamic\trans as __;
3536

36-
class Blueprint implements Arrayable, ArrayAccess, Augmentable, QueryableValue
37+
class Blueprint implements Arrayable, ArrayAccess, Augmentable, ContainsQueryableValues, QueryableValue
3738
{
3839
use ExistsAsFile, HasAugmentedData;
3940

@@ -821,4 +822,21 @@ public function commandPaletteLink(string|array $type, string $url): Link
821822
->url($url)
822823
->icon('blueprints');
823824
}
825+
826+
public function getQueryableValue(string $field)
827+
{
828+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
829+
return $this->{$method}();
830+
}
831+
832+
return null;
833+
}
834+
835+
private function queryableMethods(): array
836+
{
837+
return [
838+
'columns', 'fields', 'handle', 'hidden', 'isEmpty', 'isDeletable', 'isResettable',
839+
'namespace', 'order', 'path', 'tabs', 'title',
840+
];
841+
}
824842
}

src/Fields/Fieldset.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Statamic\CommandPalette\Category;
66
use Statamic\CommandPalette\Link;
7+
use Statamic\Contracts\Query\ContainsQueryableValues;
78
use Statamic\Events\FieldsetCreated;
89
use Statamic\Events\FieldsetCreating;
910
use Statamic\Events\FieldsetDeleted;
@@ -23,7 +24,7 @@
2324
use Statamic\Support\Arr;
2425
use Statamic\Support\Str;
2526

26-
class Fieldset
27+
class Fieldset implements ContainsQueryableValues
2728
{
2829
protected $handle;
2930
protected $contents = [];
@@ -307,6 +308,23 @@ public function commandPaletteLink(): Link
307308
->icon('fieldsets');
308309
}
309310

311+
public function getQueryableValue(string $field)
312+
{
313+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
314+
return $this->{$method}();
315+
}
316+
317+
return null;
318+
}
319+
320+
private function queryableMethods(): array
321+
{
322+
return [
323+
'editUrl', 'fields', 'handle', 'isDeletable', 'isResettable',
324+
'namespace', 'path', 'title',
325+
];
326+
}
327+
310328
public static function __callStatic($method, $parameters)
311329
{
312330
return Facades\Fieldset::{$method}(...$parameters);

src/Forms/Form.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Statamic\Contracts\Forms\Form as FormContract;
99
use Statamic\Contracts\Forms\Submission;
1010
use Statamic\Contracts\Forms\SubmissionQueryBuilder;
11+
use Statamic\Contracts\Query\ContainsQueryableValues;
1112
use Statamic\Data\ContainsData;
1213
use Statamic\Data\HasAugmentedInstance;
1314
use Statamic\Events\FormBlueprintFound;
@@ -26,9 +27,10 @@
2627
use Statamic\Forms\Exporters\Exporter;
2728
use Statamic\Statamic;
2829
use Statamic\Support\Arr;
30+
use Statamic\Support\Str;
2931
use Statamic\Support\Traits\FluentlyGetsAndSets;
3032

31-
class Form implements Arrayable, Augmentable, FormContract
33+
class Form implements Arrayable, Augmentable, ContainsQueryableValues, FormContract
3234
{
3335
use ContainsData, FluentlyGetsAndSets, HasAugmentedInstance;
3436

@@ -447,4 +449,27 @@ public function exporter(string $handle): ?Exporter
447449
{
448450
return $this->exporters()->get($handle);
449451
}
452+
453+
public function getQueryableValue(string $field)
454+
{
455+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
456+
return $this->{$method}();
457+
}
458+
459+
$value = $this->get($field);
460+
461+
if (! $field = $this->blueprint()->field($field)) {
462+
return $value;
463+
}
464+
465+
return $field->fieldtype()->toQueryableValue($value);
466+
}
467+
468+
private function queryableMethods(): array
469+
{
470+
return [
471+
'actionUrl', 'apiUrl', 'blueprint', 'dateFormat', 'editUrl', 'fields',
472+
'handle', 'honeypot', 'path', 'submissions', 'title',
473+
];
474+
}
450475
}

src/Forms/Submission.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Carbon\Carbon;
66
use Statamic\Contracts\Data\Augmentable;
77
use Statamic\Contracts\Forms\Submission as SubmissionContract;
8+
use Statamic\Contracts\Query\ContainsQueryableValues;
89
use Statamic\Data\ContainsData;
910
use Statamic\Data\ExistsAsFile;
1011
use Statamic\Data\HasAugmentedData;
@@ -21,9 +22,10 @@
2122
use Statamic\Facades\Stache;
2223
use Statamic\Forms\Uploaders\AssetsUploader;
2324
use Statamic\Forms\Uploaders\FilesUploader;
25+
use Statamic\Support\Str;
2426
use Statamic\Support\Traits\FluentlyGetsAndSets;
2527

26-
class Submission implements Augmentable, SubmissionContract
28+
class Submission implements Augmentable, ContainsQueryableValues, SubmissionContract
2729
{
2830
use ContainsData, ExistsAsFile, FluentlyGetsAndSets, HasAugmentedData, TracksQueriedColumns, TracksQueriedRelations;
2931

@@ -264,6 +266,28 @@ public function fileData()
264266
return $this->data()->all();
265267
}
266268

269+
public function getQueryableValue(string $field)
270+
{
271+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
272+
return $this->{$method}();
273+
}
274+
275+
$value = $this->get($field);
276+
277+
if (! $field = $this->blueprint()->field($field)) {
278+
return $value;
279+
}
280+
281+
return $field->fieldtype()->toQueryableValue($value);
282+
}
283+
284+
private function queryableMethods(): array
285+
{
286+
return [
287+
'blueprint', 'date', 'form', 'formattedDate', 'id', 'path',
288+
];
289+
}
290+
267291
public function __get($key)
268292
{
269293
return $this->get($key);

0 commit comments

Comments
 (0)