Getting a lot of errors Undefined index: {file_style} in _file_entity_tokens_get_property() on each page.
Inside _file_entity_tokens_get_property() function there are two tests at lines 299 and 326:
$value = $info[$file['fid']][$property] ?: NULL;
I Think it should be
$value = isset($info[$file['fid']][$property]) ?: NULL;
At least for me this stopped throwing errors and I don't see any side effect.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | file_entity-2947445-16.patch | 475 bytes | joseph.olstad |
Comments
Comment #2
joseph.olstadDuplicate of
#2944255: Token types are not defined but have tokens $info['types']['taxonomy_term']
Comment #3
joseph.olstadComment #4
joseph.olstadopenned issue
Comment #5
joseph.olstadComment #6
joseph.olstadComment #8
joseph.olstadalso committed to 7.x-2.x
Comment #9
joseph.olstadComment #10
erwangel commentedComing back to my initial issue
$value = isset($info[$file['fid']][$property]) ?: NULL;I'm not expert on shorthand php but should it be rather like this ? Previous version will return TRUE instead of a value, no ?
$value = isset($info[$file['fid']][$property]) ? $info[$file['fid']][$property]: NULL;But I think the problem is a lit bit more complex.
$property is supposed to be one of the imagecache indexes, e.g. thumbnail, large, etc.
The isset test avoids the Undefined index warning but this is not normal to get an undefined value there as the imagecache types exist but just they aren't never carried by the $info[$file]['fid'] array into the _file_entity_tokens_get_property() function. Also here is another error message related to entity_token and to this lack of $property value. There is an "Notice : Array to string conversion in token_replace() (line 102..." error which comes together with (after) the "Undefined index: {file_style} in _file_entity_tokens_get_property" error. This happens only with media image fields (media entity files), and there are no errors with drupal image field. Additionally, any image related metatag results to "http://www.sitename.com/Array"
Digging further it appears that in token_generate() (in core token.inc) we get two tokens of the same index. Here is the final result after call to module_invoke_all by token_generate:
The first (indexed 0) NULL value comes from file_entity_tokens() hook processing "field_media:thumbnail", while the second (indexed 1) value seems to be generated by the imagecache_token module.
Finally I think there is a problem either with the properties definitions at file_entity_token_info() or with the testings on file types inside file_entity_tokens() but I can't figure exactly where.
As a temporary solution, I conditioned the return of file_entity_tokens to NOT provide a replacement token if the value is NULL
Seems to work with no errors in the logs and with my image metatags generated although.
Comment #11
erwangel commentedComment #12
joseph.olstadQuick note; I should have mentioned, this was only committed to 3.x, if you want to try it you must try the 3.x dev version
Meanwhile if 3.x doesn't resolve this for you and you have a better solution for 2.x or 3.x please submit a patch.
Comment #13
saniyat commentedSame problem found as like #10 for imagecachetoken module. The proposed solution saved me but not sure that is the proper solution or not. I have created patch for 7.x-2.x branch.
Comment #14
saniyat commentedSorry, correct patch.
Comment #15
joseph.olstadThanks for the patch!
Comment #16
joseph.olstadslight change to the patch.
Comment #17
das-peter commentedComing here from #2956389: Does not work with File Entity fields, even though module has option to enable them
Exactly what I needed & not setting nothing makes sense :)
Comment #20
joseph.olstadin 7.x-2.x and 7.x-3.x dev branches