home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (node_created.inc)

This example Drupal source code file (node_created.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, conf, context, created, date, format, format_date, function, key, node, php, return, small, time

The node_created.inc Drupal example source code

<?php
// $Id: node_created.inc,v 1.1.2.1 2010/01/29 20:18:25 merlinofchaos Exp $

/**
 * 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 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));
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal node_created.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.