Add proper image and image style token support

Created on 23 August 2022, over 2 years ago
Updated 12 April 2023, over 1 year ago

Problem/Motivation

Image field tokens are not very visible nor represented in the token browser. I also have a need in the Representative Image module for a generic 'image' token type, as well as exposing image styles for the image.

With proper token type support the field tokens could be cleaned up as well.

Proposed resolution

  • Add new 'image' token type that corresponds to an ImageInterface object
  • This new type will be used for [node:image_field_name:image] nested tokens
  • Image style available via [entity-type:your_image_field_name:image:style:your_image_style_name]
  • Add new 'image-style' token type that needs both an ImageInterface object as well as an ImageStyle entity.

Remaining tasks

  • Test coverage
  • Convert field_tokens() to use the new tokens instead of manually generating their own that are not visible in the token tree

User interface changes

None

API changes

Adds hook_token_info and hook_tokens() on behalf of core's image.module.

Data model changes

Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

🇺🇸United States dave reid Nebraska USA

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • 🇮🇹Italy robertom

    Hi, thanks for this useful patch.

    I need to get relative url of image style, so I've added a commit for implement chained token relationships for url.

    now we can use a token like this:

    [entity-type:your_image_field_name:image:style:your_image_style_name:url:relative]
    

    I hope I wasn't wrong to directly add a commit on the issue fork

Production build 0.71.5 2024