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.

Comments

erwangel created an issue. See original summary.

joseph.olstad’s picture

Priority: Major » Normal
Status: Active » Closed (duplicate)
joseph.olstad’s picture

joseph.olstad’s picture

Issue summary: View changes
Status: Closed (duplicate) » Active

openned issue

joseph.olstad’s picture

Title: Undefined index: {file_style} in _file_entity_tokens_get_property() » Undefined index: {file_style} in _file_entity_tokens_git commit -m 'Issue #2944255: Token types are not defined but have tokens $info['\''types'\'']['\''taxonomy_term'\'']'git commit -m 'Issue #2947445 by erwangel, joseph.olstad: Undefined get_property()
Issue summary: View changes
Issue tags: +git commit -m 'Issue #2944255: Token types are not defined but have tokens $info['\''types'\'']['\''taxonomy_term'\'']'git commit -m 'Issue #2947445 by erwangel, +joseph.olstad: Undefined index: {file_style} in _file_entity_tokens_get_property() ' --author=
joseph.olstad’s picture

Title: Undefined index: {file_style} in _file_entity_tokens_git commit -m 'Issue #2944255: Token types are not defined but have tokens $info['\''types'\'']['\''taxonomy_term'\'']'git commit -m 'Issue #2947445 by erwangel, joseph.olstad: Undefined get_property() » Undefined index: {file_style} in _file_entity_tokens_get_property()
Issue tags: -git commit -m 'Issue #2944255: Token types are not defined but have tokens $info['\''types'\'']['\''taxonomy_term'\'']'git commit -m 'Issue #2947445 by erwangel, -joseph.olstad: Undefined index: {file_style} in _file_entity_tokens_get_property() ' --author=

  • joseph.olstad committed bbbce10 on 7.x-3.x authored by erwangel
    Issue #2947445 by erwangel, joseph.olstad: Undefined index: {file_style...
joseph.olstad’s picture

also committed to 7.x-2.x

joseph.olstad’s picture

Status: Active » Fixed
erwangel’s picture

Coming 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:

$replacements =  array('[node:field_media:thumbnail]' => 
  array (
    0 => NULL,
    1 => 'http://www.sitename.com/sites/default/files/styles/thumbnail/public/media/image/article/2002/10/article_image.jpg?itok=xxxxxx',
  ),
)

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

          if (is_array($return)) {
            $search_tokens = token_find_with_prefix($tokens, $field_name);
            if ($array_tokens = token_find_with_prefix($search_tokens, $property)) {
              $replacements += token_generate('array', $array_tokens, array('array' => $return), $options);
            }
          }
          else {
	    if ($return !== NULL)
              $replacements[$original] = $return;
          }

Seems to work with no errors in the logs and with my image metatags generated although.

erwangel’s picture

Status: Fixed » Needs work
joseph.olstad’s picture

Quick 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.

saniyat’s picture

StatusFileSize
new1.08 KB

Same 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.

saniyat’s picture

StatusFileSize
new473 bytes

Sorry, correct patch.

joseph.olstad’s picture

Status: Needs work » Needs review

Thanks for the patch!

joseph.olstad’s picture

StatusFileSize
new475 bytes

slight change to the patch.

das-peter’s picture

Status: Needs review » Reviewed & tested by the community

Coming 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 :)

  • joseph.olstad committed 05e366f on 7.x-2.x
    Issue #2947445 by saniyat, joseph.olstad, erwangel: Undefined index: {...

  • joseph.olstad committed 06fa499 on 7.x-3.x
    Issue #2947445 by saniyat, joseph.olstad, erwangel: Undefined index: {...
joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

in 7.x-2.x and 7.x-3.x dev branches

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.