You are here

node_updated.inc in Chaos Tool Suite (ctools) 6

Same filename and directory in other branches
  1. 7 plugins/content_types/node_context/node_updated.inc

File

plugins/content_types/node_context/node_updated.inc
View source
<?php

/**
 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
 */
$plugin = 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->changed) ? $node->changed : $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,
  ));
}

Functions

Namesort descending Description
ctools_node_updated_content_type_admin_title Returns the administrative title for a type.
ctools_node_updated_content_type_edit_form Returns an edit form for custom type settings.
ctools_node_updated_content_type_edit_form_submit Submit handler for the custom type settings form.
ctools_node_updated_content_type_render Render the custom content type.