theme_image_formatter() function should check does an array key $variables['path']['options'] exists to avoid Drupal error message.
If you have path for link you must specify $variables['path']['options'], even as empty array to avoid Drupal error message Notice: Undefined index: options in theme_image_formatter() (line 603 of /var/www/public_html/modules/image/image.field.inc).
It should be included check for an array key in function...
if (!empty($variables['path']['path'])) {
$path = $variables['path']['path'];
$options = isset($variables['path']['options']) ? $variables['path']['options'] : array();
// When displaying an image inside a link, the html option must be TRUE.
$options['html'] = TRUE;
$output = l($output, $path, $options);
}
Comments
Comment #1
draganerorI create patch for this.
Comment #2
draganerorComment #3
draganerorComment #4
xjmThanks for the patch @el22or!
Generally, you shouldn't mark your own patch "Reviewed and Tested by Community"; the patch should go through the review process first. See the issue statuses documentation for more information. Also, per the backport policy, we should create Drupal 8 patches first.
Looking at the patch, I think maybe we need to look at why the options key is not being passed. According to the API documentation, it sounds like the options key is expected:
(Emphasis added.)
So, could you provide steps to reproduce this error? That will help determine what is passing bad data to the function.
Comment #5
draganerorThis is my first try to make a patch, sorry for mistakes, I got it now.
So, I found problem when I tried simple image transform to link in THEMENAME_preprocess_node().
Comment #6
xjmHi @el22or,
Thanks for the example code. Based on the current API documentation, I think the correct solution currently is to set the value to
array()in the preprocess function (as you have done). So it sounds like we definitely clarify the API documentation for this. (The function seems to indicate that the path is optional, by checking if it's set, but not whether options is.)I think the more usual pattern in core would be to merge in defaults using
$array += array('key' => foo, 'key2' => bar).Oh, also, an aside: use the
LANGUAGE_NONEconstant (instead of'und').Comment #7
xjmI did a little more research. It looks like the fact that the
optionskey is expected here is consistent with theme_link(), which also expects it. See also the comments on that page.Sort-of-related issue: #1187032-12: theme_link needs to be clearer about saying not to call it directly.
Edit 2: Talked this out a bit with some folks in IRC (@msonnabaum, @merlinofchaos, @NiklasFiekas). Based on the comment linked above, we can probably say
theme_link()is irrelevant (since that's not a "real" theme function, but this is). Since we are callingl()andoptionsis optional there, we should allow it be too, as in your patch.Let's clarify the API documentation to indicate that these keys are optional.
Comment #8
xjmTagging.
Comment #9
xjmMore tagging; sorry for the noise.
Comment #10
tim.plunkettThis is actually a duplicate of the older #1396164: theme_image_formatter() should check for array key.
Comment #11
draganerorCould you give us a link to the older post? (you linked to this)
Comment #12
tim.plunkettSo I did! Sorry for the confusion.
#1038932: theme_image_formatter() assumes that title, alt, and options are always set is the issue.