User tokens do not work when Entity API module is enabled

Created on 20 April 2016, about 8 years ago
Updated 18 October 2023, 8 months ago

This code not work if enabled the entity api

  // Global token replacement, and node/user token replacements
    // if a nid/uid is found in the views result row.
    $data = array();
    if (property_exists($view->result[$row_id], 'uid')) {
      $data['user'] = user_load($view->result[$row_id]->uid);
    }
    if (property_exists($view->result[$row_id], 'nid')) {
      $data['node'] = node_load($view->result[$row_id]->nid);
    }

stdClass Object has a different structure

<? 
stdClass Object
(
       [entity] => 775
       [_entity_properties] => Array
           (
               [search_api_relevance] => 1
               [search_api_excerpt] =>
               [uid] => 775
               [entity object] => stdClass Object
                   (
                       [uid] => 775
                       [name] => oplant_775
                       [pass] =>t$S$W9L.Cve5hicKdrOgYLaS1MkGdknz
                       [mail] => plant@gmail.com
                       [theme] =>
                       [signature] =>
                       [signature_format] => plain_text
                       [created] => 1461003783
                       [access] => 0
                       [login] => 0
                       [status] => 1
                       [timezone] => Europe/Moscow
                       [language] => ru
                       [picture] => 0
                       [init] => plant@gmail.com
                       [data] =>
                       [roles] => Array
                           (
                               [2] => authenticated user
                               [3] => firstgroup
                           )

                       
                   )

               [mail] => plant@gmail.com
               [edit_url] => http://dev.site/user/775/edit
           )

       [_field_data] => Array
           (
               [field_reg_kontaktnoe_lico] => Array
                   (
                       [entity_type] => user
                       [entity] => stdClass Object
                           (
                               [uid] => 775
                               [name] => oplant_775
                               [pass] =>
t$S$W9L.Cve5hicKdrOgYLaS1MkGdknz
                               [mail] => plant@gmail.com
                               [theme] =>
                               [signature] =>
                               [signature_format] => plain_text
                               [created] => 1461003783
                               [access] => 0
                               [login] => 0
                               [status] => 1
                               [timezone] => Europe/Moscow
                               [language] => ru
                               [picture] => 0
                               [init] => plant@gmail.com
                               [data] =>
                               [roles] => Array
                                   (
                                       [2] => authenticated user
                                       [3] => firstgroup
                                   )

                               
                   )

              
                           )

                   )

 .... more

I've done this and it helped

$data['user'] = user_load($view->result[$row_id]->entity);

Add the code as correct, please. I'm not a programmer )

πŸ› Bug report
Status

Postponed: needs info

Version

1.2

Component

Tokens

Created by

πŸ‡·πŸ‡ΊRussia WiseMike

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.

Production build 0.69.0 2024