Contemplate example node is always latest by date. But sometimes I need to load not the latest node by date, but the node with exact NID, because some fields may be empty, some others may be filled.

So I want to introduce the code which adds a new feature: when the user is editing some node type template, he may enter the NID he wants. If this node exists and it has the same type with the template the user is editing, it loads as example.

I don't know if this feature would be helpful to others, but if so - maybe, current developer would check it and include the code provided in new builds?

So, latest contemplate.module, 7.x-dev,
1.

function contemplate_edit_type_form($form, &$form_state, $type = NULL) {
//...
//near $form['teaser']
//
  $form['needednid'] = array(
	'#type'				=> 'textfield',
	'#title'			=> t('Node ID to load'),
	'#default_value'	=> isset($_SESSION['contemplatenid']) ? intval($_SESSION['contemplatenid']) : '',
	);
//
//...The rest function is original
//

2.

function contemplate_edit_type_form_submit($form, &$form_state) {
unset($_SESSION['contemplatenid']);
if(isset($form_state['values']['needednid']) && ($nid = intval($form_state['values']['needednid'])) != 0)
{
	$node = node_load($nid);
	
	if($node->type == $form_state['values']['type'])
	{
		$_SESSION['contemplatenid'] = $nid;
	}
	else
	{		
		drupal_set_message(t('The node with NID you provided does not exist or its type differs from the template type.'));
	}
}
//
//...The rest function is original
//

3.

function contemplate_node_views($type) {
if(isset($_SESSION['contemplatenid']))
  {
  $result = db_query("SELECT nid FROM {node} WHERE nid=:nid AND type = :type ORDER BY created DESC", array(':nid'=>intval($_SESSION['contemplatenid']),':type' => $type->type));
  }
  else
  {
  $result = db_query("SELECT nid FROM {node} WHERE type = :type ORDER BY created DESC", array(':type' => $type->type));
  }

//
//...The rest function is original
//
CommentFileSizeAuthor
#2 contemplate.module.patch2.21 KBconspirolog
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jrglasgow’s picture

If you provide a patch with the proper code formatting I will consider it

conspirolog’s picture

FileSize
2.21 KB

Patch to contemplate.module in attach.