Skip to content

Commit

Permalink
fixing issue where array structure for references is changing #21
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincrafts committed Jan 26, 2018
1 parent a2fbcd3 commit 7fe2fc1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion modules/custom/cu_newsletter/cu_newsletter.module
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,16 @@ function cu_newsletter_preprocess_node(&$vars) {
$articles = array();
$sections = array_intersect_key($vars['elements']['field_newsletter_section'], element_children($vars['elements']['field_newsletter_section']));
foreach ($sections as $section) {

$section_item = $section['entity']['field_collection_item'];
$section_item = current($section_item);
if (!empty($section_item['field_newsletter_articles']['#items'])) {
foreach ($section_item['field_newsletter_articles']['#items'] as $reference) {
$nid = $reference['target_id'];

$nid = $reference['value'];
$articles[$nid] = $nid;
}

}
}
// Get node titles
Expand Down Expand Up @@ -216,6 +219,15 @@ function cu_newsletter_preprocess_entity(&$vars) {

$vars['content']['newsletter_content'][$nid]['#column_class'] = $column_class;
}
// Changes to entity reference changed the array structure.
// Adding an else to allow us to deploy this code separately.
elseif (!empty($item['field_newsletter_articles'][0]['#item']['target_id'])) {
$nid = $item['field_newsletter_articles'][0]['#item']['target_id'];
$node = node_load($nid);
$vars['content']['newsletter_content'][$nid] = node_view($node, $view_mode);

$vars['content']['newsletter_content'][$nid]['#column_class'] = $column_class;
}
// Otherwise do the custom text
elseif (!empty($item['field_nl_section_content_title']) || !empty($item['field_nl_section_content_body'])) {
$contents = array();
Expand Down

0 comments on commit 7fe2fc1

Please sign in to comment.