diff --git a/plugins/content_types/node_context/node_body.inc b/plugins/content_types/node_context/node_body.inc new file mode 100644 index 0000000000000000000000000000000000000000..a577cf1f7eb15d5449574d3f67cd69eb995db71e --- /dev/null +++ b/plugins/content_types/node_context/node_body.inc @@ -0,0 +1,52 @@ + TRUE, + 'title' => t('Node body'), + 'icon' => 'icon_node.png', + 'description' => t('The body of the referenced node.'), + 'required context' => new ctools_context_required(t('Node'), 'node'), + 'category' => t('Node'), + ); +} + +/** + * Render the custom content type. + */ +function ctools_node_body_content_type_render($subtype, $conf, $panel_args, $context) { + if (empty($context) || empty($context->data)) { + return; + } + + // Get a shortcut to the node. + $node = $context->data; + + // Load information about the node type. + $type = node_get_types('type', $node->type); + + // Do not render if the body is disabled for this node type. + if (!$type->has_body) { + return; + } + + // Build the content type block. + $block = new stdClass(); + $block->module = 'node_body'; + $block->title = $type->body_label; + $block->content = check_markup($node->body, $node->format, FALSE); + $block->delta = $node->nid; + + return $block; +} + +/** + * Returns the administrative title for a type. + */ +function ctools_node_body_content_type_admin_title($subtype, $conf, $context) { + return t('"@s" body', array('@s' => $context->identifier)); +} diff --git a/plugins/content_types/node_context/node_created.inc b/plugins/content_types/node_context/node_created.inc new file mode 100644 index 0000000000000000000000000000000000000000..a418258e039a607acdff2e948614ac9f3c661aad --- /dev/null +++ b/plugins/content_types/node_context/node_created.inc @@ -0,0 +1,76 @@ + TRUE, + 'title' => t('Node created date'), + 'icon' => 'icon_node.png', + 'description' => t('The date the referenced node was created.'), + 'required context' => new ctools_context_required(t('Node'), 'node'), + 'category' => t('Node'), + 'defaults' => array( + 'format' => 'small', + ), + ); +} + +/** + * Render the custom content type. + */ +function ctools_node_created_content_type_render($subtype, $conf, $panel_args, $context) { + if (empty($context) || empty($context->data)) { + return; + } + + // Get a shortcut to the node. + $node = $context->data; + + // Build the content type block. + $block = new stdClass(); + $block->module = 'node_created'; + $block->title = t('Created date'); + $block->content = format_date($node->created, $conf['format']); + $block->delta = $node->nid; + + return $block; +} + +/** + * Returns an edit form for custom type settings. + */ +function ctools_node_created_content_type_edit_form(&$form, &$form_state) { + $conf = $form_state['conf']; + + $time = time(); + $form['format'] = array( + '#title' => t('Date format'), + '#type' => 'select', + '#options' => array( + 'small' => format_date($time, 'small'), + 'medium' => format_date($time, 'medium'), + 'large' => format_date($time, 'large'), + ), + '#default_value' => $conf['format'], + ); +} + +/** + * Submit handler for the custom type settings form. + */ +function ctools_node_created_content_type_edit_form_submit(&$form, &$form_state) { + // Copy everything from our defaults. + foreach (array_keys($form_state['plugin']['defaults']) as $key) { + $form_state['conf'][$key] = $form_state['values'][$key]; + } +} + +/** + * Returns the administrative title for a type. + */ +function ctools_node_created_content_type_admin_title($subtype, $conf, $context) { + return t('"@s" created date', array('@s' => $context->identifier)); +} diff --git a/plugins/content_types/node_context/node_title.inc b/plugins/content_types/node_context/node_title.inc index 189c8e7e4c14366b2fc9341061289287a706db2b..057958cbfed999a381fcc66602b7bd3ba6820836 100644 --- a/plugins/content_types/node_context/node_title.inc +++ b/plugins/content_types/node_context/node_title.inc @@ -46,8 +46,8 @@ function ctools_node_title_content_type_render($subtype, $conf, $panel_args, $co * Returns an edit form for custom type settings. */ function ctools_node_title_content_type_edit_form(&$form, &$form_state) { - // provide a blank form so we have a place to have context setting. $conf = $form_state['conf']; + $form['link'] = array( '#title' => t('Link to node'), '#type' => 'checkbox', diff --git a/plugins/content_types/node_context/node_updated.inc b/plugins/content_types/node_context/node_updated.inc new file mode 100644 index 0000000000000000000000000000000000000000..bd8d67e05357b9d9c8e119d10ae46c68111d2f9b --- /dev/null +++ b/plugins/content_types/node_context/node_updated.inc @@ -0,0 +1,76 @@ + TRUE, + 'title' => t('Node last updated date'), + 'icon' => 'icon_node.png', + 'description' => t('The date the referenced node was last updated.'), + 'required context' => new ctools_context_required(t('Node'), 'node'), + 'category' => t('Node'), + 'defaults' => array( + 'format' => 'small', + ), + ); +} + +/** + * Render the custom content type. + */ +function ctools_node_updated_content_type_render($subtype, $conf, $panel_args, $context) { + if (empty($context) || empty($context->data)) { + return; + } + + // Get a shortcut to the node. + $node = $context->data; + + // Build the content type block. + $block = new stdClass(); + $block->module = 'node_updated'; + $block->title = t('Last updated date'); + $block->content = format_date(!empty($node->updated) ? $node->updated : $node->created, $conf['format']); + $block->delta = $node->nid; + + return $block; +} + +/** + * Returns an edit form for custom type settings. + */ +function ctools_node_updated_content_type_edit_form(&$form, &$form_state) { + $conf = $form_state['conf']; + + $time = time(); + $form['format'] = array( + '#title' => t('Date format'), + '#type' => 'select', + '#options' => array( + 'small' => format_date($time, 'small'), + 'medium' => format_date($time, 'medium'), + 'large' => format_date($time, 'large'), + ), + '#default_value' => $conf['format'], + ); +} + +/** + * Submit handler for the custom type settings form. + */ +function ctools_node_updated_content_type_edit_form_submit(&$form, &$form_state) { + // Copy everything from our defaults. + foreach (array_keys($form_state['plugin']['defaults']) as $key) { + $form_state['conf'][$key] = $form_state['values'][$key]; + } +} + +/** + * Returns the administrative title for a type. + */ +function ctools_node_updated_content_type_admin_title($subtype, $conf, $context) { + return t('"@s" last updated date', array('@s' => $context->identifier)); +}