From 3617619dffd393e4b6cb49c9ff790e8744b0adec Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 15:38:08 +0100 Subject: [PATCH 01/59] Change pagination question to ask if it should be enabled not configured --- .../src/Console/Commands/MakePublicationTypeCommand.php | 2 +- .../Feature/Commands/MakePublicationTypeCommandTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 87795cc3ee7..d23b42d306a 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -188,7 +188,7 @@ protected function addCreatedAtMetaField(): void protected function getPaginationSettings(): array { - if ($this->option('use-defaults') || ! $this->confirm('Do you want to configure pagination settings?')) { + if ($this->option('use-defaults') || ! $this->confirm('Would you like to enable pagination?')) { return [null, null, null, null]; } diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index 1cffb0585f7..e36e1e3bb2d 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -50,7 +50,7 @@ public function test_command_creates_publication_type() 'Tag', ], true) ->expectsConfirmation('Field #1 added! Add another field?') - ->expectsConfirmation('Do you want to configure pagination settings?', 'yes') + ->expectsConfirmation('Would you like to enable pagination?', 'yes') ->expectsChoice('Choose the default field you wish to sort by', '__createdAt', [ '__createdAt', 'publication-title', @@ -129,7 +129,7 @@ public function test_with_multiple_fields_of_the_same_name() ->expectsConfirmation('Field #2 added! Add another field?') - ->expectsConfirmation('Do you want to configure pagination settings?') + ->expectsConfirmation('Would you like to enable pagination?') ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'foo', [ '__createdAt', 'bar', @@ -242,7 +242,7 @@ public function testWithTagFieldInputButNoTagsCanPromptToCreateTags() ->expectsOutput("Okay, we're back on track!") ->expectsChoice('Enter tag group for field #1', 'foo', ['foo'], true) ->expectsConfirmation('Field #1 added! Add another field?') - ->expectsConfirmation('Do you want to configure pagination settings?') + ->expectsConfirmation('Would you like to enable pagination?') ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', '__createdAt', ['__createdAt']) ->doesntExpectOutput('Error: Can not create a tag field without any tag groups defined in tags.json') ->assertSuccessful(); From d234788860587b28e306a028f72343b4fdec7ad3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 15:43:07 +0100 Subject: [PATCH 02/59] Default value of choice should be the array key not the value --- .../src/Console/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index d23b42d306a..f1e74406fd0 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -197,7 +197,7 @@ protected function getPaginationSettings(): array protected function getSortField(): string { - return $this->choice('Choose the default field you wish to sort by', $this->fields->pluck('name')->toArray(), '__dateCreated'); + return $this->choice('Choose the default field you wish to sort by', $this->fields->pluck('name')->toArray(), 0); } protected function getSortDirection(): bool From bd0245be3681dbf321164b0f2ade5b56783ba60a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 15:43:39 +0100 Subject: [PATCH 03/59] Display output message marking selection with tip regarding defaults --- .../src/Console/Commands/MakePublicationTypeCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index f1e74406fd0..22937117364 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -192,6 +192,8 @@ protected function getPaginationSettings(): array return [null, null, null, null]; } + $this->info("Okay, let's set up pagination! Tip: You can just hit enter to accept the default values."); + return [$this->getSortField(), $this->getSortDirection(), $this->getPrevNextLinks(), $this->getPageSize()]; } From 2eec7cd28cdc86547177b5eb838b1e2ec874390a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 15:49:54 +0100 Subject: [PATCH 04/59] Delete deprecated pagination settings property $prevNextLinks Removed as its unlikely one would enable page size limits without a way to traverse them --- .../Features/Publications/Models/PaginationSettings.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php b/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php index 81a2f5cee4f..18a0393323c 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php @@ -13,8 +13,6 @@ class PaginationSettings implements SerializableContract public string $sortField = '__createdAt'; public bool $sortAscending = true; - /** @deprecated This setting might be deprecated as its unlikely one would enable page size limits without a way to traverse them */ - public bool $prevNextLinks = true; public int $pageSize = 25; public static function fromArray(array $data): static From c2b975cba47b3779580eb2003900204c5ddae9cb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 15:51:02 +0100 Subject: [PATCH 05/59] Remove the $prevNextLinks argument from settings constructor --- .../Features/Publications/Models/PaginationSettings.php | 2 +- packages/framework/tests/Unit/PaginationSettingsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php b/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php index 18a0393323c..24ebc658e12 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php @@ -20,7 +20,7 @@ public static function fromArray(array $data): static return new static(...$data); } - public function __construct(string $sortField = '__createdAt', bool $sortAscending = true, bool $prevNextLinks = true, int $pageSize = 25) + public function __construct(string $sortField = '__createdAt', bool $sortAscending = true, int $pageSize = 25) { $this->sortField = $sortField; $this->sortAscending = $sortAscending; diff --git a/packages/framework/tests/Unit/PaginationSettingsTest.php b/packages/framework/tests/Unit/PaginationSettingsTest.php index 79264777f1d..6d8c65d6867 100644 --- a/packages/framework/tests/Unit/PaginationSettingsTest.php +++ b/packages/framework/tests/Unit/PaginationSettingsTest.php @@ -24,7 +24,7 @@ public function testConstructWithDefaultValues() public function testConstruct() { - $paginationSettings = new PaginationSettings('foo', false, false, 10); + $paginationSettings = new PaginationSettings('foo', false, 10); $this->assertSame('foo', $paginationSettings->sortField); $this->assertFalse($paginationSettings->sortAscending); From fb302ec8e9f8a49583114bc579833861790f3a5c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 15:52:17 +0100 Subject: [PATCH 06/59] Remove internal references to removed property --- .../Features/Publications/Models/PaginationSettings.php | 2 -- packages/framework/tests/Unit/PaginationSettingsTest.php | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php b/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php index 24ebc658e12..7b73cc8e883 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PaginationSettings.php @@ -24,7 +24,6 @@ public function __construct(string $sortField = '__createdAt', bool $sortAscendi { $this->sortField = $sortField; $this->sortAscending = $sortAscending; - $this->prevNextLinks = $prevNextLinks; $this->pageSize = $pageSize; } @@ -33,7 +32,6 @@ public function toArray(): array return [ 'sortField' => $this->sortField, 'sortAscending' => $this->sortAscending, - 'prevNextLinks' => $this->prevNextLinks, 'pageSize' => $this->pageSize, ]; } diff --git a/packages/framework/tests/Unit/PaginationSettingsTest.php b/packages/framework/tests/Unit/PaginationSettingsTest.php index 6d8c65d6867..35bdb40b9a8 100644 --- a/packages/framework/tests/Unit/PaginationSettingsTest.php +++ b/packages/framework/tests/Unit/PaginationSettingsTest.php @@ -19,7 +19,6 @@ public function testConstructWithDefaultValues() $this->assertSame('__createdAt', $paginationSettings->sortField); $this->assertSame(true, $paginationSettings->sortAscending); $this->assertSame(25, $paginationSettings->pageSize); - $this->assertSame(true, $paginationSettings->prevNextLinks); } public function testConstruct() @@ -29,7 +28,6 @@ public function testConstruct() $this->assertSame('foo', $paginationSettings->sortField); $this->assertFalse($paginationSettings->sortAscending); $this->assertSame(10, $paginationSettings->pageSize); - $this->assertFalse($paginationSettings->prevNextLinks); } public function testFromArray() @@ -38,13 +36,11 @@ public function testFromArray() 'sortField' => 'foo', 'sortAscending' => false, 'pageSize' => 10, - 'prevNextLinks' => false, ]); $this->assertSame('foo', $paginationSettings->sortField); $this->assertSame(false, $paginationSettings->sortAscending); $this->assertSame(10, $paginationSettings->pageSize); - $this->assertSame(false, $paginationSettings->prevNextLinks); } public function testToArray() @@ -54,7 +50,6 @@ public function testToArray() $this->assertSame([ 'sortField' => '__createdAt', 'sortAscending' => true, - 'prevNextLinks' => true, 'pageSize' => 25, ], $paginationSettings->toArray()); } @@ -63,7 +58,7 @@ public function testToJson() { $paginationSettings = new PaginationSettings(); - $this->assertSame('{"sortField":"__createdAt","sortAscending":true,"prevNextLinks":true,"pageSize":25}', $paginationSettings->toJson()); + $this->assertSame('{"sortField":"__createdAt","sortAscending":true,"pageSize":25}', $paginationSettings->toJson()); } public function testJsonSerialize() From 059f0858534b34041c8a488b93810534d270ecb2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:36:25 +0100 Subject: [PATCH 07/59] Remove prev/next links from command --- .../Console/Commands/MakePublicationTypeCommand.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 22937117364..a05861473c9 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -49,11 +49,11 @@ public function safeHandle(): int $this->fields = $this->captureFieldsDefinitions(); - [$sortField, $sortAscending, $prevNextLinks, $pageSize] = ($this->getPaginationSettings()); + [$sortField, $sortAscending, $pageSize] = ($this->getPaginationSettings()); $canonicalField = $this->getCanonicalField(); - $creator = new CreatesNewPublicationType($title, $this->fields, $canonicalField->name, $sortField, $sortAscending, $prevNextLinks, $pageSize); + $creator = new CreatesNewPublicationType($title, $this->fields, $canonicalField->name, $sortField, $sortAscending, $pageSize); $this->output->writeln("Saving publication data to [{$creator->getOutputPath()}]"); $creator->create(); @@ -189,12 +189,12 @@ protected function addCreatedAtMetaField(): void protected function getPaginationSettings(): array { if ($this->option('use-defaults') || ! $this->confirm('Would you like to enable pagination?')) { - return [null, null, null, null]; + return [null, null, null]; } $this->info("Okay, let's set up pagination! Tip: You can just hit enter to accept the default values."); - return [$this->getSortField(), $this->getSortDirection(), $this->getPrevNextLinks(), $this->getPageSize()]; + return [$this->getSortField(), $this->getSortDirection(), $this->getPageSize()]; } protected function getSortField(): string @@ -209,11 +209,6 @@ protected function getSortDirection(): bool return $options[$this->choice('Choose the default sort direction', array_keys($options), 'Ascending')]; } - protected function getPrevNextLinks(): bool - { - return $this->confirm('Generate previous/next links in detail view?', true); - } - protected function getPageSize(): int { return (int) $this->askWithValidation('pageSize', From de3f7ced894492398b146dd913c196c8d09d1da9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:37:20 +0100 Subject: [PATCH 08/59] Remove prev/next links from creator --- .../src/Framework/Actions/CreatesNewPublicationType.php | 2 -- .../tests/Feature/Commands/MakePublicationTypeCommandTest.php | 1 - 2 files changed, 3 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index b53e36a2d81..5ffcd78fb12 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -26,7 +26,6 @@ public function __construct( protected ?string $canonicalField = null, protected ?string $sortField = null, protected ?bool $sortAscending = null, - protected ?bool $prevNextLinks = null, protected ?int $pageSize = null, ) { $this->directoryName = $this->formatStringForStorage($this->name); @@ -43,7 +42,6 @@ protected function handleCreate(): void [ $this->sortField ?? '__createdAt', $this->sortAscending ?? true, - $this->prevNextLinks ?? true, $this->pageSize ?? 25, ], $this->fields->toArray() diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index e36e1e3bb2d..373ff01fd63 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -59,7 +59,6 @@ public function test_command_creates_publication_type() 'Ascending', 'Descending', ]) - ->expectsConfirmation('Generate previous/next links in detail view?', 'yes') ->expectsQuestion('Enter the page size (0 for no limit)', 10) ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'publication-title', [ '__createdAt', From d7285425b86dd6499671cdf248560b3ebbd03a6d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:38:59 +0100 Subject: [PATCH 09/59] Remove prev/next links from test schemas --- .../tests/Feature/Actions/CreatesNewPublicationTypeTest.php | 2 -- .../tests/Feature/Commands/MakePublicationCommandTest.php | 2 -- .../tests/Feature/Commands/MakePublicationTypeCommandTest.php | 2 -- packages/framework/tests/Feature/PublicationListPageTest.php | 1 - packages/framework/tests/Feature/PublicationPageTest.php | 3 +-- packages/framework/tests/Feature/PublicationTypeTest.php | 3 --- tests/fixtures/test-publication-schema.json | 3 +-- 7 files changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php index 9e1c191dab2..33bf3b6ea5c 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php @@ -48,7 +48,6 @@ public function test_it_creates_a_new_publication_type() "pagination": { "sortField": "sort", "sortAscending": false, - "prevNextLinks": false, "pageSize": 10 }, "fields": [] @@ -75,7 +74,6 @@ public function test_create_with_default_parameters() "pagination": { "sortField": "__createdAt", "sortAscending": true, - "prevNextLinks": true, "pageSize": 25 }, "fields": [] diff --git a/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php index 4343de383c9..63c1ee2c185 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php @@ -77,7 +77,6 @@ public function test_command_selects_the_right_publication_using_the_names() 'listTemplate' => 'list', 'pagination' => [ 'pageSize' => 10, - 'prevNextLinks' => true, 'sortField' => '__createdAt', 'sortAscending' => true, ], @@ -584,7 +583,6 @@ protected function makeSchemaFile(array $merge = []): void 'listTemplate' => 'list', 'pagination' => [ 'pageSize' => 10, - 'prevNextLinks' => true, 'sortField' => '__createdAt', 'sortAscending' => true, ], diff --git a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php index 373ff01fd63..780b3f2cc1c 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php @@ -80,7 +80,6 @@ public function test_command_creates_publication_type() "pagination": { "sortField": "__createdAt", "sortAscending": true, - "prevNextLinks": true, "pageSize": 10 }, "fields": [ @@ -187,7 +186,6 @@ public function testWithTagFieldInput() "pagination": { "sortField": "__createdAt", "sortAscending": true, - "prevNextLinks": true, "pageSize": 25 }, "fields": [ diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 1371dce9a3c..b8945bbb80b 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -74,7 +74,6 @@ protected function getTestData(): array 'sortField' => 'sort', 'sortAscending' => true, 'pageSize' => 10, - 'prevNextLinks' => true, ], 'fields' => [ 'foo' => 'bar', diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index ad051c6c5e5..bbebb8dda49 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -121,8 +121,7 @@ protected function createRealPublicationFiles(): void "pagination": { "sortField": "__createdAt", "sortAscending": true, - "pageSize": 0, - "prevNextLinks": true + "pageSize": 0 }, "fields": [ { diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 6f9fb1dd4d1..c00ae13a58c 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -51,7 +51,6 @@ public function test_construct_with_default_values() 'sortField' => '__createdAt', 'sortAscending' => true, 'pageSize' => 25, - 'prevNextLinks' => true, ]), $publicationType->pagination); $this->assertEquals('test-publication', $publicationType->getDirectory()); @@ -63,7 +62,6 @@ public function test_construct_with_pagination_object() 'sortField' => 'title', 'sortAscending' => false, 'pageSize' => 10, - 'prevNextLinks' => false, ]); $publicationType = new PublicationType('Test Publication', pagination: $paginationSettings); $this->assertSame($paginationSettings, $publicationType->pagination); @@ -411,7 +409,6 @@ protected function getTestData(array $mergeData = []): array 'pagination' => [ 'sortField' => '__createdAt', 'sortAscending' => true, - 'prevNextLinks' => true, 'pageSize' => 25, ], 'fields' => [ diff --git a/tests/fixtures/test-publication-schema.json b/tests/fixtures/test-publication-schema.json index 0528d26e352..0617a00d452 100644 --- a/tests/fixtures/test-publication-schema.json +++ b/tests/fixtures/test-publication-schema.json @@ -6,8 +6,7 @@ "pagination": { "sortField": "__createdAt", "sortAscending": true, - "pageSize": 25, - "prevNextLinks": true + "pageSize": 25 }, "fields": [ { From 08737e7caf6f3c9b246c84da36155d058f46a7d0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:40:17 +0100 Subject: [PATCH 10/59] Remove values for removed argument in tests --- .../tests/Feature/Actions/CreatesNewPublicationTypeTest.php | 1 - packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php index 33bf3b6ea5c..6e8b8d33403 100644 --- a/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php +++ b/packages/framework/tests/Feature/Actions/CreatesNewPublicationTypeTest.php @@ -33,7 +33,6 @@ public function test_it_creates_a_new_publication_type() 'canonical', 'sort', false, - false, 10 ); $creator->create(); diff --git a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php b/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php index 3c70f0f3ef9..17cd15cfe3e 100644 --- a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php +++ b/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php @@ -244,7 +244,7 @@ protected function pubType(): PublicationType 'canonicalField', 'detail.blade.php', 'list.blade.php', - ['sortField', true, true, 1], + ['sortField', true, 1], [], 'directory' ); From ed440bea407f5abe20ddd1638b2ae83eb70ccd5d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:47:04 +0100 Subject: [PATCH 11/59] Extract method --- .../Features/Publications/Models/PublicationType.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index f58c86ae4a4..68a01ad2add 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -65,9 +65,7 @@ public function __construct( ) { $this->fields = $fields; $this->directory = $directory ?? Str::slug($name); - $this->pagination = $pagination instanceof PaginationSettings - ? $pagination - : PaginationSettings::fromArray($pagination); + $this->pagination = $this->evaluatePaginationSettings($pagination); } public function toArray(): array @@ -188,4 +186,11 @@ protected function getPublicationsSortedByPaginationField(): Collection return $page->matter($this->pagination->sortField); }, descending: ! $this->pagination->sortAscending)->values(); } + + protected function evaluatePaginationSettings(array|PaginationSettings $pagination): PaginationSettings + { + return $pagination instanceof PaginationSettings + ? $pagination + : PaginationSettings::fromArray($pagination); + } } From 81de1fbf52f2480013580482bb725558b1a19376 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:47:22 +0100 Subject: [PATCH 12/59] Replace '?:' with if --- .../Features/Publications/Models/PublicationType.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 68a01ad2add..26d4dc42744 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -189,8 +189,10 @@ protected function getPublicationsSortedByPaginationField(): Collection protected function evaluatePaginationSettings(array|PaginationSettings $pagination): PaginationSettings { - return $pagination instanceof PaginationSettings - ? $pagination - : PaginationSettings::fromArray($pagination); + if ($pagination instanceof PaginationSettings) { + return $pagination; + } + + return PaginationSettings::fromArray($pagination); } } From d26f78001ab4e9aaa73d1685be55aba7a1aa47b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:47:57 +0100 Subject: [PATCH 13/59] Invert 'if' statement --- .../Features/Publications/Models/PublicationType.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 26d4dc42744..8aeb88fb336 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -18,6 +18,7 @@ use Hyde\Support\Contracts\SerializableContract; use Illuminate\Support\Collection; use Illuminate\Support\Str; +use function is_array; use function json_decode; use function json_encode; use RuntimeException; @@ -189,10 +190,9 @@ protected function getPublicationsSortedByPaginationField(): Collection protected function evaluatePaginationSettings(array|PaginationSettings $pagination): PaginationSettings { - if ($pagination instanceof PaginationSettings) { - return $pagination; + if (is_array($pagination)) { + return PaginationSettings::fromArray($pagination); } - - return PaginationSettings::fromArray($pagination); + return $pagination; } } From 3cfaffbad6890f3c18eb5c7fcc6368d690cd9fdb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:48:26 +0100 Subject: [PATCH 14/59] Return null if the pagination settings are empty --- .../Features/Publications/Models/PublicationType.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 8aeb88fb336..bb4e7358415 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -188,9 +188,13 @@ protected function getPublicationsSortedByPaginationField(): Collection }, descending: ! $this->pagination->sortAscending)->values(); } - protected function evaluatePaginationSettings(array|PaginationSettings $pagination): PaginationSettings + protected function evaluatePaginationSettings(array|PaginationSettings $pagination): ?PaginationSettings { if (is_array($pagination)) { + if (empty($pagination)) { + return null; + } + return PaginationSettings::fromArray($pagination); } return $pagination; From 06724511006cca00d8d7266b56fb9a8970e18b3b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:48:50 +0100 Subject: [PATCH 15/59] Make PublicationType::$pagination nullable --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index bb4e7358415..9f24c8bdcae 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -32,7 +32,7 @@ class PublicationType implements SerializableContract use Serializable; use InteractsWithDirectories; - public PaginationSettings $pagination; + public ?PaginationSettings $pagination; protected string $directory; /** @var array> */ From 3040d1b621bcc0a8bddf8e74ad46026b75da7c61 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:49:08 +0100 Subject: [PATCH 16/59] Union type nullable to make it more noticeable --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 9f24c8bdcae..137419445e9 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -32,7 +32,7 @@ class PublicationType implements SerializableContract use Serializable; use InteractsWithDirectories; - public ?PaginationSettings $pagination; + public PaginationSettings|null $pagination; protected string $directory; /** @var array> */ From abf5b86f013020722e72d9c682c5db5fbb8496cb Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 8 Jan 2023 15:50:23 +0000 Subject: [PATCH 17/59] Apply fixes from StyleCI --- .../Framework/Features/Publications/Models/PublicationType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 137419445e9..030f384ad6a 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -197,6 +197,7 @@ protected function evaluatePaginationSettings(array|PaginationSettings $paginati return PaginationSettings::fromArray($pagination); } + return $pagination; } } From 159664956d73d7b18569e2f0602ec6ccfca9f19e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 16:54:10 +0100 Subject: [PATCH 18/59] Expect pagination to be null by default --- packages/framework/tests/Feature/PublicationTypeTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index c00ae13a58c..3fac00d1de0 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -47,11 +47,7 @@ public function test_construct_with_default_values() $this->assertEquals('detail.blade.php', $publicationType->detailTemplate); $this->assertEquals('list.blade.php', $publicationType->listTemplate); $this->assertEquals([], $publicationType->fields); - $this->assertEquals(PaginationSettings::fromArray([ - 'sortField' => '__createdAt', - 'sortAscending' => true, - 'pageSize' => 25, - ]), $publicationType->pagination); + $this->assertNull($publicationType->pagination); $this->assertEquals('test-publication', $publicationType->getDirectory()); } From 3282ac07571327e53a2f8b847f4ba80fb6dd17e8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:03:03 +0100 Subject: [PATCH 19/59] Use null safe operator for toArray call on nullable object --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 030f384ad6a..b1687d7cc54 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -76,7 +76,7 @@ public function toArray(): array 'canonicalField' => $this->canonicalField, 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, - 'pagination' => $this->pagination->toArray(), + 'pagination' => $this->pagination?->toArray(), 'fields' => $this->fields, ]; } From 9dac3ac7b5964c57663136ea722be5ef94af5384 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:04:05 +0100 Subject: [PATCH 20/59] Split out test for added complexity --- .../tests/Feature/PublicationTypeTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 202ac620499..1387dae50f4 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -435,6 +435,46 @@ public function testJsonRepresentationWithDefaultValues() JSON, $publicationType->toJson()); } + public function testArrayRepresentationWithPaginationSettings() + { + $publicationType = new PublicationType('test-publication'); + + $this->assertSame([ + 'name' => 'test-publication', + 'canonicalField' => 'identifier', + 'fields' => [], + 'pagination' => [ + 'pageSize' => 25, + 'sortField' => '__createdAt', + 'sortAscending' => true, + 'prevNextLinks' => true, + ], + 'detailTemplate' => 'detail.blade.php', + 'listTemplate' => 'list.blade.php', + ], $publicationType->toArray()); + } + + public function testJsonRepresentationWithPaginationSettings() + { + $publicationType = new PublicationType('test-publication'); + + $this->assertSame(<<<'JSON' + { + "name": "test-publication", + "canonicalField": "identifier", + "detailTemplate": "detail.blade.php", + "listTemplate": "list.blade.php", + "pagination": { + "sortField": "__createdAt", + "sortAscending": true, + "prevNextLinks": true, + "pageSize": 25 + }, + "fields": [] + } + JSON, $publicationType->toJson()); + } + protected function getTestData(array $mergeData = []): array { return array_merge([ From eae05499cd8e58a5c26e705899331bbf2bf1193b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:05:44 +0100 Subject: [PATCH 21/59] Update expected data for branch --- packages/framework/tests/Feature/PublicationTypeTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 1387dae50f4..3a1b6363c43 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -437,7 +437,7 @@ public function testJsonRepresentationWithDefaultValues() public function testArrayRepresentationWithPaginationSettings() { - $publicationType = new PublicationType('test-publication'); + $publicationType = new PublicationType('test-publication', pagination: new PaginationSettings()); $this->assertSame([ 'name' => 'test-publication', @@ -447,7 +447,6 @@ public function testArrayRepresentationWithPaginationSettings() 'pageSize' => 25, 'sortField' => '__createdAt', 'sortAscending' => true, - 'prevNextLinks' => true, ], 'detailTemplate' => 'detail.blade.php', 'listTemplate' => 'list.blade.php', @@ -456,7 +455,7 @@ public function testArrayRepresentationWithPaginationSettings() public function testJsonRepresentationWithPaginationSettings() { - $publicationType = new PublicationType('test-publication'); + $publicationType = new PublicationType('test-publication', pagination: new PaginationSettings()); $this->assertSame(<<<'JSON' { @@ -467,7 +466,6 @@ public function testJsonRepresentationWithPaginationSettings() "pagination": { "sortField": "__createdAt", "sortAscending": true, - "prevNextLinks": true, "pageSize": 25 }, "fields": [] From 113b5b72ac1d5a95d048804d414117ba084c3177 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:07:18 +0100 Subject: [PATCH 22/59] Fix expected array ordering to match actual for branch --- packages/framework/tests/Feature/PublicationTypeTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 3e0a365baba..457ba6f7db5 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -442,14 +442,14 @@ public function testArrayRepresentationWithPaginationSettings() $this->assertSame([ 'name' => 'test-publication', 'canonicalField' => 'identifier', - 'fields' => [], + 'detailTemplate' => 'detail.blade.php', + 'listTemplate' => 'list.blade.php', 'pagination' => [ - 'pageSize' => 25, 'sortField' => '__createdAt', 'sortAscending' => true, + 'pageSize' => 25, ], - 'detailTemplate' => 'detail.blade.php', - 'listTemplate' => 'list.blade.php', + 'fields' => [], ], $publicationType->toArray()); } From c07735ce6b90a0c73738419a323257ecd3a1758a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:07:45 +0100 Subject: [PATCH 23/59] Expect pagination settings to default to null --- .../tests/Feature/PublicationTypeTest.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 457ba6f7db5..26c2e19d2ea 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -404,12 +404,7 @@ public function testArrayRepresentationWithDefaultValues() 'canonicalField' => 'identifier', 'detailTemplate' => 'detail.blade.php', 'listTemplate' => 'list.blade.php', - 'pagination' => [ - 'sortField' => '__createdAt', - 'sortAscending' => true, - 'prevNextLinks' => true, - 'pageSize' => 25, - ], + 'pagination' => null, 'fields' => [], ], $publicationType->toArray()); } @@ -424,12 +419,7 @@ public function testJsonRepresentationWithDefaultValues() "canonicalField": "identifier", "detailTemplate": "detail.blade.php", "listTemplate": "list.blade.php", - "pagination": { - "sortField": "__createdAt", - "sortAscending": true, - "prevNextLinks": true, - "pageSize": 25 - }, + "pagination": null, "fields": [] } JSON, $publicationType->toJson()); From c9848e3b1707775b65c2178cb03e060777742d6c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:15:10 +0100 Subject: [PATCH 24/59] Remove null values from array representation --- .../Features/Publications/Models/PublicationType.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index b1687d7cc54..9f3880ee102 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Features\Publications\Models; +use function array_filter; use function array_merge; use function dirname; use Exception; @@ -71,14 +72,14 @@ public function __construct( public function toArray(): array { - return [ + return array_filter([ 'name' => $this->name, 'canonicalField' => $this->canonicalField, 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, 'pagination' => $this->pagination?->toArray(), 'fields' => $this->fields, - ]; + ]); } public function toJson($options = JSON_PRETTY_PRINT): string From a430a9d19cf00038a09d4cace2c96db1bfea8c76 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:15:13 +0100 Subject: [PATCH 25/59] Revert "Remove null values from array representation" This reverts commit c9848e3b1707775b65c2178cb03e060777742d6c. --- .../Features/Publications/Models/PublicationType.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 9f3880ee102..b1687d7cc54 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Features\Publications\Models; -use function array_filter; use function array_merge; use function dirname; use Exception; @@ -72,14 +71,14 @@ public function __construct( public function toArray(): array { - return array_filter([ + return [ 'name' => $this->name, 'canonicalField' => $this->canonicalField, 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, 'pagination' => $this->pagination?->toArray(), 'fields' => $this->fields, - ]); + ]; } public function toJson($options = JSON_PRETTY_PRINT): string From 5021b76ce351eb9c627c4e46dd586fecce015ae7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:17:35 +0100 Subject: [PATCH 26/59] Remove null values from array representation using callback function --- .../Features/Publications/Models/PublicationType.php | 10 ++++++++-- .../framework/tests/Feature/PublicationTypeTest.php | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index b1687d7cc54..83073ad3f6f 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Features\Publications\Models; +use function array_filter; use function array_merge; use function dirname; use Exception; @@ -71,14 +72,14 @@ public function __construct( public function toArray(): array { - return [ + return $this->withoutNullValues([ 'name' => $this->name, 'canonicalField' => $this->canonicalField, 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, 'pagination' => $this->pagination?->toArray(), 'fields' => $this->fields, - ]; + ]); } public function toJson($options = JSON_PRETTY_PRINT): string @@ -200,4 +201,9 @@ protected function evaluatePaginationSettings(array|PaginationSettings $paginati return $pagination; } + + protected function withoutNullValues(array $array): array + { + return array_filter($array, fn (mixed $value): bool => ! is_null($value)); + } } diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 26c2e19d2ea..0056784d63b 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -404,7 +404,6 @@ public function testArrayRepresentationWithDefaultValues() 'canonicalField' => 'identifier', 'detailTemplate' => 'detail.blade.php', 'listTemplate' => 'list.blade.php', - 'pagination' => null, 'fields' => [], ], $publicationType->toArray()); } @@ -419,7 +418,6 @@ public function testJsonRepresentationWithDefaultValues() "canonicalField": "identifier", "detailTemplate": "detail.blade.php", "listTemplate": "list.blade.php", - "pagination": null, "fields": [] } JSON, $publicationType->toJson()); From 1dd5a3b19ab32f1144688e00761c48b7c29bf210 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:23:34 +0100 Subject: [PATCH 27/59] Change publication type constructor to only accept ?array for pagination settings The publication type constructor now only accepts arrays for the publication setting (to keeps things simple, and since all other arguments are primitive PHP types) --- .../Publications/Models/PublicationType.php | 14 +++++--------- .../tests/Feature/PublicationTypeTest.php | 16 ++++++++-------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 83073ad3f6f..a964b6cb183 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -61,7 +61,7 @@ public function __construct( public string $canonicalField = 'identifier', public string $detailTemplate = 'detail.blade.php', public string $listTemplate = 'list.blade.php', - array|PaginationSettings $pagination = [], + ?array $pagination = [], array $fields = [], ?string $directory = null ) { @@ -189,17 +189,13 @@ protected function getPublicationsSortedByPaginationField(): Collection }, descending: ! $this->pagination->sortAscending)->values(); } - protected function evaluatePaginationSettings(array|PaginationSettings $pagination): ?PaginationSettings + protected function evaluatePaginationSettings(array $pagination): ?PaginationSettings { - if (is_array($pagination)) { - if (empty($pagination)) { - return null; - } - - return PaginationSettings::fromArray($pagination); + if (empty($pagination)) { + return null; } - return $pagination; + return PaginationSettings::fromArray($pagination); } protected function withoutNullValues(array $array): array diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 0056784d63b..78b9fbba119 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -52,15 +52,15 @@ public function test_construct_with_default_values() $this->assertEquals('test-publication', $publicationType->getDirectory()); } - public function test_construct_with_pagination_object() + public function test_construct_with_pagination_settings() { - $paginationSettings = PaginationSettings::fromArray([ + $paginationSettings = [ 'sortField' => 'title', 'sortAscending' => false, 'pageSize' => 10, - ]); + ]; $publicationType = new PublicationType('Test Publication', pagination: $paginationSettings); - $this->assertSame($paginationSettings, $publicationType->pagination); + $this->assertSame($paginationSettings, $publicationType->pagination->toArray()); } public function test_class_is_arrayable() @@ -310,7 +310,7 @@ public function testGetPaginatorSortsCollectionBySpecifiedPaginationSettings() $paginationSettings = new PaginationSettings('myNumber'); $fields = [['name' => 'myNumber', 'type' => 'integer']]; - $publicationType = new PublicationType('test-publication', 'myNumber', pagination: $paginationSettings, fields: $fields); + $publicationType = new PublicationType('test-publication', 'myNumber', pagination: $paginationSettings->toArray(), fields: $fields); $publicationType->save(); $pages[0] = (new PublicationPage('test-publication/page-1', ['myNumber' => 5], type: $publicationType))->save(); @@ -332,7 +332,7 @@ public function testGetPaginatorSortsCollectionBySpecifiedPaginationSettingsWith $paginationSettings = new PaginationSettings('myNumber', false); $fields = [['name' => 'myNumber', 'type' => 'integer']]; - $publicationType = new PublicationType('test-publication', 'myNumber', pagination: $paginationSettings, fields: $fields); + $publicationType = new PublicationType('test-publication', 'myNumber', pagination: $paginationSettings->toArray(), fields: $fields); $publicationType->save(); $pages[0] = (new PublicationPage('test-publication/page-1', ['myNumber' => 5], type: $publicationType))->save(); @@ -425,7 +425,7 @@ public function testJsonRepresentationWithDefaultValues() public function testArrayRepresentationWithPaginationSettings() { - $publicationType = new PublicationType('test-publication', pagination: new PaginationSettings()); + $publicationType = new PublicationType('test-publication', pagination: (new PaginationSettings())->toArray()); $this->assertSame([ 'name' => 'test-publication', @@ -443,7 +443,7 @@ public function testArrayRepresentationWithPaginationSettings() public function testJsonRepresentationWithPaginationSettings() { - $publicationType = new PublicationType('test-publication', pagination: new PaginationSettings()); + $publicationType = new PublicationType('test-publication', pagination: (new PaginationSettings())->toArray()); $this->assertSame(<<<'JSON' { From 9c725138b5087ac8c038aab97b32949981eb35c5 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 8 Jan 2023 16:23:48 +0000 Subject: [PATCH 28/59] Apply fixes from StyleCI --- .../Framework/Features/Publications/Models/PublicationType.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index a964b6cb183..a442cbf6bc9 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -19,7 +19,6 @@ use Hyde\Support\Contracts\SerializableContract; use Illuminate\Support\Collection; use Illuminate\Support\Str; -use function is_array; use function json_decode; use function json_encode; use RuntimeException; From 9b338e2ae3d72188083a0bc4b417449aef22c573 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:28:17 +0100 Subject: [PATCH 29/59] Replace promoted properties with traditional property declarations --- .../Publications/Models/PublicationType.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index a442cbf6bc9..147a9747770 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -33,6 +33,10 @@ class PublicationType implements SerializableContract use InteractsWithDirectories; public PaginationSettings|null $pagination; + public string $listTemplate = 'list.blade.php'; + public string $detailTemplate = 'detail.blade.php'; + public string $canonicalField = 'identifier'; + public string $name; protected string $directory; /** @var array> */ @@ -56,14 +60,18 @@ public static function fromFile(string $schemaFile): static } public function __construct( - public string $name, - public string $canonicalField = 'identifier', - public string $detailTemplate = 'detail.blade.php', - public string $listTemplate = 'list.blade.php', + string $name, + string $canonicalField = 'identifier', + string $detailTemplate = 'detail.blade.php', + string $listTemplate = 'list.blade.php', ?array $pagination = [], array $fields = [], ?string $directory = null ) { + $this->name = $name; + $this->canonicalField = $canonicalField; + $this->detailTemplate = $detailTemplate; + $this->listTemplate = $listTemplate; $this->fields = $fields; $this->directory = $directory ?? Str::slug($name); $this->pagination = $this->evaluatePaginationSettings($pagination); From 63c70c0f9e5cf66d2b2a97cca0d051ce6e3c47f3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:29:54 +0100 Subject: [PATCH 30/59] Invert order of properties flipped by PhpStorm refactor --- .../Features/Publications/Models/PublicationType.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 147a9747770..ad67ed930c6 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -33,10 +33,10 @@ class PublicationType implements SerializableContract use InteractsWithDirectories; public PaginationSettings|null $pagination; - public string $listTemplate = 'list.blade.php'; - public string $detailTemplate = 'detail.blade.php'; - public string $canonicalField = 'identifier'; public string $name; + public string $canonicalField = 'identifier'; + public string $detailTemplate = 'detail.blade.php'; + public string $listTemplate = 'list.blade.php'; protected string $directory; /** @var array> */ From eab76d6dc02c6d3c6539aec7fc52ed9fa4768f80 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:31:09 +0100 Subject: [PATCH 31/59] Sort class properties to match constructor and add some spacing --- .../Features/Publications/Models/PublicationType.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index ad67ed930c6..fcdf2f9c929 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -32,16 +32,18 @@ class PublicationType implements SerializableContract use Serializable; use InteractsWithDirectories; - public PaginationSettings|null $pagination; public string $name; public string $canonicalField = 'identifier'; public string $detailTemplate = 'detail.blade.php'; public string $listTemplate = 'list.blade.php'; - protected string $directory; + + public null|PaginationSettings $pagination; /** @var array> */ public array $fields = []; + protected string $directory; + public static function get(string $name): static { return static::fromFile("$name/schema.json"); From 3a1b6cf95446fb7e2a780420683f2205aced7432 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:43:46 +0100 Subject: [PATCH 32/59] Document all publication type properties --- .../Publications/Models/PublicationType.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index fcdf2f9c929..001bbca02f0 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -32,16 +32,32 @@ class PublicationType implements SerializableContract use Serializable; use InteractsWithDirectories; + /** The "pretty" name of the publication type */ public string $name; + + /** + * The field name that is used as the canonical (or identifying) field of publications. + * It's used primarily for generating filenames, and the publications must thus be unique by this field. + */ public string $canonicalField = 'identifier'; + + /** The Blade filename or view identifier used for rendering a single publication */ public string $detailTemplate = 'detail.blade.php'; + + /** The Blade filename or view identifier used for rendering the index page (or index pages, when using pagination) */ public string $listTemplate = 'list.blade.php'; + /** The pagination settings. Set to null to disable pagination. Make sure your list view supports it when enabled. */ public null|PaginationSettings $pagination; - /** @var array> */ + /** + * The front matter fields used for the publications. + * + * @var array> + */ public array $fields = []; + /** The directory of the publication files */ protected string $directory; public static function get(string $name): static From 3fbc6bfc4c0cf6caf1ebae72d1f9ae030696fd39 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:44:19 +0100 Subject: [PATCH 33/59] Document helper method --- .../Framework/Features/Publications/Models/PublicationType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 001bbca02f0..e376db9ac20 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -112,6 +112,7 @@ public function toJson($options = JSON_PRETTY_PRINT): string return json_encode($this->toArray(), $options); } + /** Get the publication type's identifier */ public function getIdentifier(): string { return $this->directory ?? Str::slug($this->name); From b11d39aaf517cfc2b05f0027f5c47e04187878ee Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:50:19 +0100 Subject: [PATCH 34/59] Change default canonical field to __createdAt As this is what is being null coalesced to in the creator action, plus it matches the pagination defaults --- .../Features/Publications/Models/PublicationType.php | 4 ++-- .../framework/tests/Feature/PublicationTypeTest.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index e376db9ac20..16ebafae71a 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -39,7 +39,7 @@ class PublicationType implements SerializableContract * The field name that is used as the canonical (or identifying) field of publications. * It's used primarily for generating filenames, and the publications must thus be unique by this field. */ - public string $canonicalField = 'identifier'; + public string $canonicalField = '__createdAt'; /** The Blade filename or view identifier used for rendering a single publication */ public string $detailTemplate = 'detail.blade.php'; @@ -79,7 +79,7 @@ public static function fromFile(string $schemaFile): static public function __construct( string $name, - string $canonicalField = 'identifier', + string $canonicalField = '__createdAt', string $detailTemplate = 'detail.blade.php', string $listTemplate = 'list.blade.php', ?array $pagination = [], diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 78b9fbba119..c6d90f2ccbc 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -43,7 +43,7 @@ public function test_construct_with_default_values() $publicationType = new PublicationType('Test Publication'); $this->assertEquals('Test Publication', $publicationType->name); - $this->assertEquals('identifier', $publicationType->canonicalField); + $this->assertEquals('__createdAt', $publicationType->canonicalField); $this->assertEquals('detail.blade.php', $publicationType->detailTemplate); $this->assertEquals('list.blade.php', $publicationType->listTemplate); $this->assertEquals([], $publicationType->fields); @@ -401,7 +401,7 @@ public function testArrayRepresentationWithDefaultValues() $this->assertSame([ 'name' => 'test-publication', - 'canonicalField' => 'identifier', + 'canonicalField' => '__createdAt', 'detailTemplate' => 'detail.blade.php', 'listTemplate' => 'list.blade.php', 'fields' => [], @@ -415,7 +415,7 @@ public function testJsonRepresentationWithDefaultValues() $this->assertSame(<<<'JSON' { "name": "test-publication", - "canonicalField": "identifier", + "canonicalField": "__createdAt", "detailTemplate": "detail.blade.php", "listTemplate": "list.blade.php", "fields": [] @@ -429,7 +429,7 @@ public function testArrayRepresentationWithPaginationSettings() $this->assertSame([ 'name' => 'test-publication', - 'canonicalField' => 'identifier', + 'canonicalField' => '__createdAt', 'detailTemplate' => 'detail.blade.php', 'listTemplate' => 'list.blade.php', 'pagination' => [ @@ -448,7 +448,7 @@ public function testJsonRepresentationWithPaginationSettings() $this->assertSame(<<<'JSON' { "name": "test-publication", - "canonicalField": "identifier", + "canonicalField": "__createdAt", "detailTemplate": "detail.blade.php", "listTemplate": "list.blade.php", "pagination": { From 96e64522648b4fa5272dc8d29c711ac296050c7a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 17:55:15 +0100 Subject: [PATCH 35/59] Deprecate helper method (and the fixture) --- packages/testing/src/TestCase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/testing/src/TestCase.php b/packages/testing/src/TestCase.php index 75507907378..0cb042c9f06 100644 --- a/packages/testing/src/TestCase.php +++ b/packages/testing/src/TestCase.php @@ -48,6 +48,7 @@ protected function tearDown(): void parent::tearDown(); } + /** @deprecated as it's probably better to do this via the object constructor */ protected function setupTestPublication(string $directory = 'test-publication') { Filesystem::copy('tests/fixtures/test-publication-schema.json', "$directory/schema.json"); From 1f50e41e28b2e6d2f721b72f9545f0687d4713f7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:33:19 +0100 Subject: [PATCH 36/59] Add newline to PHPDoc comment --- .../Framework/Features/Publications/Models/PublicationType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 16ebafae71a..0f50042ecdb 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -37,6 +37,7 @@ class PublicationType implements SerializableContract /** * The field name that is used as the canonical (or identifying) field of publications. + * * It's used primarily for generating filenames, and the publications must thus be unique by this field. */ public string $canonicalField = '__createdAt'; From 322f51d102e804c7b359339442f981fa45562ba7 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 8 Jan 2023 17:33:43 +0000 Subject: [PATCH 37/59] Apply fixes from StyleCI --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 0f50042ecdb..339f58e8193 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -37,7 +37,7 @@ class PublicationType implements SerializableContract /** * The field name that is used as the canonical (or identifying) field of publications. - * + * * It's used primarily for generating filenames, and the publications must thus be unique by this field. */ public string $canonicalField = '__createdAt'; From f47d697a745ceef6dc764110966556718be66302 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:34:50 +0100 Subject: [PATCH 38/59] Deprecate getFieldData method --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 339f58e8193..b5d271dc971 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -132,7 +132,7 @@ public function getDirectory(): string /** * Get the raw field definitions for this publication type. * - * @see self::getFields() to get the deserialized field definitions. + * @deprecated Use getFields() instead */ public function getFieldData(): array { From c94a528c6a4026758cdc51b9e0235b9d0416d035 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:38:05 +0100 Subject: [PATCH 39/59] Refactor internal field data state to be parsed Makes it impossible to create an invalid schema only to not realize it until later. Also removes the duplicate getters which is just confusing. --- .../Publications/Models/PublicationType.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index b5d271dc971..727901bdf73 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -54,9 +54,9 @@ class PublicationType implements SerializableContract /** * The front matter fields used for the publications. * - * @var array> + * @var \Illuminate\Support\Collection */ - public array $fields = []; + public Collection $fields; /** The directory of the publication files */ protected string $directory; @@ -91,7 +91,7 @@ public function __construct( $this->canonicalField = $canonicalField; $this->detailTemplate = $detailTemplate; $this->listTemplate = $listTemplate; - $this->fields = $fields; + $this->fields = $this->parseFieldData($fields); $this->directory = $directory ?? Str::slug($name); $this->pagination = $this->evaluatePaginationSettings($pagination); } @@ -148,9 +148,7 @@ public function getFieldData(): array */ public function getFields(): Collection { - return Collection::make($this->fields)->mapWithKeys(function (array $data): array { - return [$data['name'] => new PublicationFieldDefinition(...$data)]; - }); + return $this->fields; } public function getFieldDefinition(string $fieldName): PublicationFieldDefinition @@ -216,6 +214,13 @@ protected function getPublicationsSortedByPaginationField(): Collection }, descending: ! $this->pagination->sortAscending)->values(); } + protected function parseFieldData(array $fields): Collection + { + return Collection::make($fields)->mapWithKeys(function (array $data): array { + return [$data['name'] => new PublicationFieldDefinition(...$data)]; + }); + } + protected function evaluatePaginationSettings(array $pagination): ?PaginationSettings { if (empty($pagination)) { From 954a6cf13fffa49f79f9bbf9d2c9b870b737797d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:39:13 +0100 Subject: [PATCH 40/59] Temporarily map without key for compatibility during refactor --- .../Features/Publications/Models/PublicationType.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 727901bdf73..4edb5eb2aae 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -216,6 +216,11 @@ protected function getPublicationsSortedByPaginationField(): Collection protected function parseFieldData(array $fields): Collection { + return Collection::make($fields)->map(function (array $data): PublicationFieldDefinition { + return new PublicationFieldDefinition(...$data); + }); + + // FIXME return Collection::make($fields)->mapWithKeys(function (array $data): array { return [$data['name'] => new PublicationFieldDefinition(...$data)]; }); From 4ab5570fa266a6d8cc9b526d3cc59a58745f96f9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:42:51 +0100 Subject: [PATCH 41/59] Array fields when arraying --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 4edb5eb2aae..2598885e3b7 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -104,7 +104,7 @@ public function toArray(): array 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, 'pagination' => $this->pagination?->toArray(), - 'fields' => $this->fields, + 'fields' => $this->fields->toArray(), ]); } From 4fd7175b13e78993fe76f6217f4b97ef79e84aa6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:44:45 +0100 Subject: [PATCH 42/59] Swap order to match actual Since the parsed value is sorted by object --- packages/framework/tests/Feature/PublicationTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index c6d90f2ccbc..d6f782f1dd2 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -475,8 +475,8 @@ protected function getTestData(array $mergeData = []): array ], 'fields' => [ [ - 'name' => 'title', 'type' => 'string', + 'name' => 'title', ], ], ], $mergeData); From dd5170bdb738548830b7391fb2dcb37994dd9942 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:46:20 +0100 Subject: [PATCH 43/59] Revert "Temporarily map without key for compatibility during refactor" This reverts commit 954a6cf13fffa49f79f9bbf9d2c9b870b737797d. --- .../Features/Publications/Models/PublicationType.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 2598885e3b7..387f6994026 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -216,11 +216,6 @@ protected function getPublicationsSortedByPaginationField(): Collection protected function parseFieldData(array $fields): Collection { - return Collection::make($fields)->map(function (array $data): PublicationFieldDefinition { - return new PublicationFieldDefinition(...$data); - }); - - // FIXME return Collection::make($fields)->mapWithKeys(function (array $data): array { return [$data['name'] => new PublicationFieldDefinition(...$data)]; }); From cdec538e1044f3552d7d42f71c4907d30fd8e828 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:46:49 +0100 Subject: [PATCH 44/59] Serialize fields without keys --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 387f6994026..af66c5c3234 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -104,7 +104,7 @@ public function toArray(): array 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, 'pagination' => $this->pagination?->toArray(), - 'fields' => $this->fields->toArray(), + 'fields' => $this->fields->values()->toArray(), ]); } From 628a42eec0b5d657075b394216dd2e9eb542fd91 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:48:04 +0100 Subject: [PATCH 45/59] Replace usage of deprecated method that will now probably need fixing --- .../src/Console/Commands/ValidatePublicationsCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php b/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php index 87c5f7dcfa3..3387eff11e5 100644 --- a/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php +++ b/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php @@ -67,7 +67,7 @@ public function safeHandle(): int $this->output->write("\n Validating publication [$publication->title]"); $publication->matter->forget('__createdAt'); - foreach ($publication->type->getFieldData() as $field) { + foreach ($publication->type->getFields() as $field) { // FIXME this probably needs fixing as it expected array before $countFields++; $fieldName = $field['name']; $pubTypeField = new PublicationFieldDefinition($field['type'], $fieldName); From de3d635c34f07b48f401d1997d7cd9a3771ad690 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:48:46 +0100 Subject: [PATCH 46/59] Remove deprecated getFieldData method --- .../Features/Publications/Models/PublicationType.php | 12 ------------ .../framework/tests/Feature/PublicationTypeTest.php | 11 ----------- 2 files changed, 23 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index af66c5c3234..b34a17d0e1d 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -129,21 +129,9 @@ public function getDirectory(): string return $this->directory; } - /** - * Get the raw field definitions for this publication type. - * - * @deprecated Use getFields() instead - */ - public function getFieldData(): array - { - return $this->fields; - } - /** * Get the publication fields, deserialized to PublicationFieldDefinition objects. * - * @see self::getFieldData() to get the raw field definitions. - * * @return \Illuminate\Support\Collection */ public function getFields(): Collection diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index d6f782f1dd2..4273b80d34e 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -204,17 +204,6 @@ public function test_get_field_method_parses_publication_fields_with_option_prop ]), $publicationType->getFields()); } - public function test_get_field_data_returns_field_data() - { - $publicationType = new PublicationType(...$this->getTestData()); - - $this->assertSame([['name' => 'title', 'type' => 'string']], $publicationType->getFieldData()); - - $publicationType->fields = []; - - $this->assertSame([], $publicationType->getFieldData()); - } - public function test_get_method_can_find_existing_file_on_disk() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); From 5023367d053f2c98e2c19deb7bc6010642c7b683 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:50:21 +0100 Subject: [PATCH 47/59] Fix up constructor tests --- packages/framework/tests/Feature/PublicationTypeTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 4273b80d34e..52baed43415 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -33,7 +33,11 @@ public function test_can_construct_new_publication_type() if ($key === 'pagination') { $this->assertEquals($property, $publicationType->$key->toArray()); } else { - $this->assertEquals($property, $publicationType->$key); + if ($key === 'fields') { + $this->assertEquals($property, $publicationType->$key->values()->toArray()); + } else { + $this->assertEquals($property, $publicationType->$key); + } } } } @@ -46,7 +50,7 @@ public function test_construct_with_default_values() $this->assertEquals('__createdAt', $publicationType->canonicalField); $this->assertEquals('detail.blade.php', $publicationType->detailTemplate); $this->assertEquals('list.blade.php', $publicationType->listTemplate); - $this->assertEquals([], $publicationType->fields); + $this->assertEquals(collect([]), $publicationType->fields); $this->assertNull($publicationType->pagination); $this->assertEquals('test-publication', $publicationType->getDirectory()); From 3396909444288818389c21750bc8f3442b9c4e01 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:51:21 +0100 Subject: [PATCH 48/59] Arbitrary field data that cannot be used anyway is now not supported anymore --- .../tests/Feature/PublicationTypeTest.php | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 52baed43415..e0a518e5e48 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -134,32 +134,6 @@ public function test_can_load_from_json_file() $this->assertEquals($publicationType, PublicationType::fromFile(('tests/fixtures/test-publication-schema.json'))); } - public function test_it_loads_arbitrary_publication_fields_from_schema_file() - { - $this->directory('test-publication'); - $fields = [ - [ - 'name' => 'Title', - 'type' => 'text', - 'identifier' => 'title', - 'required' => true, - ], - [ - 'name' => 'Body', - 'type' => 'markdown', - 'identifier' => 'body', - 'required' => true, - ], - ]; - $this->file('test-publication/schema.json', json_encode([ - 'name' => 'Test Publication', - 'fields' => $fields, - ])); - - $publicationType = PublicationType::fromFile('test-publication/schema.json'); - $this->assertSame($fields, $publicationType->fields); - } - public function test_get_fields_method_returns_collection_of_field_objects() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); From 091f2e22e297232932a1584fdec82c5ad9bb07f4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:53:28 +0100 Subject: [PATCH 49/59] Test can load fields with validation rules --- .../tests/Feature/PublicationTypeTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index e0a518e5e48..80b6c0f7007 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -134,6 +134,25 @@ public function test_can_load_from_json_file() $this->assertEquals($publicationType, PublicationType::fromFile(('tests/fixtures/test-publication-schema.json'))); } + public function test_can_load_fields_with_validation_rules() + { + $this->directory('test-publication'); + $fields = [ + [ + 'type' => 'text', + 'name' => 'title', + 'rules' => ['required'], + ], + ]; + $this->file('test-publication/schema.json', json_encode([ + 'name' => 'Test Publication', + 'fields' => $fields, + ])); + + $publicationType = PublicationType::fromFile('test-publication/schema.json'); + $this->assertSame($fields, $publicationType->getFields()->values()->toArray()); + } + public function test_get_fields_method_returns_collection_of_field_objects() { $publicationType = new PublicationType(...$this->getTestDataWithPathInformation()); From 76b33b9d10a42aeb0c37eb9216402ada16ef9868 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 18:53:57 +0100 Subject: [PATCH 50/59] Add todo --- .../Framework/Features/Publications/Models/PublicationType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index b34a17d0e1d..d5539d50929 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -204,6 +204,7 @@ protected function getPublicationsSortedByPaginationField(): Collection protected function parseFieldData(array $fields): Collection { + // FIXME check if we actually need the named key, as that adds complexity and the need to call ->values() return Collection::make($fields)->mapWithKeys(function (array $data): array { return [$data['name'] => new PublicationFieldDefinition(...$data)]; }); From 0c5bd4e1da8eeac3057c8401bc1156e6194afd65 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 19:27:11 +0100 Subject: [PATCH 51/59] Update test for changed internal data structure --- .../Feature/Actions/SeedsPublicationFilesTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/framework/tests/Feature/Actions/SeedsPublicationFilesTest.php b/packages/framework/tests/Feature/Actions/SeedsPublicationFilesTest.php index b2517f09219..d5e91b8028c 100644 --- a/packages/framework/tests/Feature/Actions/SeedsPublicationFilesTest.php +++ b/packages/framework/tests/Feature/Actions/SeedsPublicationFilesTest.php @@ -133,9 +133,9 @@ public function testWithTagType() { $tags = ['test-publication' => ['foo', 'bar', 'baz']]; $this->file('tags.json', json_encode($tags)); - $this->pubType->fields = [ - (new PublicationFieldDefinition('tag', 'tag', tagGroup: 'test-publication'))->toArray(), - ]; + $this->pubType->fields = collect([ + (new PublicationFieldDefinition('tag', 'tag', tagGroup: 'test-publication')), + ]); $this->pubType->save(); (new SeedsPublicationFiles($this->pubType))->create(); @@ -187,9 +187,9 @@ protected function firstPublication(): MarkdownDocument protected function updateSchema(string $type, string $name): void { - $this->pubType->fields = [ - (new PublicationFieldDefinition($type, $name))->toArray(), - ]; + $this->pubType->fields = collect([ + (new PublicationFieldDefinition($type, $name)), + ]); $this->pubType->save(); } From b9e0999733d43aa3586888e7f2610285ddb6bc2e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 19:30:09 +0100 Subject: [PATCH 52/59] Update validate command to use new collection structure --- .../src/Console/Commands/ValidatePublicationsCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php b/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php index 3387eff11e5..3e1cb0cad4b 100644 --- a/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php +++ b/packages/framework/src/Console/Commands/ValidatePublicationsCommand.php @@ -67,10 +67,10 @@ public function safeHandle(): int $this->output->write("\n Validating publication [$publication->title]"); $publication->matter->forget('__createdAt'); - foreach ($publication->type->getFields() as $field) { // FIXME this probably needs fixing as it expected array before + foreach ($publication->type->getFields() as $field) { $countFields++; - $fieldName = $field['name']; - $pubTypeField = new PublicationFieldDefinition($field['type'], $fieldName); + $fieldName = $field->name; + $pubTypeField = new PublicationFieldDefinition($field->type, $fieldName); try { if ($verbose) { From 89720cc054502eb084b25e4c4f8930612a344044 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 19:35:23 +0100 Subject: [PATCH 53/59] Use proper field structure for test --- packages/framework/tests/Feature/PublicationListPageTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index b8945bbb80b..907f28fa757 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -76,7 +76,10 @@ protected function getTestData(): array 'pageSize' => 10, ], 'fields' => [ - 'foo' => 'bar', + [ + 'type' => 'string', + 'name' => 'Foo', + ] ], ]; } From 3b34071c77f243dc82b8c4afd23ac1c6a24ea706 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 8 Jan 2023 18:35:38 +0000 Subject: [PATCH 54/59] Apply fixes from StyleCI --- packages/framework/tests/Feature/PublicationListPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 907f28fa757..2740af557b8 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -79,7 +79,7 @@ protected function getTestData(): array [ 'type' => 'string', 'name' => 'Foo', - ] + ], ], ]; } From c20eea14ef87285d3defd11eead31eaad12f94cf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 20:16:54 +0100 Subject: [PATCH 55/59] Revert "Revert "Temporarily map without key for compatibility during refactor"" This reverts commit dd5170bdb738548830b7391fb2dcb37994dd9942. --- .../Features/Publications/Models/PublicationType.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index d5539d50929..0d0f4d49811 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -204,6 +204,10 @@ protected function getPublicationsSortedByPaginationField(): Collection protected function parseFieldData(array $fields): Collection { + return Collection::make($fields)->map(function (array $data): PublicationFieldDefinition { + return new PublicationFieldDefinition(...$data); + }); + // FIXME check if we actually need the named key, as that adds complexity and the need to call ->values() return Collection::make($fields)->mapWithKeys(function (array $data): array { return [$data['name'] => new PublicationFieldDefinition(...$data)]; From 4fe1e8b47b238c1842d12a35e9f471a76254fde5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 20:17:49 +0100 Subject: [PATCH 56/59] Remove expectations for array keys --- .../framework/tests/Feature/PublicationTypeTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 80b6c0f7007..3c0ce567b56 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -161,7 +161,7 @@ public function test_get_fields_method_returns_collection_of_field_objects() $this->assertInstanceOf(Collection::class, $collection); $this->assertInstanceOf(PublicationFieldDefinition::class, $collection->first()); $this->assertEquals(new Collection([ - 'title' => new PublicationFieldDefinition('string', 'title'), + new PublicationFieldDefinition('string', 'title'), ]), $collection); } @@ -178,8 +178,8 @@ public function test_get_field_method_parses_publication_fields_from_schema_file $publicationType = PublicationType::fromFile('test-publication/schema.json'); $this->assertEquals(new Collection([ - 'title' => new PublicationFieldDefinition('string', 'title'), - 'number' => new PublicationFieldDefinition('integer', 'number'), + new PublicationFieldDefinition('string', 'title'), + new PublicationFieldDefinition('integer', 'number'), ]), $publicationType->getFields()); } @@ -196,8 +196,8 @@ public function test_get_field_method_parses_publication_fields_with_option_prop $publicationType = PublicationType::fromFile('test-publication/schema.json'); $this->assertEquals(new Collection([ - 'title' => new PublicationFieldDefinition('string', 'title', ['foo', 'bar']), - 'tags' => new PublicationFieldDefinition('tag', 'tags', tagGroup: 'myTags'), + new PublicationFieldDefinition('string', 'title', ['foo', 'bar']), + new PublicationFieldDefinition('tag', 'tags', tagGroup: 'myTags'), ]), $publicationType->getFields()); } From d1f5d537e7611089f96e1de388baebadace73844 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 20:21:12 +0100 Subject: [PATCH 57/59] Revert "Revert "Revert "Temporarily map without key for compatibility during refactor""" This reverts commit c20eea14ef87285d3defd11eead31eaad12f94cf. --- .../Features/Publications/Models/PublicationType.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 0d0f4d49811..d5539d50929 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -204,10 +204,6 @@ protected function getPublicationsSortedByPaginationField(): Collection protected function parseFieldData(array $fields): Collection { - return Collection::make($fields)->map(function (array $data): PublicationFieldDefinition { - return new PublicationFieldDefinition(...$data); - }); - // FIXME check if we actually need the named key, as that adds complexity and the need to call ->values() return Collection::make($fields)->mapWithKeys(function (array $data): array { return [$data['name'] => new PublicationFieldDefinition(...$data)]; From d9be7cbcc64ca15103d503364ebb47c802517ffe Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 20:22:18 +0100 Subject: [PATCH 58/59] Remove array keys from the field collection as they're not used anywhere and add complexity without value They are only expected in a single test file and never actually used. They also don't offer any new information since the name is present within the value. --- .../Features/Publications/Models/PublicationType.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index d5539d50929..14930ab3b29 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -204,9 +204,8 @@ protected function getPublicationsSortedByPaginationField(): Collection protected function parseFieldData(array $fields): Collection { - // FIXME check if we actually need the named key, as that adds complexity and the need to call ->values() - return Collection::make($fields)->mapWithKeys(function (array $data): array { - return [$data['name'] => new PublicationFieldDefinition(...$data)]; + return Collection::make($fields)->map(function (array $data): PublicationFieldDefinition { + return new PublicationFieldDefinition(...$data); }); } From 12810541a1b2c6978d86b6e6e3e783a72a6454c7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Jan 2023 20:24:13 +0100 Subject: [PATCH 59/59] Remove ->values calls that are no longer needed See d9be7cbcc64ca15103d503364ebb47c802517ffe --- .../Features/Publications/Models/PublicationType.php | 2 +- packages/framework/tests/Feature/PublicationTypeTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 14930ab3b29..df05dc5331c 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -104,7 +104,7 @@ public function toArray(): array 'detailTemplate' => $this->detailTemplate, 'listTemplate' => $this->listTemplate, 'pagination' => $this->pagination?->toArray(), - 'fields' => $this->fields->values()->toArray(), + 'fields' => $this->fields->toArray(), ]); } diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index 3c0ce567b56..0f77854c031 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -34,7 +34,7 @@ public function test_can_construct_new_publication_type() $this->assertEquals($property, $publicationType->$key->toArray()); } else { if ($key === 'fields') { - $this->assertEquals($property, $publicationType->$key->values()->toArray()); + $this->assertEquals($property, $publicationType->$key->toArray()); } else { $this->assertEquals($property, $publicationType->$key); } @@ -150,7 +150,7 @@ public function test_can_load_fields_with_validation_rules() ])); $publicationType = PublicationType::fromFile('test-publication/schema.json'); - $this->assertSame($fields, $publicationType->getFields()->values()->toArray()); + $this->assertSame($fields, $publicationType->getFields()->toArray()); } public function test_get_fields_method_returns_collection_of_field_objects()