Create extra fields on nodes

Use hook_field_extra_fields to use the new fields with the manage display function. The content of the new field is built in hook_node_view.


/**
 * Implements hook_field_extra_fields().
 */
function demo_field_extra_fields() {
  $extra = array();

  $extra['node']['article'] = array(
    'display' => array(
      'EXTRA_FIELD' => array(
        'label' => 'LABEL',
        'description' => t('DESCRIPTION'),
        'weight' => -99,
      ),
    )
  );
  
  return $extra;
}

/**
 * Implements hook_node_view().
 */
function demo_node_view($node, $view_mode, $langcode) {
  
  switch ($node->type) {
    case 'article':
      
      $node->content['EXTRA_FIELD'] = array(
        '#markup' => 'MARKUP COMES HERE.'
      );
     
      break;
  }
 
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.