View source
<?php
module_load_include('inc', 'twig', 'twig.field');
module_load_include('inc', 'twig', 'twig.filter');
module_load_include('inc', 'twig', 'twig.utils');
function twig_menu() {
return array(
'admin/structure/twig/enable-field' => array(
'title' => t('Enable Twig'),
'page callback' => '_twig_enable_field',
'page arguments' => array(
4,
5,
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'twig.admin.inc',
'type' => MENU_CALLBACK,
),
);
}
function twig_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' && $plugin == 'export_ui') {
return 'plugins/' . $plugin;
}
}
function twig_form_field_ui_field_overview_form_alter(&$form, &$form_state) {
if ($form['fields']['twig_template']['#row_type'] == 'extra_field') {
$form['fields']['twig_template']['edit'] = array(
'#type' => 'link',
'#title' => t('enable'),
'#href' => 'admin/structure/twig/enable-field/' . $form['#entity_type'] . '/' . $form['#bundle'],
);
}
}
function twig_process_node(&$vars) {
if ($vars['view_mode'] == 'full') {
$wrapper = entity_metadata_wrapper('node', $vars['node']);
if (isset($wrapper->twig_template) && ($template = $wrapper->twig_template
->value())) {
$context = _twig_extract_entity_fields($vars['content']);
$vars['content'] = array(
'#markup' => _twig_render($template, $context),
);
$vars['page'] = TRUE;
}
}
}