Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use optional context and add ting_colletion context #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions plugins/content_types/recommender.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ $plugin = array(
//'edit form' => 'ting_inspiration_list_content_type_edit_form',
'render callback' => 'ting_recommender_content_type_render',
'category' => t('Ting'),
'required context' => new ctools_context_required(t('Ting object'), 'ting_object'),
'required context' => array(
new ctools_context_optional(t('Ting object'), 'ting_object'),
new ctools_context_optional(t('Ting collection'), 'ting_collection'),
),
'render last' => TRUE,
);

Expand All @@ -22,13 +25,29 @@ $plugin = array(
function ting_recommender_content_type_render($subtype, $conf, $panel_args, $context) {
// Define the return block.
$block = new stdClass();

drupal_add_js('https://cdn.bibspire.dk/ddbcms.js', 'external');
$object = isset($context->data) ? ($context->data) : NULL;

$pid = NULL;

// Ting object context.
if (!empty($context[0]->data)) {
/** @var \TingEntity */
$object = $context[0]->data;
$pid = $object->getId();
}
// Ting collection context.
elseif (!empty($context[1]->data)) {
/** @var \TingCollection */
$collection = $context[1]->data;
$pid = $collection->getId();
}

$data = '';
if (isset($object)) {
$data = 'data-ting-object-id="' . $object->getId() . '"';
if (isset($pid)) {
$data = "data-ting-object-id='$pid'";
}

// Set block content.
$block->content = '<a name="recommender"></a><div id="ting-recommender" ' . $data . '></div>';
return $block;
Expand Down