Add property plugin example usage

Created on 15 June 2024, 6 months ago
Updated 18 September 2024, 3 months ago

Problem/Motivation

I'm very interested in trying out the new Property plugin, but I'm not sure how to use it :)

(A follow-up to ✨ Add Property plugin Fixed )

My very, very rough guess so far got me this far -- and it does save a value, but, I don't think it's what I'm meant to do?

# my_theme.style_options.yml

options:
  aria_label:
    plugin: property
    label: 'ARIA label'
    multiple: false
contexts:
  paragraphs:
    button:
      options:
        aria_label: true

Steps to reproduce

N/A

Proposed resolution

Could you please add example usage to the example style options config YML file?
https://git.drupalcode.org/project/style_options/-/blob/1.1.x/example.st...

Also, if possible, a rec for the best way to access this value in a twig template? (I've gotten as far as staring blankly at {{ dd(paragraph.behavior_settings.0) }}, but I feel like that can't be it, there must be another way I'm meant to access this thing -- or, maybe it'll be clearer when I have it set up right.)

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Active

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States alison

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @alison
  • πŸ‡ΊπŸ‡ΈUnited States alison
  • πŸ‡ΊπŸ‡ΈUnited States alison
  • πŸ‡ΊπŸ‡ΈUnited States sethhill

    Hi @alison. I ended up hitting a similar issue on a new site. It looks like I had solved it previously using a preprocess hook, like this:

    function mymodule_preprocess_paragraph(&$variables): void {
      /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
      $paragraph = $variables['paragraph'];
      $behaviorSettings = $paragraph->getAllBehaviorSettings();
    
      // Set style option behaviors as a logical template variable.
      if (!empty($behaviorSettings['style_options'])) {
        foreach ($behaviorSettings['style_options'] as $key => $style) {
          if (isset($style['property'])) {
            $variables['style_options'][$key] = $style['property'];
          }
        }
      }
    }
    

    and then in Twig was able to get at it with {{ style_options.my_style_option }}.

  • πŸ‡ΊπŸ‡ΈUnited States alison

    Thanks so much for sharing @sethhill! We've paused on our internal project to experiment with Mercury Editor, but I've got this saved for if/when we finally circle back to that effort (🀞🀞). And meanwhile, I'll share this with the other person I know who's been experimenting with Mercury Editor.

Production build 0.71.5 2024