From 0b63d8bfa5cc4acda4beb0aa8aedbbad889ea56a Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 28 Apr 2022 22:25:43 -0400 Subject: [PATCH 01/23] Change `read_only` toggle in field config to `visibility` select. --- .../Controllers/CP/Fields/FieldsController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Http/Controllers/CP/Fields/FieldsController.php b/src/Http/Controllers/CP/Fields/FieldsController.php index fa086199111..46a08ee4995 100644 --- a/src/Http/Controllers/CP/Fields/FieldsController.php +++ b/src/Http/Controllers/CP/Fields/FieldsController.php @@ -128,11 +128,16 @@ protected function blueprint($blueprint) 'type' => 'section', ], ], - 'read_only' => [ - 'display' => __('Read Only'), - 'instructions' => __('statamic::messages.fields_read_only_instructions'), - 'type' => 'toggle', - 'validate' => 'boolean', + 'visibility' => [ + 'display' => __('Visibility'), + 'instructions' => __('statamic::messages.fields_visibility_instructions'), + 'options' => [ + 'visible' => __('Visible'), + 'read_only' => __('Read Only'), + 'hidden' => __('Hidden'), + ], + 'default' => 'visible', + 'type' => 'select', 'width' => 33, ], ]); From 767faec3a34982bb4ca1028559456372dabb7070 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 28 Apr 2022 22:28:26 -0400 Subject: [PATCH 02/23] Normalize field visibility in `toPublishArray()`. --- src/Fields/Field.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 01c4335475a..38791b36003 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -88,6 +88,18 @@ public function instructions() return array_get($this->config, 'instructions'); } + public function visibility() + { + $visibility = array_get($this->config, 'visibility'); + $legacyReadOnly = array_get($this->config, 'read_only'); + + if ($legacyReadOnly && ! $visibility) { + return 'read_only'; + } + + return $visibility ?? 'visible'; + } + public function rules() { $rules = [$this->handle => $this->addNullableRule(array_merge( @@ -208,6 +220,7 @@ public function toPublishArray() 'display' => $this->display(), 'instructions' => $this->instructions(), 'required' => $this->isRequired(), + 'visibility' => $this->visibility(), ]); } From 10d8b85859f4d4750de952e2f58dc34bb5e0b17f Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 28 Apr 2022 22:29:16 -0400 Subject: [PATCH 03/23] Rename this method for clarity versus publish visibility. --- src/Fields/Blueprint.php | 4 ++-- src/Fields/Field.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Fields/Blueprint.php b/src/Fields/Blueprint.php index 586795a7027..c63f70848a7 100644 --- a/src/Fields/Blueprint.php +++ b/src/Fields/Blueprint.php @@ -329,8 +329,8 @@ public function columns() ->fieldtype($field->fieldtype()->indexComponent()) ->label(__($field->display())) ->listable($field->isListable()) - ->defaultVisibility($field->isVisible()) - ->visible($field->isVisible()) + ->defaultVisibility($field->isVisibleOnListing()) + ->visible($field->isVisibleOnListing()) ->sortable($field->isSortable()) ->defaultOrder($index + 1); }) diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 38791b36003..18841049073 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -184,7 +184,7 @@ public function isListable() return (bool) $this->get('listable'); } - public function isVisible() + public function isVisibleOnListing() { if (is_null($this->get('listable'))) { return in_array($this->handle, ['title', 'slug', 'date', 'author']); From eb63c0f2ad9907801479ecec3b176cfcddd43793 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 28 Apr 2022 22:30:01 -0400 Subject: [PATCH 04/23] Update English instruction text. --- resources/lang/en/messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 5c4b8073528..8e27a31697d 100644 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -71,7 +71,7 @@ 'fields_instructions_instructions' => 'Shown under the field\'s display label, like this very text. Markdown is supported.', 'fields_instructions_position_instructions' => 'Show instructions above or below the field.', 'fields_listable_instructions' => 'Control the listing column visibility.', - 'fields_read_only_instructions' => 'Disable editing in the control panel.', + 'fields_visibility_instructions' => 'Control field visibility on publish forms.', 'fieldset_import_fieldset_instructions' => 'The fieldset to be imported.', 'fieldset_import_prefix_instructions' => 'The prefix that should be applied to each field when they are imported. eg. hero_', 'fieldset_intro' => 'Fieldsets are an optional companion to blueprints, acting as reusable partials that can be used within blueprints.', From 1e38ca63610dbe3abb08aff4a4e9917ed21172e5 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 28 Apr 2022 22:32:17 -0400 Subject: [PATCH 05/23] Use new `visibility` read only state on publish forms. --- resources/js/components/publish/Field.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/components/publish/Field.vue b/resources/js/components/publish/Field.vue index 600c4b33828..5a30fd8bb80 100644 --- a/resources/js/components/publish/Field.vue +++ b/resources/js/components/publish/Field.vue @@ -139,7 +139,7 @@ export default { isReadOnly() { if (this.storeState.isRoot === false && !this.config.localizable) return true; - return this.isLocked || this.readOnly || this.config.read_only || false; + return this.isLocked || this.readOnly || this.config.visibility === 'read_only' || false; }, isLocalizable() { From 5b75060fb18a65fdd2250d490f82d7843c0d91df Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 28 Apr 2022 22:40:45 -0400 Subject: [PATCH 06/23] Normalize visibility in field transformer for blueprint edit form, etc. --- src/Fields/FieldTransformer.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Fields/FieldTransformer.php b/src/Fields/FieldTransformer.php index c391bf96d9e..5e2850cb086 100644 --- a/src/Fields/FieldTransformer.php +++ b/src/Fields/FieldTransformer.php @@ -92,6 +92,7 @@ private static function inlineFieldToVue($field): array $config['width'] = $config['width'] ?? 100; $config['localizable'] = $config['localizable'] ?? false; $config = static::normalizeRequiredValidation($config); + $config = static::normalizeVisibility($config); return [ 'handle' => $field['handle'], @@ -158,4 +159,17 @@ protected static function normalizeRequiredValidation($config) return $config; } + + protected static function normalizeVisibility($config) + { + $legacyReadOnly = Arr::pull($config, 'read_only'); + + $visibility = Arr::get($config, 'visibility'); + + if ($legacyReadOnly && ! $visibility) { + $config['visibility'] = 'read_only'; + } + + return $config; + } } From 6d17e5ecd34646e2447240ccae221053730bccc1 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 28 Apr 2022 22:47:56 -0400 Subject: [PATCH 07/23] Wire up `hidden` visibility state on publish forms. --- resources/js/components/publish/Field.vue | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/js/components/publish/Field.vue b/resources/js/components/publish/Field.vue index 5a30fd8bb80..ba8bd7232e9 100644 --- a/resources/js/components/publish/Field.vue +++ b/resources/js/components/publish/Field.vue @@ -4,6 +4,7 @@ :config="config" :initial-value="value" :initial-meta="meta" + v-if="isVisible" >
@@ -142,6 +143,10 @@ export default { return this.isLocked || this.readOnly || this.config.visibility === 'read_only' || false; }, + isVisible() { + return this.config.visibility !== 'hidden'; + }, + isLocalizable() { return this.$config.get('sites').length > 1 && this.config.localizable; }, From c0845035ae3ea1dce72b7b3bbfe903229bf95325 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 11:13:57 -0400 Subject: [PATCH 08/23] Clean up fallback logic for old `read_only` boolean config. --- src/Fields/Field.php | 5 +++-- src/Fields/FieldTransformer.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 18841049073..2c80d6476ec 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -90,8 +90,9 @@ public function instructions() public function visibility() { - $visibility = array_get($this->config, 'visibility'); - $legacyReadOnly = array_get($this->config, 'read_only'); + $visibility = Arr::get($this->config, 'visibility'); + + $legacyReadOnly = Arr::get($this->config, 'read_only'); if ($legacyReadOnly && ! $visibility) { return 'read_only'; diff --git a/src/Fields/FieldTransformer.php b/src/Fields/FieldTransformer.php index 5e2850cb086..8fc1cf216fb 100644 --- a/src/Fields/FieldTransformer.php +++ b/src/Fields/FieldTransformer.php @@ -162,10 +162,10 @@ protected static function normalizeRequiredValidation($config) protected static function normalizeVisibility($config) { - $legacyReadOnly = Arr::pull($config, 'read_only'); - $visibility = Arr::get($config, 'visibility'); + $legacyReadOnly = Arr::pull($config, 'read_only'); + if ($legacyReadOnly && ! $visibility) { $config['visibility'] = 'read_only'; } From 29db26577c3f46c401d2b97767900a82f4dd3d05 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 12:03:24 -0400 Subject: [PATCH 09/23] Update the other references to old `read_only` field config. --- resources/js/components/fieldtypes/Fieldtype.vue | 2 +- resources/js/components/fieldtypes/replicator/Field.vue | 2 +- src/Http/Controllers/CP/Collections/EntriesController.php | 4 ++-- src/Http/Controllers/CP/Users/UsersController.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/js/components/fieldtypes/Fieldtype.vue b/resources/js/components/fieldtypes/Fieldtype.vue index 7ad70a143e4..66d06618729 100644 --- a/resources/js/components/fieldtypes/Fieldtype.vue +++ b/resources/js/components/fieldtypes/Fieldtype.vue @@ -49,7 +49,7 @@ export default { }, isReadOnly() { - return this.readOnly || this.config.read_only || false; + return this.readOnly || this.config.visibility === 'read_only' || false; }, replicatorPreview() { diff --git a/resources/js/components/fieldtypes/replicator/Field.vue b/resources/js/components/fieldtypes/replicator/Field.vue index 7cb9f5073b1..c8da5083d44 100644 --- a/resources/js/components/fieldtypes/replicator/Field.vue +++ b/resources/js/components/fieldtypes/replicator/Field.vue @@ -112,7 +112,7 @@ export default { }, isReadOnly() { - return this.readOnly || this.field.read_only || false; + return this.readOnly || this.field.visibility === 'read_only' || false; }, classes() { diff --git a/src/Http/Controllers/CP/Collections/EntriesController.php b/src/Http/Controllers/CP/Collections/EntriesController.php index 3c67641d014..f092455c29c 100644 --- a/src/Http/Controllers/CP/Collections/EntriesController.php +++ b/src/Http/Controllers/CP/Collections/EntriesController.php @@ -84,7 +84,7 @@ public function edit(Request $request, $collection, $entry) } if (User::current()->cant('edit-other-authors-entries', [EntryContract::class, $collection, $blueprint])) { - $blueprint->ensureFieldHasConfig('author', ['read_only' => true]); + $blueprint->ensureFieldHasConfig('author', ['visibility' => 'read_only']); } [$values, $meta] = $this->extractFromFields($entry, $blueprint); @@ -247,7 +247,7 @@ public function create(Request $request, $collection, $site) } if (User::current()->cant('edit-other-authors-entries', [EntryContract::class, $collection, $blueprint])) { - $blueprint->ensureFieldHasConfig('author', ['read_only' => true]); + $blueprint->ensureFieldHasConfig('author', ['visibility' => 'read_only']); } $values = []; diff --git a/src/Http/Controllers/CP/Users/UsersController.php b/src/Http/Controllers/CP/Users/UsersController.php index 1d0071c9899..97786f652bf 100644 --- a/src/Http/Controllers/CP/Users/UsersController.php +++ b/src/Http/Controllers/CP/Users/UsersController.php @@ -172,11 +172,11 @@ public function edit(Request $request, $user) $blueprint = $user->blueprint(); if (! User::current()->can('edit roles')) { - $blueprint->ensureField('roles', ['read_only' => true]); + $blueprint->ensureField('roles', ['visibility' => 'read_only']); } if (! User::current()->can('edit user groups')) { - $blueprint->ensureField('groups', ['read_only' => true]); + $blueprint->ensureField('groups', ['visibility' => 'read_only']); } $fields = $blueprint From 6e825c766797ea455f8cd3f25b163c2efbd99ed2 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 12:06:37 -0400 Subject: [PATCH 10/23] Remove old translation instructions for other languages. --- resources/lang/de/messages.php | 1 - resources/lang/de_CH/messages.php | 1 - resources/lang/fr/messages.php | 1 - resources/lang/nb/messages.php | 1 - resources/lang/nl/messages.php | 1 - resources/lang/ru/messages.php | 1 - resources/lang/zh_CN/messages.php | 1 - 7 files changed, 7 deletions(-) diff --git a/resources/lang/de/messages.php b/resources/lang/de/messages.php index e9a972b2420..24cd3f0a2db 100644 --- a/resources/lang/de/messages.php +++ b/resources/lang/de/messages.php @@ -71,7 +71,6 @@ 'fields_instructions_instructions' => 'Wird unter der Bezeichnung des Feldes angezeigt, genau wie dieser Text hier. Markdown wird unterstützt.', 'fields_instructions_position_instructions' => 'Beschreibung über oder unter dem Feld anzeigen.', 'fields_listable_instructions' => 'Steuert die Darstellung in der Listenansicht.', - 'fields_read_only_instructions' => 'Die Bearbeitungsmöglichkeit im Control Panel deaktivieren.', 'fieldset_import_fieldset_instructions' => 'Das zu importierende Fieldset.', 'fieldset_import_prefix_instructions' => 'Ein Präfix, welches jedem Feld beim Import vorangestellt werden soll (z.B. hero_)', 'fieldset_intro' => 'Fieldsets sind optionale Ergänzungen zu Blueprints und dienen als wiederverwendbare Partials, die in Blueprints verwendet werden können.', diff --git a/resources/lang/de_CH/messages.php b/resources/lang/de_CH/messages.php index 5dd3845fde2..879c3563dff 100644 --- a/resources/lang/de_CH/messages.php +++ b/resources/lang/de_CH/messages.php @@ -71,7 +71,6 @@ 'fields_instructions_instructions' => 'Wird unter der Bezeichnung des Feldes angezeigt, genau wie dieser Text hier. Markdown wird unterstützt.', 'fields_instructions_position_instructions' => 'Beschreibung über oder unter dem Feld anzeigen.', 'fields_listable_instructions' => 'Steuert die Darstellung in der Listenansicht.', - 'fields_read_only_instructions' => 'Die Bearbeitungsmöglichkeit im Control Panel deaktivieren.', 'fieldset_import_fieldset_instructions' => 'Das zu importierende Fieldset.', 'fieldset_import_prefix_instructions' => 'Ein Präfix, welches jedem Feld beim Import vorangestellt werden soll (z.B. hero_)', 'fieldset_intro' => 'Fieldsets sind optionale Ergänzungen zu Blueprints und dienen als wiederverwendbare Partials, die in Blueprints verwendet werden können.', diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index 24ad9809d29..764a36b8860 100644 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -71,7 +71,6 @@ 'fields_instructions_instructions' => 'Texte affiché sous l’étiquette du champ (comme celui-ci). Markdown est pris en compte.', 'fields_instructions_position_instructions' => 'Défini le positionnement des instructions par rapport au champ.', 'fields_listable_instructions' => 'Contrôle la visibilité de ce champ dans les colonnes.', - 'fields_read_only_instructions' => 'Désactivez la possibilité de modifier dans le panneau de contrôle.', 'fieldset_import_fieldset_instructions' => 'Le jeu de champs à importer.', 'fieldset_import_prefix_instructions' => 'Le préfixe à appliquer à chaque champ lors de leur importation. Ex. hero_', 'fieldset_intro' => 'Les jeux de champs sont des compagnons optionnels des Blueprints qui vous permettent de créer des partiels réutilisables dans tous vos Blueprints.', diff --git a/resources/lang/nb/messages.php b/resources/lang/nb/messages.php index 192aecc11eb..a016ab9dbcb 100644 --- a/resources/lang/nb/messages.php +++ b/resources/lang/nb/messages.php @@ -71,7 +71,6 @@ 'fields_instructions_instructions' => 'Vises under feltets visningsetikett, slik som denne teksten. Markdown støttes.', 'fields_instructions_position_instructions' => 'Vis instruksjoner over eller under feltet.', 'fields_listable_instructions' => 'Styrer om feltet skjules eller vises i lister.', - 'fields_read_only_instructions' => 'Deaktiver redigering i kontrollpanelet.', 'fieldset_import_fieldset_instructions' => 'Feltsettet som skal importeres.', 'fieldset_import_prefix_instructions' => 'Prefikset som skal brukes på hvert felt når de importeres, for eksempel helt_', 'fieldset_intro' => 'Feltsett er en valgfri ledsager til blueprint og fungerer som gjenbrukbare delreplikaer som kan brukes i blueprint.', diff --git a/resources/lang/nl/messages.php b/resources/lang/nl/messages.php index 73ef7c741a5..b962daa8a7f 100644 --- a/resources/lang/nl/messages.php +++ b/resources/lang/nl/messages.php @@ -71,7 +71,6 @@ 'fields_instructions_instructions' => 'Wordt getoond onder het velds weergavelabel, net zoals deze tekst. Markdown is toegestaan.', 'fields_instructions_position_instructions' => 'Waar de instructie gepositioneerd moet worden ten opzichte van het veld.', 'fields_listable_instructions' => 'Bepaal of dit veld getoond moet worden als kolom in overzichtstabellen.', - 'fields_read_only_instructions' => 'Schakel uit dat je het veld kunt wijzigen in het controle paneel.', 'fieldset_import_fieldset_instructions' => 'De fieldset die geïmporteerd moet worden.', 'fieldset_import_prefix_instructions' => 'Het voorvoegsel dat op ieder veld toegepast moet worden als ze worden geïmporteerd. Bijv: hero_', 'fieldset_intro' => 'Fieldsets zijn een optionele toevoeging aan blueprints, het zijn herbruikbare partials die in blueprints gebruikt kunnen worden.', diff --git a/resources/lang/ru/messages.php b/resources/lang/ru/messages.php index 003d573c661..01b7e482cca 100644 --- a/resources/lang/ru/messages.php +++ b/resources/lang/ru/messages.php @@ -71,7 +71,6 @@ 'fields_instructions_instructions' => 'Показывается под отображаемой меткой поля, как этот самый текст. Поддерживается Markdown.', 'fields_instructions_position_instructions' => 'Где должны располагаться инструкции относительно поля.', 'fields_listable_instructions' => 'Управление видимостью столбца этого поля.', - 'fields_read_only_instructions' => 'Отключить редактирование в панели управления.', 'fieldset_import_fieldset_instructions' => 'Набор полей, который необходимо импортировать.', 'fieldset_import_prefix_instructions' => 'Префикс, который должен быть применен к каждому полю при импорте. Например, `hero_`', 'fieldset_intro' => 'Наборы полей являются дополнением к чертежам, действуя как многократно используемые частицы.', diff --git a/resources/lang/zh_CN/messages.php b/resources/lang/zh_CN/messages.php index 989741ab970..734c1e68793 100644 --- a/resources/lang/zh_CN/messages.php +++ b/resources/lang/zh_CN/messages.php @@ -71,7 +71,6 @@ 'fields_instructions_instructions' => '显示在字段的显示标签下,就像文本一样。支持Markdown。', 'fields_instructions_position_instructions' => '在字段上方或下方显示指示。', 'fields_listable_instructions' => '控制此字段列的可见性。', - 'fields_read_only_instructions' => '禁用控制面板中的编辑。', 'fieldset_import_fieldset_instructions' => '要导入的字段集。', 'fieldset_import_prefix_instructions' => '导入每个字段时应应用的前缀。例如。hero_', 'fieldset_intro' => '字段集是蓝图的可选伴侣,允许您创建要在蓝图中使用的部分。', From 8eb2bd7cffb41fbd478b26ce86314adfc8585c2c Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 12:20:39 -0400 Subject: [PATCH 11/23] Pass tests again. --- tests/Fields/BlueprintTest.php | 8 ++++++-- tests/Fields/FieldTest.php | 1 + tests/Fields/FieldsTest.php | 4 ++++ tests/Fields/SectionTest.php | 2 ++ tests/Fieldtypes/NestedFieldsTest.php | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/Fields/BlueprintTest.php b/tests/Fields/BlueprintTest.php index 24122f38969..89532e03cec 100644 --- a/tests/Fields/BlueprintTest.php +++ b/tests/Fields/BlueprintTest.php @@ -359,6 +359,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'append' => null, 'antlers' => false, 'default' => null, + 'visibility' => 'visible', ], ], ], @@ -380,6 +381,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'component' => 'textarea', 'antlers' => false, 'default' => null, + 'visibility' => 'visible', ], ], ], @@ -454,6 +456,7 @@ public function converts_to_array_suitable_for_rendering_prefixed_conditional_fi 'required' => false, 'antlers' => false, 'default' => null, + 'visibility' => 'visible', ], [ 'handle' => 'nested_deeper_two', @@ -470,6 +473,7 @@ public function converts_to_array_suitable_for_rendering_prefixed_conditional_fi 'required' => false, 'antlers' => false, 'default' => null, + 'visibility' => 'visible', ], ], ], @@ -563,7 +567,7 @@ public function it_ensures_a_field_has_config() ], ]]); - $fields = $blueprint->ensureFieldHasConfig('author', ['read_only' => true])->fields(); + $fields = $blueprint->ensureFieldHasConfig('author', ['visibility' => 'read_only'])->fields(); $this->assertEquals(['type' => 'text'], $fields->get('title')->config()); $this->assertEquals(['type' => 'text'], $fields->get('content')->config()); @@ -571,7 +575,7 @@ public function it_ensures_a_field_has_config() $expectedConfig = [ 'type' => 'text', 'do_not_touch_other_config' => true, - 'read_only' => true, + 'visibility' => 'read_only', ]; $this->assertEquals($expectedConfig, $fields->get('author')->config()); diff --git a/tests/Fields/FieldTest.php b/tests/Fields/FieldTest.php index 6b388e796ed..80f548b6661 100644 --- a/tests/Fields/FieldTest.php +++ b/tests/Fields/FieldTest.php @@ -324,6 +324,7 @@ public function preProcess($data) 'instructions' => 'Test instructions', 'required' => true, 'validate' => 'required', + 'visibility' => 'visible', 'component' => 'example', 'a_config_field_with_pre_processing' => 'foo preprocessed', 'a_config_field_without_pre_processing' => 'foo', diff --git a/tests/Fields/FieldsTest.php b/tests/Fields/FieldsTest.php index 622b2a6981e..10c2f979d44 100644 --- a/tests/Fields/FieldsTest.php +++ b/tests/Fields/FieldsTest.php @@ -422,6 +422,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'append' => null, 'antlers' => false, 'default' => null, + 'visibility' => 'visible', ], [ 'handle' => 'two', @@ -436,6 +437,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'antlers' => false, 'placeholder' => null, 'default' => null, + 'visibility' => 'visible', ], ], $fields->toPublishArray()); } @@ -491,6 +493,7 @@ public function converts_to_array_suitable_for_rendering_prefixed_conditional_fi 'required' => false, 'antlers' => false, 'default' => null, + 'visibility' => 'visible', ], [ 'handle' => 'nested_deeper_two', @@ -507,6 +510,7 @@ public function converts_to_array_suitable_for_rendering_prefixed_conditional_fi 'required' => false, 'antlers' => false, 'default' => null, + 'visibility' => 'visible', ], ], $fields->toPublishArray()); } diff --git a/tests/Fields/SectionTest.php b/tests/Fields/SectionTest.php index 9cc9c0c2a23..75e517e9481 100644 --- a/tests/Fields/SectionTest.php +++ b/tests/Fields/SectionTest.php @@ -148,6 +148,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'append' => null, 'antlers' => false, 'default' => null, + 'visibility' => 'visible', ], [ 'handle' => 'two', @@ -162,6 +163,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'antlers' => false, 'placeholder' => null, 'default' => null, + 'visibility' => 'visible', ], ], ], $section->toPublishArray()); diff --git a/tests/Fieldtypes/NestedFieldsTest.php b/tests/Fieldtypes/NestedFieldsTest.php index a2d89c995f8..97242912930 100644 --- a/tests/Fieldtypes/NestedFieldsTest.php +++ b/tests/Fieldtypes/NestedFieldsTest.php @@ -82,6 +82,7 @@ public function preProcess($data) 'handle' => 'image', 'prefix' => null, 'required' => true, + 'visibility' => 'visible', ], ], $actual); } From 4e480cbfbc6497c2c940bf6421396f8ef72f3ab4 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 13:37:15 -0400 Subject: [PATCH 12/23] Move this logic into our `showField()` handler. --- .../field-conditions/ValidatorMixin.js | 19 ++++++++++++------- resources/js/components/publish/Field.vue | 5 ----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/resources/js/components/field-conditions/ValidatorMixin.js b/resources/js/components/field-conditions/ValidatorMixin.js index 29170978883..f91eb90a2bf 100644 --- a/resources/js/components/field-conditions/ValidatorMixin.js +++ b/resources/js/components/field-conditions/ValidatorMixin.js @@ -9,21 +9,26 @@ export default { methods: { showField(field, dottedKey) { - let dottedPrefix = dottedKey + var dottedPrefix = dottedKey ? dottedKey.replace(new RegExp('\.'+field.handle+'$'), '') : ''; - let validator = new Validator(field, this.values, this.$store, this.storeName); - let passes = validator.passesConditions(); - let hiddenByRevealerField = validator.hasRevealerCondition(dottedPrefix); + if (field.visibility === 'hidden') { + var hideField = true; + var omitValue = false; + } else { + var validator = new Validator(field, this.values, this.$store, this.storeName); + var hideField = ! validator.passesConditions(); + var omitValue = ! validator.hasRevealerCondition(dottedPrefix); + } this.$store.commit(`publish/${this.storeName}/setHiddenField`, { dottedKey: dottedKey || field.handle, - hidden: ! passes, - omitValue: ! hiddenByRevealerField, + hidden: hideField, + omitValue: omitValue, }); - return passes; + return ! hideField; } } } diff --git a/resources/js/components/publish/Field.vue b/resources/js/components/publish/Field.vue index ba8bd7232e9..5a30fd8bb80 100644 --- a/resources/js/components/publish/Field.vue +++ b/resources/js/components/publish/Field.vue @@ -4,7 +4,6 @@ :config="config" :initial-value="value" :initial-meta="meta" - v-if="isVisible" >
@@ -143,10 +142,6 @@ export default { return this.isLocked || this.readOnly || this.config.visibility === 'read_only' || false; }, - isVisible() { - return this.config.visibility !== 'hidden'; - }, - isLocalizable() { return this.$config.get('sites').length > 1 && this.config.localizable; }, From bd7c7d2935bf0ca52fff6ae0b81f5039200829b8 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 13:40:48 -0400 Subject: [PATCH 13/23] Be super clear in VueX state that nothing is getting omitted unless explicitly hidden. --- resources/js/components/field-conditions/ValidatorMixin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/components/field-conditions/ValidatorMixin.js b/resources/js/components/field-conditions/ValidatorMixin.js index f91eb90a2bf..97ec43547ae 100644 --- a/resources/js/components/field-conditions/ValidatorMixin.js +++ b/resources/js/components/field-conditions/ValidatorMixin.js @@ -25,7 +25,7 @@ export default { this.$store.commit(`publish/${this.storeName}/setHiddenField`, { dottedKey: dottedKey || field.handle, hidden: hideField, - omitValue: omitValue, + omitValue: hideField && omitValue, }); return ! hideField; From 81a6f39515220f8a3f6fa3b67b92b403ca910395 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 16:29:49 -0400 Subject: [PATCH 14/23] Deprecate old `read_only` field config for addon fieldtypes. --- src/Fields/Field.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 2c80d6476ec..63a6d12753a 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -222,6 +222,7 @@ public function toPublishArray() 'instructions' => $this->instructions(), 'required' => $this->isRequired(), 'visibility' => $this->visibility(), + 'read_only' => $this->visibility() === 'read_only', // Deprecated: Addon fieldtypes should now reference new `visibility` state. ]); } From 068c6724952cb8bf8c6417957f9aa3194c8939ba Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 16:40:33 -0400 Subject: [PATCH 15/23] Pass tests again. --- tests/Fields/BlueprintTest.php | 4 ++++ tests/Fields/FieldTest.php | 1 + tests/Fields/FieldsTest.php | 4 ++++ tests/Fields/SectionTest.php | 2 ++ tests/Fieldtypes/NestedFieldsTest.php | 1 + 5 files changed, 12 insertions(+) diff --git a/tests/Fields/BlueprintTest.php b/tests/Fields/BlueprintTest.php index 89532e03cec..d42c26ea977 100644 --- a/tests/Fields/BlueprintTest.php +++ b/tests/Fields/BlueprintTest.php @@ -360,6 +360,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'antlers' => false, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], ], ], @@ -382,6 +383,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'antlers' => false, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], ], ], @@ -457,6 +459,7 @@ public function converts_to_array_suitable_for_rendering_prefixed_conditional_fi 'antlers' => false, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], [ 'handle' => 'nested_deeper_two', @@ -474,6 +477,7 @@ public function converts_to_array_suitable_for_rendering_prefixed_conditional_fi 'antlers' => false, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], ], ], diff --git a/tests/Fields/FieldTest.php b/tests/Fields/FieldTest.php index 80f548b6661..87aefe0cb57 100644 --- a/tests/Fields/FieldTest.php +++ b/tests/Fields/FieldTest.php @@ -325,6 +325,7 @@ public function preProcess($data) 'required' => true, 'validate' => 'required', 'visibility' => 'visible', + 'read_only' => false, // deprecated 'component' => 'example', 'a_config_field_with_pre_processing' => 'foo preprocessed', 'a_config_field_without_pre_processing' => 'foo', diff --git a/tests/Fields/FieldsTest.php b/tests/Fields/FieldsTest.php index 10c2f979d44..c1b739bbff0 100644 --- a/tests/Fields/FieldsTest.php +++ b/tests/Fields/FieldsTest.php @@ -423,6 +423,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'antlers' => false, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], [ 'handle' => 'two', @@ -438,6 +439,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'placeholder' => null, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], ], $fields->toPublishArray()); } @@ -494,6 +496,7 @@ public function converts_to_array_suitable_for_rendering_prefixed_conditional_fi 'antlers' => false, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], [ 'handle' => 'nested_deeper_two', @@ -511,6 +514,7 @@ public function converts_to_array_suitable_for_rendering_prefixed_conditional_fi 'antlers' => false, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], ], $fields->toPublishArray()); } diff --git a/tests/Fields/SectionTest.php b/tests/Fields/SectionTest.php index 75e517e9481..ed11886efcb 100644 --- a/tests/Fields/SectionTest.php +++ b/tests/Fields/SectionTest.php @@ -149,6 +149,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'antlers' => false, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], [ 'handle' => 'two', @@ -164,6 +165,7 @@ public function converts_to_array_suitable_for_rendering_fields_in_publish_compo 'placeholder' => null, 'default' => null, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], ], ], $section->toPublishArray()); diff --git a/tests/Fieldtypes/NestedFieldsTest.php b/tests/Fieldtypes/NestedFieldsTest.php index 97242912930..01a1c83fe2a 100644 --- a/tests/Fieldtypes/NestedFieldsTest.php +++ b/tests/Fieldtypes/NestedFieldsTest.php @@ -83,6 +83,7 @@ public function preProcess($data) 'prefix' => null, 'required' => true, 'visibility' => 'visible', + 'read_only' => false, // deprecated ], ], $actual); } From cced197a5d3d7059a1439e989c7abbd587a5b95c Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 Apr 2022 18:29:17 -0400 Subject: [PATCH 16/23] Add hidden state to width selector. --- .../js/components/blueprints/RegularField.vue | 6 ++- .../js/components/fields/WidthSelector.vue | 47 +++++++++++++------ .../sass/components/fieldset-builder.scss | 6 +++ 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/resources/js/components/blueprints/RegularField.vue b/resources/js/components/blueprints/RegularField.vue index d4cc16f7bbe..ddbfd3601d9 100644 --- a/resources/js/components/blueprints/RegularField.vue +++ b/resources/js/components/blueprints/RegularField.vue @@ -10,7 +10,7 @@
- +