t('Node field'), 'defaults' => array( 'link' => TRUE, 'created_format' => 'small', 'updated_format' => 'small', ), ); } /** * Return all block content types available. */ function ctools_node_fields_content_type_content_types() { $types = array(); $types['title'] = array( 'category' => t('Node'), 'title' => t('Node title'), 'icon' => 'icon_node.png', 'description' => t('Title of the referenced node.'), 'required context' => new ctools_context_required(t('Node'), 'node'), ); $types['body'] = array( 'category' => t('Node'), 'title' => t('Node body'), 'icon' => 'icon_node.png', 'description' => t('Body of the referenced node.'), 'required context' => new ctools_context_required(t('Node'), 'node'), ); $types['created'] = array( 'category' => t('Node'), 'title' => t('Node created date'), 'icon' => 'icon_node.png', 'description' => t('Created date of the referenced node.'), 'required context' => new ctools_context_required(t('Node'), 'node'), ); $types['updated'] = array( 'category' => t('Node'), 'title' => t('Node last updated date'), 'icon' => 'icon_node.png', 'description' => t('Last updated date of the referenced node.'), 'required context' => new ctools_context_required(t('Node'), 'node'), ); return $types; } /** * Output function for the 'node_fields' content type. */ function ctools_node_fields_content_type_render($subtype, $conf, $panel_args, $context) { if (!empty($context) && empty($context->data)) { return; } $node = drupal_clone($context->data); $block = new stdClass(); $block->module = 'node'; $block->delta = $node->nid; switch ($subtype) { case 'title': $type = node_get_types('type', $node->type); $block->title = $type->title_label; $block->content = !empty($conf['link']) ? l($node->title, 'node/'. $node->nid) : check_plain($node->title); break; case 'body': $type = node_get_types('type', $node->type); if (!$type->has_body) { return; } $block->title = $type->body_label; $block->content = check_markup($node->body, $node->format, FALSE); break; case 'created': $block->title = t('Created date'); $block->content = format_date($node->created, $conf['created_format']); break; case 'updated': $block->title = t('Last updated date'); $block->content = format_date(!empty($node->updated) ? $node->updated : $node->created, $conf['updated_format']); break; default: return; } return $block; } /** * Returns an edit form for the custom type. */ function ctools_node_fields_content_type_edit_form(&$form, &$form_state) { $conf = $form_state['conf']; if ($form_state['subtype_name'] == 'title') { $form['link'] = array( '#title' => t('Link to node'), '#type' => 'checkbox', '#default_value' => $conf['link'], '#description' => t('Check here to make the field link to the node.'), ); } if (in_array($form_state['subtype_name'], array('created', 'updated'))) { $time = time(); $format_key = $form_state['subtype_name'] .'_format'; $form[$format_key] = 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' => isset($conf[$format_key]) ? $conf[$format_key] : 'small', ); } } /** * Submit handler for the node field settings form. */ function ctools_node_fields_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_fields_content_type_admin_title($subtype, $conf, $context) { $types = ctools_node_fields_content_type_content_types(); return t('"@s" @node-field', array('@s' => $context->identifier, '@node-field' => $types[$subtype]['title'])); }