Undefined index in md_cleanse_preprocess_node()

josi's picture
josi
Tue, 01/20/2015 - 11:12
#1
Undefined index in md_cleanse_preprocess_node()

There is a notice/warning when I click on a blog post's date (e.g. http://demo.megadrupal.com/d7/md-cleanse/archive/201406)

Notice: Undefined index: field_portfolio_category in md_cleanse_preprocess_node() (line 670 of /home/www/demo.megadrupal.com/public_html/d7/md-cleanse/sites/all/themes/md_cleanse/template.php).
Warning: Invalid argument supplied for foreach() in md_cleanse_preprocess_node() (line 670 of /home/www/demo.megadrupal.com/public_html/d7/md-cleanse/sites/all/themes/md_cleanse/template.php).

How can I fix this?

cindy's picture
cindy
Wed, 01/21/2015 - 03:52

Hi. Please send us your site's url and admin account as well as FTP account to [email protected] (also this forum link) We will check and fix this issue

josi's picture
josi
Wed, 01/21/2015 - 05:25

Hi Cindy, I cannot send you my account information, could you just tell me how to fix this?

cindy's picture
cindy
Wed, 01/21/2015 - 22:08

Please open file template.php (md_cleanse/template.php) > find and remove the function named md_cleanse_preprocess_node(&$variables) and replace with: 

md_cleanse_preprocess_node(&$variables) {
if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
$variables['classes_array'][] = 'node-full';
}


$node = $variables['node'];
if ($node->type == 'portfolio') {
$categories = array();
$content = $variables['content'];
if(isset($content['field_portfolio_category'])) {
foreach ($content['field_portfolio_category']['#items'] as $item) {
$categories["taxonomy/term/{$item['tid']}"] = $item['taxonomy_term']->name;
}
}
$variables['categories'] = $categories;
}
if ($node->type == 'blog') {
$categories = array();
$content = $variables['content'];
if(isset($content['field_blog_categories'])) {
foreach ($content['field_blog_categories']['#items'] as $item) {
$categories["taxonomy/term/{$item['tid']}"] = $item['taxonomy_term']->name;
}
}
$variables['categories'] = $categories;
}

$votes = 0;
if (module_exists('votingapi')) {
$criteria = array(
'entity_type' => 'node',
'entity_id' => $node->nid,
'function' => 'sum',
'value_type' => 'points',
);
$result = votingapi_select_results($criteria);
if (!empty($result)) {
$votes = $result[0]['value'];
}
}
$variables['votes'] = $votes;
$shares_icon = array();
$shares = field_get_items('node', $node, 'field_portfolio_share_icons');
if ($shares) {
foreach ($shares as $share) {
$share = entity_load_single('field_collection_item', $share['value']);
$shares_icon[] = array(
'social' => $share->field_share_social['und'][0]['value'],
'link' => $share->field_share_link['und'][0]['value'],
);
}
}

$variables['shares_icon'] = $shares_icon;
$client_array = array();
$clients = field_get_items('node', $node, 'field_portfolio_client');
if ($clients) {
foreach ($clients as $client) {
$client = entity_load_single('field_collection_item', $client['value']);
$client_array[] = array(
'name' => $client->field_client_name['und'][0]['value'],
'link' => $client->field_client_link['und'][0]['value'],
);
}
}

$variables['clients'] = $client_array;

$content = $variables['content'];

if (isset($content['field_portfolio_images'])) {
// sliders
$has_video = FALSE;
foreach ($content['field_portfolio_images']['#items'] as $multimedia) {
if ($multimedia['file']->type == 'video') {
$has_video = TRUE;
$variables['slider_video_link'] = file_create_url($multimedia['file']->uri);
$variables['slider_image_link'] = file_create_url($content['field_portfolio_thumbnail'][0]['#item']['uri']);
break;
}
}


if ($has_video) {
$variables['slider_type'] = 'video';
} elseif (count($content['field_portfolio_images']['#items']) > 1) { // slider
$variables['slider_type'] = 'slider';
$variables['slider_images_link'] = array();
foreach ($content['field_portfolio_images']['#items'] as $image) {
$variables['slider_images_link'][] = file_create_url($image['file']->uri);
}
} else { // popup image view.
$variables['slider_image_link'] = file_create_url($content['field_portfolio_thumbnail'][0]['#item']['uri']);
$variables['slider_type'] = 'single';
}
}
$variables['cleanse_next'] = cleanse_get_next_node($node);
$variables['cleanse_previous'] = cleanse_get_previous_node($node);
}

josi's picture
josi
Thu, 01/22/2015 - 08:21

Thank you, that helped

Log in or register to post comments
Have More Idea?

We are here to build your website!

No Universal solution fits all special business requirements. Our experienced team is ready with ideas and state-of-the-art technical solutions to consult the best solution within your budget.