t('Node field'), 'defaults' => array( 'link' => TRUE, 'created_format' => 'small', 'updated_format' => 'small', 'boolean_format' => 'yes-no', ), ); } /** * 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('The 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('The 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'), ); $types['author'] = array( 'category' => t('Node'), 'title' => t('Node author'), 'icon' => 'icon_node.png', 'description' => t('The author of the referenced node.'), 'required context' => new ctools_context_required(t('Node'), 'node'), ); $types['status'] = array( 'category' => t('Node'), 'title' => t('Node published'), 'icon' => 'icon_node.png', 'description' => t('The published status 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; case 'author': $block->title = t('Author'); $block->content = !empty($conf['link']) ? theme('username', $node) : check_plain($node->name ? $node->name : variable_get('anonymous', t('Anonymous'))); break; case 'status': $block->title = t('Published'); switch ($conf['boolean_format']) { case 'yes-no': default: $block->content = $node->status ? t('Yes') : t('No'); break; case 'true-false': $block->content = $node->status ? t('True') : t('False'); break; case 'on-off': $block->content = $node->status ? t('On') : t('Off'); break; } 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', ); } if ($form_state['subtype_name'] == 'author') { $form['link'] = array( '#title' => t('Link to author profile'), '#type' => 'checkbox', '#default_value' => $conf['link'], '#description' => t('Check here to make the field link to the author profile.'), ); } if ($form_state['subtype_name'] == 'status') { $form['boolean_format'] = array( '#type' => 'select', '#title' => t('Output format'), '#options' => array( 'yes-no' => t('Yes/No'), 'true-false' => t('True/False'), 'on-off' => t('On/Off'), ), '#default_value' => $conf['boolean_format'], ); } } /** * 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'])); }