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,
  ];
Command icon 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

Guillaume Aveline created an issue. See original summary.

la vague illuminee’s picture

I 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.

la vague illuminee’s picture

Issue summary: View changes
pdureau’s picture

Status: Active » Postponed (maintainer needs more info)

Hi Guillaume,

Thanks for your proposal.

Currently, previews are at fields and settings level, so:

  • only one preview per component (the merge of each field and setting previews)
  • same preview values for all variants

As you already know, we have a few issues to move previews out of fields and settings, to the component level, so:

  • many previews per component (we all agree about that)
  • some previews can be specific to some variants, many previews per variant (we are still discussing about that)

AFAIK your proposal is a bit different, adding previews at the variant level, so:

  • only one preview per component (the merge of each field and setting previews)
  • some variants can have their own previews, only one preview per variant

Describing the YAML structure with JSON path, you are proposing /variants/0/previews instead of /previews/0/variants, but I am afraid it will be a more restricted solution.

Is my understanding right?

pdureau’s picture

Component: Code » UI Patterns Library
pdureau’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

The UI Patterns 2.x solution looks good enough