Problem/Motivation
The [img] shortcode takes a src parameter which can contain either an absolute or a relative URL. This can cause an issues in the following circumstances:
- The site is moved to a different directory.
- The image URL is changed (image updated).
In addition, we are unable to take advantage of image styles.
Proposed resolution
I propose adding the following parameters:
- mid - Generate the absolute file URL based on the supplied media id and use this URL in the src attribute of the img tag.
- imagestyle - Add the ability to supply an image style. If both mid and imagestyle are supplied, the URL of the appropriate style will be set as the src attribute of the img tag.
Remaining tasks
Test/Review.
User interface changes
At present, I don't think there are any user interface implications.
API changes
N/A.
Data model changes
N/A.
Comments
Comment #2
sthomps5 commentedComment #3
sthomps5 commentedComment #4
sthomps5 commentedComment #5
sthomps5 commentedComment #6
sthomps5 commentedComment #7
sthomps5 commentedmid (media id) is a more appropriate attribute name than file id (fid). It is more convenient to retrieve the media id within Drupal.
Comment #8
sthomps5 commentedCreated a new patch after realising that media id was being used to create a file entity. We now convert the media id to a file entity before proceeding to retrieve URLs.
Comment #9
sthomps5 commentedNoting here that the media library has a required field of 'alt' attribute. If pulling a file in using mid, it makes sense to use the alt attribute of the media file itself if an attribute isn't supplied as an override.
Comment #10
sthomps5 commentedTesting reveals that setting an image style causes an error. This issue is resolved in this patch.
Comment #11
sthomps5 commentedCode refactor, and logic that pulls in the alt attribute if the media id is supplied and no alt attribute is given in the shortcode.
This enables us to write shorter shortcodes such as:
[img mid="1" style="medium" /]
...and still have the alt attribute added as this is a required field on the media object with an id of 1.
Comment #12
sthomps5 commentedRenaming the style attribute to imagestyle to avoid confusion with the style attribute used in other shortcodes that add inline style.
Comment #13
sthomps5 commentedComment #14
sthomps5 commentedComment #16
sthomps5 commentedComment #17
sthomps5 commented