I have a strange thing going on with DS' hook_ds_fields_info hook.
I defined 3 DS_FIELD_TYPE_PREPROCESS type DS fields and 2 DS_FIELD_TYPE_FUNCTION type fields.
I am having this issue with the $fields['syp_relevant_videos'] DS_FIELD_TYPE_FUNCTION call, which suppose to use the value of field_sports_channel "List (text) Select list" field as an argument in the view.
I attached the screenshot of dsm($field); output. As you can see, $field['entity']->field_sports_channel['und'][0]['value'] has a string value.
However, when the _syp_relevant_videos function is as below, I get a white screen of death. Only reference to this error I can get is from the Apache error log:
PHP Fatal error: Unsupported operand types in /var/www/modules/node/node.module on line 1360, referer: http://example.com/node/27
The module code is below. Even though both DS_FIELD_TYPE_FUNCTION fields are pretty much the same, second one doesn't work.
Both of them uses views with arguments, and return the output of the views. And I tested the both views in Views UI with and without arguments, they both are fine. And both of them are relatively simple views.
What am I missing?
syp_helper.module
/**
* Implements hook_ds_fields_info().
*
* @see ds.api.php
*/
function syp_helper_ds_fields_info($entity_type) {
$fields = array();
$fields['syp_video_uploaded_by'] = array(
'title' => t('SYP: Video uploaded by'),
'field_type' => DS_FIELD_TYPE_PREPROCESS,
'ui_limit' => array('video|*'),
);
$fields['syp_video_stats'] = array(
'title' => t('SYP: Video stats'),
'field_type' => DS_FIELD_TYPE_PREPROCESS,
'ui_limit' => array('video|*'),
);
$fields['syp_video_rate'] = array(
'title' => t('SYP: Video rate: PRO vs. FAIL'),
'field_type' => DS_FIELD_TYPE_PREPROCESS,
'ui_limit' => array('video|*'),
);
$fields['syp_more_videos_by_author'] = array(
'title' => t('SYP: More videos by author'),
'field_type' => DS_FIELD_TYPE_FUNCTION,
'ui_limit' => array('video|*'),
'function' => '_syp_more_videos_by_author',
);
$fields['syp_relevant_videos'] = array(
'title' => t('SYP: Relevant videos'),
'field_type' => DS_FIELD_TYPE_FUNCTION,
'ui_limit' => array('video|*'),
'function' => '_syp_relevant_videos',
);
return array('node' => $fields);
}
// Other videos by the same author, excluding the current video.
function _syp_more_videos_by_author($field) {
$output = '';
$other_videos_by_author = views_embed_view('syp_more_videos_by_author', 'default', $field['entity']->uid, $field['entity']->nid);
if ($other_videos_by_author) {
$output = '<div class="syp-more-videos-by-author clearfix">' .
'<h3 class="block-title">' .
l(
t('More videos by @author', array('@author' => $field['entity']->name)),
'user/' . $field['entity']->uid . '/videos',
array(
'attributes' => array(
'class' => array('more'),
),
)
) .
'</h3>' .
$other_videos_by_author .
'</div>';
}
return $output;
}
/**
* SYP: Relevant Videos.
*
* Calls a view to display a list of videos from the same category.
*/
function _syp_relevant_videos($field) {
$output = '';
$category = '';
if (isset($field['entity']->field_sports_channel['und'][0]['value'])) {
$category = $field['entity']->field_sports_channel['und'][0]['value'];
$output = '<div class="syp-relevant-videos clearfix">' .
'<h3 class="block-title">' .
l(
t('Relevant videos'),
'sports/' . $category,
array(
'attributes' => array(
'class' => array('more'),
),
)
) .
'</h3>' .
views_embed_view('syp_relevant_videos', 'default', $category) .
'</div>';
}
return $output;
}
| Comment | File | Size | Author |
|---|---|---|---|
| dsm($field); | 146.86 KB | osman |
Comments
Comment #1
x_v commentedfollowing
Comment #2
swentel commentedThat's (most likely) from the call to views_embed_view() which also references the same node you're looking at. I've been bitten by this one.
The way I could make it work is to exclude the current node id you're looking at on the page also in views.