Entity Formatter

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

For a general introduction to the Entity Formatter module view its module page.

API Documentation

The full API Documentation can be found here: http://entity_formatter.valderama.net

Examples

Print the first value

  print $page->getImages()->setImageStyle('thumbnail')->img(); 

Print the first value (if present) with label

  if ($page->getImages()->isDeltaValid()) {
    print t('Images') . ':';
    print $page->getImages()->img();
  } 

Print all values

  foreach ($page->getImages() as $image) {
    print $image->setImageStyle('thumbnail')->img();
  } 

Print the third value

  if ($page->getImages()->isDeltaValid(3)) {
    print $page->getImages()->setDelta(3)->img();
  } 

Print first until third value (if present)

  $num_to_print = min(3, count($page->getImages()));
  for ($delta = 0; $delta < $num_to_print; $delta++) {
    print $page->getImages()->setDelta($delta)->img();
  } 

Drush

The module provides a single drush command "entity-formatter-make" or short "efm".

drush efm node --bundles=page,article --module=entity_formatter_custom

This example generates formatter classes for page and article node types and place them in the entity_formatter_custom module (generating module if not exists).

Usage examples for entity_formatter_wrap()

entity_formatter_wrap() is a helper function to wrap field values with some markup and labels. Its wraps your field values with HMTL with a

Guide maintainers

valderama's picture