taxonomy_test.module

Same filename and directory in other branches
  1. 7.x modules/simpletest/tests/taxonomy_test.module
  2. 9 core/modules/taxonomy/tests/modules/taxonomy_test/taxonomy_test.module
  3. 8.9.x core/modules/taxonomy/tests/modules/taxonomy_test/taxonomy_test.module
  4. 11.x core/modules/taxonomy/tests/modules/taxonomy_test/taxonomy_test.module

Provides test hook implementations for taxonomy tests.

File

core/modules/taxonomy/tests/modules/taxonomy_test/taxonomy_test.module

View source
<?php


/**
 * @file
 * Provides test hook implementations for taxonomy tests.
 */

use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_query_alter().
 */
function taxonomy_test_query_alter(AlterableInterface $query) {
  $value = \Drupal::state()->get(__FUNCTION__);
  if (isset($value)) {
    \Drupal::state()->set(__FUNCTION__, ++$value);
  }
}

/**
 * Implements hook_query_TAG_alter().
 */
function taxonomy_test_query_term_access_alter(AlterableInterface $query) {
  $value = \Drupal::state()->get(__FUNCTION__);
  if (isset($value)) {
    \Drupal::state()->set(__FUNCTION__, ++$value);
  }
}

/**
 * Implements hook_query_TAG_alter().
 */
function taxonomy_test_query_taxonomy_term_access_alter(AlterableInterface $query) {
  $value = \Drupal::state()->get(__FUNCTION__);
  if (isset($value)) {
    \Drupal::state()->set(__FUNCTION__, ++$value);
  }
}

/**
 * Implements hook_form_BASE_FORM_ID_alter() for the taxonomy term form.
 */
function taxonomy_test_form_taxonomy_term_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (\Drupal::state()->get('taxonomy_test.disable_parent_form_element', FALSE)) {
    $form['relations']['parent']['#disabled'] = TRUE;
  }
}

/**
 * Implements hook_ENTITY_TYPE_load() for the taxonomy term.
 */
function taxonomy_test_taxonomy_term_load($entities) {
  $value = \Drupal::state()->get(__FUNCTION__);
  // Only record loaded terms is the test has set this to an empty array.
  if (is_array($value)) {
    $value = array_merge($value, array_keys($entities));
    \Drupal::state()->set(__FUNCTION__, array_unique($value));
  }
}

Functions

Title Deprecated Summary
taxonomy_test_form_taxonomy_term_form_alter Implements hook_form_BASE_FORM_ID_alter() for the taxonomy term form.
taxonomy_test_query_alter Implements hook_query_alter().
taxonomy_test_query_taxonomy_term_access_alter Implements hook_query_TAG_alter().
taxonomy_test_query_term_access_alter Implements hook_query_TAG_alter().
taxonomy_test_taxonomy_term_load Implements hook_ENTITY_TYPE_load() for the taxonomy term.

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