Egen modul, template och preprocess funktion.. behöver lite förklaring :)

Events happening in the community are now at Drupal community events on www.drupal.org.
Urme's picture

Sitter och testar och gör en egen modul för en cck formatter.

Så här ser koden ut i formattertest.module.

function formattertest_field_formatter_info() {
  $formatters['breakingnews'] = array(
    'label' => t('Breaking news: Full image'),
    'field types' => array('nodereference'),
    'description' => t('Displays a teaser with large image above'),
  ); 
  return $formatters;
}

function formattertest_theme() {
  $theme['formattertest_formatter_breakingnews'] = array('template' => 'formattertest_formatter_breakingnews','arguments' => array('element' => NULL));
 
  return $theme;
}

function formattertest_preprocess_formattertest_formatter_breakingnews(&$variables) {
   dsm($variables);
}

Sedan har jag en template fil som ser ut så här:

$importednode = node_load($element['#item']['nid']);
  $output = '';
  $output .= t('Breaking news!!').'<br /><br />';
  $output .= '<br />'.$importednode->teaser.'<br />'.t('Comments:').$importednode->comment_count;
  echo $output;

Template filen ser ju inge vidare ut, jag vill flytta över node_load(); till preprocess funktionen, min fråga är varför $variables innehåller massa mer än $element som jag kan använda direkt i template filen. $variables['element'] är samma som just $element, kan jag få att preprocess funktionen får in bara just $element eller är det standard att jag får in allt?

Template filens upplägg är bara ett test än så länge.

Detta är mitt "första" försök på en modul, så ha överseende :)

Sweden

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: