Skip to content
This repository was archived by the owner on Oct 29, 2020. It is now read-only.

Commit 888d16a

Browse files
author
Diego Lorenzo
committed
New function added to get entity if not already laoded.
As it turns out not all stages in Drupal request/page data load cycle are created equal. During the loading of the node for the reportback share, when the node is loaded for the campaign, not all the nested nodes (ie: facts) are loaded as well; instead those nodes are loaded with just a target_id indicator. So sometimes we need to roll up our sleeves and load the node ourselves
1 parent a9db259 commit 888d16a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/modules/dosomething/dosomething_fact/dosomething_fact.module

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function dosomething_fact_get_facts_data($node, $field_names) {
9595

9696
if ($field_data) {
9797
if (array_key_exists($language, $field_data)) {
98-
$entity = $field_data[$language][0]['entity'];
98+
$entity = dosomething_fact_get_entity($field_data, $language);
9999
}
100100

101101
if (isset($field_data[0]['entity']) && is_object($field_data[0]['entity'])) {
@@ -138,6 +138,23 @@ function dosomething_fact_get_facts_data($node, $field_names) {
138138
return NULL;
139139
}
140140

141+
/**
142+
* Return the entity, whether it was already loaded in the field data,
143+
* or if it needs to go and retrieve it.
144+
*
145+
* @param $data
146+
* @param string $language
147+
* @return mixed
148+
*/
149+
function dosomething_fact_get_entity($data, $language = LANGUAGE_NONE) {
150+
if (isset($data[$language][0]['target_id'])) {
151+
$entity = entity_load('node', [$data[$language][0]['target_id']]);
152+
return $entity ? array_shift($entity) : NULL;
153+
}
154+
155+
return $data[$language][0]['entity'];
156+
}
157+
141158
/**
142159
* Get specific data from the fact entity.
143160
*

lib/themes/dosomething/paraneue_dosomething/templates/reportback/reportback-permalink.tpl.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
</div>
8181
<div class="card__copy">
8282
<p class="heading -alpha"><?php print $node->title; ?></p>
83-
8483
<?php if ($node->fact_problem['fact']): ?>
8584
<h3><?php print t('The Problem'); ?></h3>
8685
<p><?php print $node->fact_problem['fact']; ?></p>

0 commit comments

Comments
 (0)