summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2009-07-18 22:10:49 (GMT)
committer Earl Miles2009-07-18 22:10:49 (GMT)
commit52f037c187cd61997bc7b7bbe870165427443025 (patch)
treecad05ffc7d754c52cc8345f677fd410c009b169a
parent127b1b79622f2fc2645222e0bdb5cf3be4ea775c (diff)
#514432 by markus_petrux: Various node fields available as a pane.
-rw-r--r--plugins/content_types/node_context/node_body.inc52
-rw-r--r--plugins/content_types/node_context/node_created.inc76
-rw-r--r--plugins/content_types/node_context/node_title.inc2
-rw-r--r--plugins/content_types/node_context/node_updated.inc76
4 files changed, 205 insertions, 1 deletions
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 0000000..a577cf1
--- /dev/null
+++ b/plugins/content_types/node_context/node_body.inc
@@ -0,0 +1,52 @@
+<?php
+// $Id$
+
+/**
+ * Callback function to supply a list of content types.
+ */
+function ctools_node_body_ctools_content_types() {
+ return array(
+ 'single' => 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 0000000..a418258
--- /dev/null
+++ b/plugins/content_types/node_context/node_created.inc
@@ -0,0 +1,76 @@
+<?php
+// $Id$
+
+/**
+ * Callback function to supply a list of content types.
+ */
+function ctools_node_created_ctools_content_types() {
+ return array(
+ 'single' => 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 189c8e7..057958c 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 0000000..bd8d67e
--- /dev/null
+++ b/plugins/content_types/node_context/node_updated.inc
@@ -0,0 +1,76 @@
+<?php
+// $Id$
+
+/**
+ * Callback function to supply a list of content types.
+ */
+function ctools_node_updated_ctools_content_types() {
+ return array(
+ 'single' => 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));
+}