Problem/Motivation
But I'm working with current version 1.7 and I have this specific need with a pattern referencing an image, and two variants.
In the first variant, I'm expecting the full image rendered from drupal with theme image.
In the second, I'm just expecting the URI of the image to set as a background.
So I have this need to define a different preview for a variant which I'm working on.
I'm aware of following existing issues, for incomming 2.x version.
https://www.drupal.org/project/ui_patterns/issues/3336654
https://www.drupal.org/project/ui_patterns/issues/3353289
https://www.drupal.org/project/ui_patterns/issues/3360373
Proposed resolution
Let's imagine this pattern
header:
label: Header
variants:
rounded:
label: Rounded
color-1:
label: Color 1
color-2:
label: Color 2
fields:
title:
type: text
label: Title
preview: Hello, world!
image:
type: image
label: Image
preview: "//placehold.co/600x400"
I want a specific preview for the image field in rounded variant, and for demonstration purpose, I'll change the preview title too.
header:
label: Header
variants:
rounded:
label: Rounded
preview:
title: Hello, rounded!
image:
theme: image
uri: "//placehold.co/200x200"
color-1:
label: Color 1
color-2:
label: Color 2
fields:
title:
type: text
label: Title
preview: Hello, world!
image:
type: image
label: Image
preview: "//placehold.co/600x400"
Remaining tasks
Review and discuss
Data model changes
I added a preview attributes to PatternDefinitionVariant
protected $definition = [
'name' => NULL,
'label' => NULL,
'description' => NULL,
'use' => NULL,
+ 'preview' => NULL,
];
Issue fork ui_patterns-3377457
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
la vague illuminee commentedI added tests for this issue, but the function
public static function processFields(array $element)is not tested.And I don't know how to create test for it.
Comment #4
la vague illuminee commentedComment #5
pdureau commentedHi Guillaume,
Thanks for your proposal.
Currently, previews are at fields and settings level, so:
As you already know, we have a few issues to move previews out of fields and settings, to the component level, so:
AFAIK your proposal is a bit different, adding previews at the variant level, so:
Describing the YAML structure with JSON path, you are proposing
/variants/0/previewsinstead of/previews/0/variants, but I am afraid it will be a more restricted solution.Is my understanding right?
Comment #6
pdureau commentedComment #7
pdureau commentedThe UI Patterns 2.x solution looks good enough