You are here

function custom_formatters_engine_php_render in Custom Formatters 7.2

Render callback for Custom Formatters PHP engine.

Parameters

object $formatter: The Custom formatter object.

string $obj_type: The Entity type.

object $object: The Entity object.

array $field: The Field settings.

array $instance: The Field instance.

string $langcode: The language code.

array $items: The Field items.

array $display: The display settings.

Return value

mixed|bool The output of the Custom formatter or FALSE.

1 string reference to 'custom_formatters_engine_php_render'
custom_formatters_custom_formatters_engine_info in includes/custom_formatters.inc
Implements hook_custom_formatters_engine().

File

engines/php.inc, line 96
PHP engine for Custom Formatters modules.

Code

function custom_formatters_engine_php_render($formatter, $obj_type, $object, $field, $instance, $langcode, $items, $display) {
  global $theme_path, $theme_info, $conf;

  // Store current theme path.
  $old_theme_path = $theme_path;

  // Restore theme_path to the theme, as long as php_eval() executes,
  // so code evaluated will not see the caller module as the current theme.
  // If theme info is not initialized get the path from theme_default.
  if (!isset($theme_info)) {
    $theme_path = drupal_get_path('theme', $conf['theme_default']);
  }
  else {
    $theme_path = dirname($theme_info->filename);
  }

  // Build variables array for formatter.
  $variables = array(
    '#obj_type' => $obj_type,
    '#object' => $object,
    '#field' => $field,
    '#instance' => $instance,
    '#langcode' => $langcode,
    '#items' => $items,
    '#display' => $display,
  );
  ob_start();
  $output = eval($formatter->code);
  $output = !empty($output) ? $output : ob_get_contents();
  ob_end_clean();

  // Preview debugging; Show the available variables data.
  if (module_exists('devel') && isset($formatter->preview) && $formatter->preview['options']['dpm']['vars']) {
    dpm($variables);
  }

  // Recover original theme path.
  $theme_path = $old_theme_path;
  return empty($output) ? FALSE : $output;
}