twig_theme_test.module 3.02 KB
Newer Older
1 2 3 4 5 6
<?php

/**
 * Implements hook_theme().
 */
function twig_theme_test_theme($existing, $type, $theme, $path) {
7
  $items['twig_theme_test_filter'] = array(
8
    'variables' => array('quote' => array(), 'attributes' => array()),
9 10
    'template' => 'twig_theme_test.filter',
  );
11 12 13
  $items['twig_theme_test_php_variables'] = array(
    'template' => 'twig_theme_test.php_variables',
  );
14 15 16 17
  $items['twig_theme_test_trans'] = array(
    'variables' => array(),
    'template' => 'twig_theme_test.trans',
  );
18 19 20 21
  $items['twig_theme_test_placeholder_outside_trans'] = array(
    'variables' => array('var' => ''),
    'template' => 'twig_theme_test.placeholder_outside_trans',
  );
22 23 24 25
  $items['twig_namespace_test'] = array(
    'variables' => array(),
    'template' => 'twig_namespace_test',
  );
26 27 28 29 30 31 32 33 34
  $items['twig_registry_loader_test'] = array(
    'variables' => array(),
  );
  $items['twig_registry_loader_test_include'] = array(
    'variables' => array(),
  );
  $items['twig_registry_loader_test_extend'] = array(
    'variables' => array(),
  );
35 36 37
  $items['twig_raw_test'] = array(
    'variables' => array('script' => ''),
  );
38 39 40
  $items['twig_autoescape_test'] = array(
    'variables' => array('script' => ''),
  );
41 42 43 44
  $items['twig_theme_test_url_generator'] = array(
    'variables' => array(),
    'template' => 'twig_theme_test.url_generator',
  );
45
  $items['twig_theme_test_link_generator'] = array(
46 47 48 49 50
    'variables' => [
      'test_url' => NULL,
      'test_url_attribute' => NULL,
      'attributes' => [],
    ],
51 52
    'template' => 'twig_theme_test.link_generator',
  );
53 54 55 56
  $items['twig_theme_test_url_to_string'] = array(
    'variables' => array('test_url' => NULL),
    'template' => 'twig_theme_test.url_to_string',
  );
57 58 59 60
  $items['twig_theme_test_file_url'] = array(
    'variables' => array(),
    'template' => 'twig_theme_test.file_url',
  );
61 62 63 64
  $items['twig_theme_test_attach_library'] = array(
    'variables' => array(),
    'template' => 'twig_theme_test.attach_library',
  );
65 66 67 68 69 70
  $items['twig_theme_test_renderable'] = array(
    'variables' => array(
      'renderable' => NULL,
    ),
    'template' => 'twig_theme_test.renderable',
  );
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  return $items;
}

/*
 * Helper function to test PHP variables in the Twig engine.
 */
function _test_theme_twig_php_values() {
  // Prefix each variable with "twig_" so that Twig doesn't get confused
  // between a variable and a primitive. Arrays are not tested since they should
  // be a Drupal render array.
  return array(
    'twig_null' => array(
      'value' => NULL,
      'expected' => '',
    ),
    'twig_bool_false' => array(
      'value' => FALSE,
      'expected' => '',
    ),
    'twig_bool_true' => array(
      'value' => TRUE,
      'expected' => '1',
    ),
    'twig_int' => array(
      'value' => 1,
      'expected' => '1',
    ),
    'twig_int_0' => array(
      'value' => 0,
      'expected' => '0',
    ),
    'twig_float' => array(
      'value' => 122.34343,
      'expected' => '122.34343',
    ),
    'twig_string' => array(
      'value' => 'Hello world!',
      'expected' => 'Hello world!',
    ),
  );
}