View source
<?php
use Drupal\Core\Extension\Extension;
function theme_test_theme($existing, $type, $theme, $path) {
$items['theme_test'] = array(
'file' => 'theme_test.inc',
'variables' => array(
'foo' => '',
),
'function' => 'theme_theme_test',
);
$items['theme_test_template_test'] = array(
'template' => 'theme_test.template_test',
);
$items['theme_test_template_test_2'] = array(
'template' => 'theme_test.template_test',
);
$items['theme_test_suggestion_provided'] = array(
'variables' => array(),
);
$items['theme_test_specific_suggestions'] = array(
'variables' => array(),
);
$items['theme_test_suggestions'] = array(
'variables' => array(),
);
$items['theme_test_general_suggestions'] = array(
'variables' => array(),
);
$items['theme_test_function_suggestions'] = array(
'variables' => array(),
'function' => 'theme_theme_test_function_suggestions',
);
$items['theme_test_suggestions_include'] = array(
'variables' => array(),
'function' => 'theme_theme_test_suggestions_include',
);
$items['theme_test_foo'] = array(
'variables' => array(
'foo' => NULL,
),
'function' => 'theme_theme_test_foo',
);
$items['theme_test_render_element'] = array(
'render element' => 'elements',
);
$items['theme_test_render_element_children'] = array(
'render element' => 'element',
'function' => 'theme_theme_test_render_element_children',
);
$items['theme_test_function_template_override'] = array(
'variables' => array(),
'function' => 'theme_theme_test_function_template_override',
);
$info['test_theme_not_existing_function'] = array(
'function' => 'test_theme_not_existing_function',
);
$items['theme_test_preprocess_suggestions'] = [
'variables' => [
'foo' => '',
'bar' => '',
],
];
return $items;
}
function theme_test_preprocess_html(&$variables) {
$variables['html_attributes']['theme_test_html_attribute'] = 'theme test html attribute value';
$variables['attributes']['theme_test_body_attribute'] = 'theme test body attribute value';
$variables['attributes']['theme_test_page_variable'] = 'Page variable is an array.';
}
function theme_test_page_bottom(array &$page_bottom) {
$page_bottom['theme_test_page_bottom'] = array(
'#markup' => 'theme test page bottom markup',
);
}
function template_preprocess_theme_test_function_suggestions(&$variables) {
}
function theme_theme_test_foo($variables) {
return $variables['foo'];
}
function theme_theme_test_function_template_override($variables) {
return 'theme_test_function_template_override test failed.';
}
function theme_test_theme_suggestions_theme_test_preprocess_suggestions($variables) {
return [
'theme_test_preprocess_suggestions__' . $variables['foo'],
];
}
function theme_test_preprocess_theme_test_preprocess_suggestions(&$variables) {
$variables['foo'] = 'Theme hook implementor=theme_theme_test_preprocess_suggestions().';
}
function theme_test_preprocess_theme_test_preprocess_suggestions__monkey(&$variables) {
$variables['foo'] = 'Monkey';
}
function template_preprocess_theme_test_render_element(&$variables) {
$variables['attributes']['data-variables-are-preprocessed'] = TRUE;
}
function theme_theme_test_render_element_children($variables) {
return drupal_render($variables['element']);
}
function theme_theme_test_function_suggestions($variables) {
return 'Original theme function.';
}
function theme_test_theme_suggestions_theme_test_suggestion_provided(array $variables) {
return array(
'theme_test_suggestion_provided__' . 'foo',
);
}
function theme_test_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
drupal_set_message(__FUNCTION__ . '() executed.');
}
function theme_test_theme_suggestions_theme_test_suggestions_alter(array &$suggestions, array $variables) {
drupal_set_message(__FUNCTION__ . '() executed.');
}
function theme_theme_test_suggestions_include($variables) {
return 'Original function before altering theme suggestions.';
}
function theme_test_system_info_alter(array &$info, Extension $file, $type) {
if ($type == 'theme' && $file
->getName() == 'test_theme' && \Drupal::state()
->get('theme_test.modify_info_files')) {
$info += [
'libraries' => [],
];
$info['libraries'][] = 'core/backbone';
}
}
function theme_test_theme_suggestions_node(array $variables) {
$xss = '<script type="text/javascript">alert(\'yo\');</script>';
$suggestions[] = 'node__' . $xss;
return $suggestions;
}