twig_theme_test.module

Same filename in other branches
  1. 9 core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module
  2. 8.9.x core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module
  3. 10 core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module

File

core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module

View source
<?php


/**
 * @file
 * Test module.
 */
declare (strict_types=1);

/**
 * 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 [
        'twig_null' => [
            'value' => NULL,
            'expected' => '',
        ],
        'twig_bool_false' => [
            'value' => FALSE,
            'expected' => '',
        ],
        'twig_bool_true' => [
            'value' => TRUE,
            'expected' => '1',
        ],
        'twig_int' => [
            'value' => 1,
            'expected' => '1',
        ],
        'twig_int_0' => [
            'value' => 0,
            'expected' => '0',
        ],
        'twig_float' => [
            'value' => 122.34343,
            'expected' => '122.34343',
        ],
        'twig_string' => [
            'value' => 'Hello world!',
            'expected' => 'Hello world!',
        ],
    ];
}

/**
 * Implements template_preprocess_status_messages().
 */
function twig_theme_test_preprocess_status_messages(&$variables) : void {
    $variables['attributes']['class'][] = 'custom-test-messages-class';
}

Functions

Title Deprecated Summary
twig_theme_test_preprocess_status_messages Implements template_preprocess_status_messages().
_test_theme_twig_php_values Helper function to test PHP variables in the Twig engine.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.