Skip to content

Instantly share code, notes, and snippets.

@balsama
Last active August 29, 2015 14:02
Show Gist options
  • Save balsama/07febae122b2aa0a7f48 to your computer and use it in GitHub Desktop.
Save balsama/07febae122b2aa0a7f48 to your computer and use it in GitHub Desktop.
Custom Formatter to display published on date as defined by the "Publication Date" module. (Use this gist as CTools Import Code)
$formatter = new stdClass();
$formatter->disabled = FALSE; /* Edit this to true to make a default formatter disabled initially */
$formatter->api_version = 2;
$formatter->name = 'published_date';
$formatter->label = 'Published Date';
$formatter->description = 'Displays the date that the node was published.';
$formatter->mode = 'php';
$formatter->field_types = 'list_boolean';
$formatter->code = 'if ($variables[\'#items\'][0][\'value\']) {
if (isset($variables[\'#object\']->published_at)) {
return date(\'m.d.Y\', $variables[\'#object\']->published_at);
}
else {
return \'<p>Missing plugin. Please install the `publication_date` module or select a different formatter for the \' . $variables[\'#field\'][\'field_name\'] . \' field.</p>\';
}
}
else {
return false;
}';
$formatter->fapi = '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment