token.inc in Custom Formatters 7.2
Same filename in this branch
Token engine for Custom Formatters modules.
File
engines/token.incView source
<?php
/**
* @file
* Token engine for Custom Formatters modules.
*/
/**
* Theme alter for 'HTML + Token' engine.
*
* @param array $theme
* A keyed array as expected by hook_theme().
*/
function custom_formatters_engine_token_theme_alter(&$theme) {
$theme['custom_formatters_token_export'] = array(
'variables' => array(
'item' => NULL,
'module' => NULL,
),
'template' => 'token.export',
'path' => drupal_get_path('module', 'custom_formatters') . '/engines',
);
}
/**
* Settings form callback for Custom Formatters Token engine.
*
* @param array $form
* The form api array.
*/
function custom_formatters_engine_token_settings_form(&$form) {
$form['code']['#attributes']['class'][] = 'syntax-html';
// Additional debugging modes.
$form['preview']['options']['dpm'] = array(
'#type' => 'container',
);
$form['preview']['options']['dpm']['html'] = array(
'#type' => 'checkbox',
'#title' => t('Output raw HTML (requires !devel module).', array(
'!devel' => l(t('Devel'), 'http://drupal.org/project/devel'),
)),
'#default_value' => module_exists('devel'),
'#disabled' => !module_exists('devel'),
);
}
/**
* Render callback for Custom Formatters Token engine.
*
* @param object $formatter
* The Custom formatter object.
* @param string $obj_type
* The Entity type.
* @param object $object
* The Entity object.
* @param array $field
* The Field settings.
* @param array $instance
* The Field instance.
* @param string $langcode
* The language code.
* @param array $items
* The Field items.
* @param array $display
* The display settings.
*
* @return mixed|bool
* The output of the Custom formatter or FALSE.
*/
function custom_formatters_engine_token_render($formatter, $obj_type, $object, $field, $instance, $langcode, $items, $display) {
$element = array();
foreach ($items as $delta => $item) {
$text = $formatter->code;
$token_data = array(
'obj_type' => $obj_type,
$obj_type => $object,
'item' => $item,
);
drupal_alter('custom_formatters_token_data', $token_data, $text, $field, $delta);
$element[$delta] = array(
'#markup' => token_replace($text, $token_data, array(
'clear' => TRUE,
)),
);
}
return $element;
}
/**
* Export callback for Custom Formatters Token engine.
*
* @param object $item
* The Custom formatter object.
* @param string $module
* The user defined module name.
*
* @return string
* The exported formatter value.
*/
function custom_formatters_engine_token_export($item, $module) {
return theme('custom_formatters_token_export', array(
'item' => $item,
'module' => $module,
));
}
Functions
Name | Description |
---|---|
custom_formatters_engine_token_export | Export callback for Custom Formatters Token engine. |
custom_formatters_engine_token_render | Render callback for Custom Formatters Token engine. |
custom_formatters_engine_token_settings_form | Settings form callback for Custom Formatters Token engine. |
custom_formatters_engine_token_theme_alter | Theme alter for 'HTML + Token' engine. |