common_test.module

Same filename in other branches
  1. 7.x modules/simpletest/tests/common_test.module
  2. 9 core/modules/system/tests/modules/common_test/common_test.module
  3. 8.9.x core/modules/system/tests/modules/common_test/common_test.module
  4. 10 core/modules/system/tests/modules/common_test/common_test.module

File

core/modules/system/tests/modules/common_test/common_test.module

View source
<?php


/**
 * @file
 * Helper module for the Common tests.
 */
declare (strict_types=1);

/**
 * Implements hook_TYPE_alter().
 *
 * Same as common_test_drupal_alter_alter(), but here, we verify that themes
 * can also alter and come last.
 */
function olivero_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
    // Alter first argument.
    if (is_array($data)) {
        $data['foo'] .= ' theme';
    }
    elseif (is_object($data)) {
        $data->foo .= ' theme';
    }
    // Alter second argument, if present.
    if (isset($arg2)) {
        if (is_array($arg2)) {
            $arg2['foo'] .= ' theme';
        }
        elseif (is_object($arg2)) {
            $arg2->foo .= ' theme';
        }
    }
    // Try to alter third argument, if present.
    if (isset($arg3)) {
        if (is_array($arg3)) {
            $arg3['foo'] .= ' theme';
        }
        elseif (is_object($arg3)) {
            $arg3->foo .= ' theme';
        }
    }
}

/**
 * Implements hook_module_implements_alter().
 *
 * @see block_drupal_alter_foo_alter()
 */
function common_test_module_implements_alter(&$implementations, $hook) {
    // For
    // \Drupal::moduleHandler()->alter(array('drupal_alter', 'drupal_alter_foo'), ...),
    // make the block module implementations run after all the other modules. Note
    // that when \Drupal::moduleHandler->alter() is called with an array of types,
    // the first type is considered primary and controls the module order.
    if ($hook == 'drupal_alter_alter' && isset($implementations['block'])) {
        $group = $implementations['block'];
        unset($implementations['block']);
        $implementations['block'] = $group;
    }
}

/**
 * Implements MODULE_preprocess().
 *
 * @see RenderTest::testDrupalRenderThemePreprocessAttached()
 */
function common_test_preprocess(&$variables, $hook) {
    if (!\Drupal::state()->get('theme_preprocess_attached_test', FALSE)) {
        return;
    }
    $variables['#attached']['library'][] = 'test/generic_preprocess';
}

/**
 * Implements MODULE_preprocess_HOOK().
 *
 * @see RenderTest::testDrupalRenderThemePreprocessAttached()
 */
function common_test_preprocess_common_test_render_element(&$variables) {
    if (!\Drupal::state()->get('theme_preprocess_attached_test', FALSE)) {
        return;
    }
    $variables['#attached']['library'][] = 'test/specific_preprocess';
}

Functions

Title Deprecated Summary
common_test_module_implements_alter Implements hook_module_implements_alter().
common_test_preprocess Implements MODULE_preprocess().
common_test_preprocess_common_test_render_element Implements MODULE_preprocess_HOOK().
olivero_drupal_alter_alter Implements hook_TYPE_alter().

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