From fce823abcc719280f61fbc0efef6de7655a4de3b Mon Sep 17 00:00:00 2001 From: Neo Lejondahl <64473191+NeoIsRecursive@users.noreply.github.com> Date: Mon, 4 Dec 2023 21:16:31 +0100 Subject: [PATCH 001/117] [4.x] Make url and uri available in preview targets (#9104) Co-authored-by: Duncan McClean --- src/Entries/Entry.php | 2 ++ tests/Data/Entries/EntryTest.php | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php index c330345cc4..43db0382e1 100644 --- a/src/Entries/Entry.php +++ b/src/Entries/Entry.php @@ -947,6 +947,8 @@ private function resolvePreviewTargetUrl($format) return (string) Antlers::parse($format, array_merge($this->routeData(), [ 'site' => $this->site(), + 'uri' => $this->uri(), + 'url' => $this->url(), 'permalink' => $this->absoluteUrl(), 'locale' => $this->locale(), ])); diff --git a/tests/Data/Entries/EntryTest.php b/tests/Data/Entries/EntryTest.php index 2e38b0ad3c..2f00200244 100644 --- a/tests/Data/Entries/EntryTest.php +++ b/tests/Data/Entries/EntryTest.php @@ -2192,6 +2192,7 @@ public function it_gets_preview_targets() 'fr' => 'le-blog/{slug}', 'de' => 'das-blog/{slug}', ]); + $collection->save(); $entryEn = (new Entry)->collection($collection)->locale('en')->slug('foo')->date('2014-01-01'); @@ -2229,6 +2230,27 @@ public function it_gets_preview_targets() ['label' => 'Index', 'format' => 'http://preview.com/{locale}/{year}/blog?preview=true', 'url' => 'http://preview.com/de/2016/blog?preview=true'], ['label' => 'Show', 'format' => 'http://preview.com/{locale}/{year}/blog/{slug}?preview=true', 'url' => 'http://preview.com/de/2016/blog/das-foo?preview=true'], ], $entryDe->previewTargets()->all()); + + $collection->previewTargets([ + ['label' => 'url', 'format' => 'http://preview.domain.com/preview?url={url}', 'refresh' => false], + ['label' => 'uri', 'format' => 'http://preview.domain.com/preview?uri={uri}', 'refresh' => false], + ]); + $collection->save(); + + $this->assertEquals([ + ['label' => 'url', 'format' => 'http://preview.domain.com/preview?url={url}', 'url' => 'http://preview.domain.com/preview?url=/blog/foo'], + ['label' => 'uri', 'format' => 'http://preview.domain.com/preview?uri={uri}', 'url' => 'http://preview.domain.com/preview?uri=/blog/foo'], + ], $entryEn->previewTargets()->all()); + + $this->assertEquals([ + ['label' => 'url', 'format' => 'http://preview.domain.com/preview?url={url}', 'url' => 'http://preview.domain.com/preview?url=/fr/le-blog/le-foo'], + ['label' => 'uri', 'format' => 'http://preview.domain.com/preview?uri={uri}', 'url' => 'http://preview.domain.com/preview?uri=/le-blog/le-foo'], + ], $entryFr->previewTargets()->all()); + + $this->assertEquals([ + ['label' => 'url', 'format' => 'http://preview.domain.com/preview?url={url}', 'url' => 'http://preview.domain.com/preview?url=/das-blog/das-foo'], + ['label' => 'uri', 'format' => 'http://preview.domain.com/preview?uri={uri}', 'url' => 'http://preview.domain.com/preview?uri=/das-blog/das-foo'], + ], $entryDe->previewTargets()->all()); } /** @test */ From 14667208867fa5aaee32bdd2aa75ee196b610147 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Mon, 4 Dec 2023 20:17:19 +0000 Subject: [PATCH 002/117] [4.x] Harden collection handle check in Taxonomy::findByUri to prevent partial matches (#9108) --- src/Stache/Repositories/TaxonomyRepository.php | 2 +- src/Stache/Repositories/TermRepository.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Stache/Repositories/TaxonomyRepository.php b/src/Stache/Repositories/TaxonomyRepository.php index 2ac3c7a613..d24e010576 100644 --- a/src/Stache/Repositories/TaxonomyRepository.php +++ b/src/Stache/Repositories/TaxonomyRepository.php @@ -67,7 +67,7 @@ public function findByUri(string $uri, string $site = null): ?Taxonomy return true; } - return Str::startsWith($uri, '/'.$collection->handle()); + return Str::startsWith($uri.'/', '/'.$collection->handle().'/'); }); if ($collection) { diff --git a/src/Stache/Repositories/TermRepository.php b/src/Stache/Repositories/TermRepository.php index c91c379ac1..e29acfc6d8 100644 --- a/src/Stache/Repositories/TermRepository.php +++ b/src/Stache/Repositories/TermRepository.php @@ -59,7 +59,7 @@ public function findByUri(string $uri, string $site = null): ?Term return true; } - return Str::startsWith($uri, '/'.$collection->handle()); + return Str::startsWith($uri.'/', '/'.$collection->handle().'/'); }); if ($collection) { From 1cca34f4a9a4e2ed4af5219886709ff79fc563de Mon Sep 17 00:00:00 2001 From: Duncan McClean <19637309+duncanmcclean@users.noreply.github.com> Date: Mon, 4 Dec 2023 20:21:12 +0000 Subject: [PATCH 003/117] [4.x] Fix "Hide Display" setting not being persisted on reference field (#9111) --- .../components/fieldtypes/FieldDisplayFieldtype.vue | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/resources/js/components/fieldtypes/FieldDisplayFieldtype.vue b/resources/js/components/fieldtypes/FieldDisplayFieldtype.vue index 60e31e2227..f127ebcd50 100644 --- a/resources/js/components/fieldtypes/FieldDisplayFieldtype.vue +++ b/resources/js/components/fieldtypes/FieldDisplayFieldtype.vue @@ -47,8 +47,17 @@ export default { return parent; }, + nearestFieldSettings() { + let parent = this; + while (parent.$options._componentTag !== 'field-settings') { + parent = parent.$parent; + if (parent === this.$root) return null; + } + return parent; + }, + hidden() { - return this.$store.state.publish[this.storeName].values.hide_display; + return this.nearestFieldSettings.values.hide_display; } }, @@ -60,7 +69,7 @@ export default { methods: { toggleHidden() { - this.nearestPublishContainer.setFieldValue('hide_display', ! this.hidden); + this.nearestFieldSettings.updateField('hide_display', ! this.hidden) } } From d978f44b0f9cf13e99406c7c3f698e4dd48e78d7 Mon Sep 17 00:00:00 2001 From: John Koster Date: Mon, 4 Dec 2023 15:09:45 -0600 Subject: [PATCH 004/117] [4.x] Antlers: corrects a subtle bug with conditions resolving variables (#9106) --- .../Language/Parser/AntlersNodeParser.php | 10 ++++- tests/Antlers/Parser/ConditionalNodesTest.php | 3 +- tests/Antlers/Runtime/ConditionLogicTest.php | 42 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/View/Antlers/Language/Parser/AntlersNodeParser.php b/src/View/Antlers/Language/Parser/AntlersNodeParser.php index 6709b7ba4f..b7e83abefe 100644 --- a/src/View/Antlers/Language/Parser/AntlersNodeParser.php +++ b/src/View/Antlers/Language/Parser/AntlersNodeParser.php @@ -243,8 +243,16 @@ public function parseNode(AntlersNode $node) $node->isClosingTag = $this->canBeClosingTag($node); + $lexerContent = $node->getContent(); + + if ($node->name->name == 'if' || $node->name->name == 'unless' || $node->name->name == 'elseif') { + if (mb_strlen(trim($lexerContent)) > 0) { + $lexerContent = '('.$lexerContent.')'; + } + } + // Need to run node type analysis here before the runtime node step. - $runtimeNodes = $this->lexer->tokenize($node, $node->getContent()); + $runtimeNodes = $this->lexer->tokenize($node, $lexerContent); $node->runtimeNodes = $runtimeNodes; diff --git a/tests/Antlers/Parser/ConditionalNodesTest.php b/tests/Antlers/Parser/ConditionalNodesTest.php index 607c777156..2065cab5ca 100644 --- a/tests/Antlers/Parser/ConditionalNodesTest.php +++ b/tests/Antlers/Parser/ConditionalNodesTest.php @@ -149,7 +149,8 @@ public function test_conditions_do_not_get_parsed_as_modifiers() /** @var AntlersNode $firstNode */ $firstNode = $nodes[0]; - $this->assertCount(7, $firstNode->runtimeNodes); + // The () are added automatically. + $this->assertCount(9, $firstNode->runtimeNodes); // Parse the text that would produce the 7 runtime nodes above. $runtimeNodes = $this->getParsedRuntimeNodes("{{ is_small_article || collection:handle == 'vacancies' }}"); diff --git a/tests/Antlers/Runtime/ConditionLogicTest.php b/tests/Antlers/Runtime/ConditionLogicTest.php index e4089b94a1..a0834d7247 100644 --- a/tests/Antlers/Runtime/ConditionLogicTest.php +++ b/tests/Antlers/Runtime/ConditionLogicTest.php @@ -3,8 +3,10 @@ namespace Tests\Antlers\Runtime; use Facades\Tests\Factories\EntryFactory; +use Statamic\Fields\Field; use Statamic\Fields\LabeledValue; use Statamic\Fields\Value; +use Statamic\Fieldtypes\Code; use Statamic\Fieldtypes\Select; use Statamic\Support\Arr; use Statamic\Tags\Tags; @@ -13,9 +15,12 @@ use Statamic\View\Cascade; use Tests\Antlers\Fixtures\Addon\Tags\VarTest; use Tests\Antlers\ParserTestCase; +use Tests\FakesViews; class ConditionLogicTest extends ParserTestCase { + use FakesViews; + public function test_negation_following_or_is_evaluated() { $template = '{{ if !first && first_row_headers || !first_row_headers }}yes{{ else }}no{{ /if }}'; @@ -769,4 +774,41 @@ public function test_uppercase_logical_keywords_in_conditions() $this->assertSame('No', $this->renderString($template)); } + + public function test_arrayable_strings_inside_conditions_used_with_modifiers() + { + $code = new Code(); + $field = new Field('code_field', [ + 'type' => 'code', + 'antlers' => false, + ]); + + $code->setField($field); + $value = new Value('Oh hai, mark.', 'code_field', $code); + + $template = <<<'EOT' +{{ partial:test :code="code_field" }} +EOT; + + $this->withFakeViews(); + $this->viewShouldReturnRaw('test', <<<'EOT' +{{ if code | starts_with('
') }} +Yes{{ else }} +No{{ /if }} +EOT + + ); + + $this->assertSame('No', trim($this->renderString($template, ['code_field' => $value], true))); + + $this->viewShouldReturnRaw('test', <<<'EOT' +{{ if code | starts_with('Oh hai, mark.') }} +Yes{{ else }} +No{{ /if }} +EOT + + ); + + $this->assertSame('Yes', trim($this->renderString($template, ['code_field' => $value], true))); + } } From af45cab48e50454a5fe9cf0c93a9dcea3e1b024d Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Mon, 4 Dec 2023 21:11:18 +0000 Subject: [PATCH 005/117] [4.x] When appending glide filename consider that the extension may have changed (#9097) --- src/Imaging/GlideManager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Imaging/GlideManager.php b/src/Imaging/GlideManager.php index 4600044c2e..ad329c6eb4 100644 --- a/src/Imaging/GlideManager.php +++ b/src/Imaging/GlideManager.php @@ -47,6 +47,10 @@ public function server(array $config = []) $cachePath .= '/'.Str::beforeLast($filename, '.').'/'.Str::of($path)->after('/'); + if ($extension = ($params['fm'] ?? false)) { + $cachePath = Str::beforeLast($cachePath, '.').'.'.$extension; + } + return $cachePath; }); } From fe9e6932876557e4e4049071f516c46ae3f5f2c8 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 5 Dec 2023 14:17:46 +0000 Subject: [PATCH 006/117] [4.x] Fix for Can't add title to a fieldset and use fieldset prefixes at the same time (#9116) --- src/Fields/Blueprint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fields/Blueprint.php b/src/Fields/Blueprint.php index 12fa154021..fb297e5b95 100644 --- a/src/Fields/Blueprint.php +++ b/src/Fields/Blueprint.php @@ -257,7 +257,7 @@ private function addEnsuredFieldToContents($contents, $ensured) $field = $allFields->get($importKey); $tab = $field['tab']; $fields = collect($tabs[$tab]['sections'][$targetSectionIndex]['fields'])->keyBy(function ($field) { - return (isset($field['import'])) ? 'import:'.$field['import'] : $field['handle']; + return (isset($field['import'])) ? 'import:'.($field['prefix'] ?? null).$field['import'] : $field['handle']; }); $importedConfig = $importedField['field']->config(); $config = array_merge($config, $importedConfig); From 24ebdf6c0ede427d4486a9d2068feabaa1b793d5 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 5 Dec 2023 15:14:13 +0000 Subject: [PATCH 007/117] [4.x] Handle glide exceptions gracefully (#9109) Co-authored-by: Jason Varga --- src/Tags/Glide.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Tags/Glide.php b/src/Tags/Glide.php index 7fae863889..bfd584c92a 100644 --- a/src/Tags/Glide.php +++ b/src/Tags/Glide.php @@ -132,20 +132,24 @@ public function generate($items = null) $items = is_iterable($items) ? collect($items) : collect([$items]); return $items->map(function ($item) { - $data = ['url' => $this->generateGlideUrl($item)]; - - if ($this->isValidExtension($item)) { - $path = $this->generateImage($item); - $attrs = Attributes::from(GlideManager::cacheDisk(), $path); - $data = array_merge($data, $attrs); - } - - if ($item instanceof Augmentable) { - $data = array_merge($item->toAugmentedArray(), $data); + try { + $data = ['url' => $this->generateGlideUrl($item)]; + + if ($this->isValidExtension($item)) { + $path = $this->generateImage($item); + $attrs = Attributes::from(GlideManager::cacheDisk(), $path); + $data = array_merge($data, $attrs); + } + + if ($item instanceof Augmentable) { + $data = array_merge($item->toAugmentedArray(), $data); + } + + return $data; + } catch (\Exception $e) { + \Log::error($e->getMessage()); } - - return $data; - })->all(); + })->filter()->all(); } /** From 74aadb1ccee65646b20e155be7f39c7bb696aad8 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 5 Dec 2023 12:17:26 -0500 Subject: [PATCH 008/117] [4.x] Change nocache performance optimizations to be opt-in (#9124) --- src/StaticCaching/NoCache/Tags.php | 7 +++++-- tests/StaticCaching/NocacheTagsTest.php | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/StaticCaching/NoCache/Tags.php b/src/StaticCaching/NoCache/Tags.php index 90c0a8c721..60a08a7387 100644 --- a/src/StaticCaching/NoCache/Tags.php +++ b/src/StaticCaching/NoCache/Tags.php @@ -23,8 +23,11 @@ public function index() { if ($this->params->has('select')) { $fields = $this->params->explode('select'); - } elseif (config('statamic.antlers.version') === 'runtime') { - $fields = Antlers::identifiers($this->content); + + if (in_array('@auto', $fields)) { + $identifiers = Antlers::identifiers($this->content); + $fields = array_merge(array_diff($fields, ['@auto']), $identifiers); + } } return $this diff --git a/tests/StaticCaching/NocacheTagsTest.php b/tests/StaticCaching/NocacheTagsTest.php index f33f0314e8..5929cb2882 100644 --- a/tests/StaticCaching/NocacheTagsTest.php +++ b/tests/StaticCaching/NocacheTagsTest.php @@ -106,10 +106,13 @@ public function it_can_keep_nested_nocache_tags_dynamic_inside_cache_tags() /** @test */ public function it_only_adds_appropriate_fields_of_context_to_session() { - // We will not add `baz` to the session because it is not used in the template. - // We will not add `nope` to the session because it is not in the context. - $expectedFields = ['foo', 'bar']; - $template = '{{ nocache }}{{ foo }}{{ bar }}{{ nope }}{{ /nocache }}'; + $expectedFields = [ + 'foo', // By adding @auto it will be picked up from the template. + 'baz', // Explicitly selected + // 'bar' // Not explicitly selected + // 'nope' // Not in the context + ]; + $template = '{{ nocache select="@auto|baz" }}{{ foo }}{{ nope }}{{ /nocache }}'; $context = [ 'foo' => 'alfa', 'bar' => 'bravo', From 884852600c782c3340c08173658ffcb72078264b Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Tue, 5 Dec 2023 19:23:52 +0100 Subject: [PATCH 009/117] [4.x] Add Laravel Pulse link to global header (#9125) * Add link to global header and Pulse logo as SVG * Always show link in `local` environments --- resources/svg/icons/regular/pulse.svg | 4 ++++ resources/views/partials/global-header.blade.php | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 resources/svg/icons/regular/pulse.svg diff --git a/resources/svg/icons/regular/pulse.svg b/resources/svg/icons/regular/pulse.svg new file mode 100644 index 0000000000..28eb7d55ea --- /dev/null +++ b/resources/svg/icons/regular/pulse.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/resources/views/partials/global-header.blade.php b/resources/views/partials/global-header.blade.php index 9795eb1a6e..373c0137fc 100644 --- a/resources/views/partials/global-header.blade.php +++ b/resources/views/partials/global-header.blade.php @@ -36,6 +36,12 @@ @endif + @if (Route::has('pulse') && (app()->environment('local') || $user->can('viewPulse'))) + + @endif + @if (config('nova.path') && (app()->environment('local') || $user->can('viewNova')))
diff --git a/resources/views/partials/breadcrumb.blade.php b/resources/views/partials/breadcrumb.blade.php index 407a281ce3..37c253d957 100644 --- a/resources/views/partials/breadcrumb.blade.php +++ b/resources/views/partials/breadcrumb.blade.php @@ -3,6 +3,6 @@
@cp_svg('icons/micro/chevron-right')
- {{ $title }} + {{ $title }}
diff --git a/resources/views/partials/nav-main.blade.php b/resources/views/partials/nav-main.blade.php index 2940190062..fe4b03d51c 100644 --- a/resources/views/partials/nav-main.blade.php +++ b/resources/views/partials/nav-main.blade.php @@ -2,7 +2,7 @@ @section('nav-main')