From 8917b2df61279f07d14c1444ba93442b6ffdf171 Mon Sep 17 00:00:00 2001 From: Axel Rutz Date: Tue, 5 Aug 2014 23:49:24 +0200 Subject: [PATCH] #2010898-50-interdiff --- ...ntityReference_SelectionHandler_Views.class.php | 36 +++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/plugins/selection/EntityReference_SelectionHandler_Views.class.php b/plugins/selection/EntityReference_SelectionHandler_Views.class.php index db63301..365cfe2 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Views.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Views.class.php @@ -16,9 +16,6 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio $this->field = $field; $this->instance = $instance; $this->entity = $entity; - // Get the entity token type of the entity type. - $entity_info = entity_get_info($entity_type); - $this->entity_type_token = isset($entity_info['token type']) ? $entity_info['token type'] : $entity_type; } /** @@ -72,19 +69,15 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio ); if (module_exists('token')) { // Get the token type for the entity type our field is in (a type 'taxonomy_term' has a 'term' type token). - $instance_entity_info = entity_get_info($instance['entity_type']); - $token_type = isset($instance_entity_info['token type']) ? $instance_entity_info['token type'] : $instance['entity_type']; + $info = entity_get_info($instance['entity_type']); + $token_type = isset($info['token type']) ? $info['token type'] : $instance['entity_type']; $form['view']['tokens'] = array( - '#theme' => 'token_tree_link', - // The token types that have specific context. Can be multiple token types like 'term' and/or 'user'. + '#theme' => 'token_tree', '#token_types' => array($token_type), - // A boolean TRUE or FALSE whether to include 'global' context tokens like [current-user:*] - // or [site:*]. Defaults to TRUE. '#global_types' => TRUE, - // A boolean whether to include the 'Click this token to insert in into the the focused textfield' - // JavaScript functionality. Defaults to TRUE. '#click_insert' => TRUE, + '#dialog' => TRUE, ); } } @@ -208,13 +201,22 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio $data = array(); $options = array('clear' => TRUE); - // Check if the entity has an ID. If not, don't pass the entity to token_replace(). - if ($this->entity) { - list($id, $vid, $bundle) = entity_extract_ids($this->instance['entity_type'], $this->entity); - if (!empty($id)) { - // Only pass the entity to token_replace() if it has a valid ID. - $data = array($this->entity_type_token => $this->entity); + if ($entity = $this->entity) { + // D7 HACK: For new entities, entity and revision id are not set. This leads to + // * token replacement emitting PHP warnings + // * views choking on empty arguments + // We workaround this by filling in '0' for these IDs + // and use a clone to leave no traces of our unholy doings. + $info = entity_get_info($this->instance['entity_type']); + if (!isset($entity->{$info['entity keys']['id']})) { + $entity = clone $entity; + $entity->{$info['entity keys']['id']} = '0'; + if (isset($info['entity keys']['revision'])) { + $entity->{$info['entity keys']['revision']} = '0'; + } } + + $data[$info['token type']] = $entity; } // Replace tokens for each argument. foreach ($args as $key => $arg) { -- 1.7.9.5