class TaxonomyTestHooks

Hook implementations for taxonomy_test.

Hierarchy

Expanded class hierarchy of TaxonomyTestHooks

File

core/modules/taxonomy/tests/modules/taxonomy_test/src/Hook/TaxonomyTestHooks.php, line 19

Namespace

Drupal\taxonomy_test\Hook
View source
class TaxonomyTestHooks {
    
    /**
     * Implements hook_entity_access().
     */
    public function entityAccess(EntityInterface $entity, string $operation, AccountInterface $account) : AccessResultInterface {
        if ($entity instanceof TermInterface) {
            $parts = explode(' ', (string) $entity->label());
            if (in_array('Inaccessible', $parts, TRUE) && in_array($operation, $parts, TRUE)) {
                return AccessResult::forbidden();
            }
        }
        return AccessResult::neutral();
    }
    
    /**
     * Implements hook_query_alter().
     */
    public function queryAlter(AlterableInterface $query) : void {
        $value = \Drupal::state()->get('taxonomy_test_query_alter');
        if (isset($value)) {
            \Drupal::state()->set('taxonomy_test_query_alter', ++$value);
        }
    }
    
    /**
     * Implements hook_query_TAG_alter().
     */
    public function queryTermAccessAlter(AlterableInterface $query) : void {
        $value = \Drupal::state()->get('taxonomy_test_query_term_access_alter');
        if (isset($value)) {
            \Drupal::state()->set('taxonomy_test_query_term_access_alter', ++$value);
        }
    }
    
    /**
     * Implements hook_query_TAG_alter().
     */
    public function queryTaxonomyTermAccessAlter(AlterableInterface $query) : void {
        $value = \Drupal::state()->get('taxonomy_test_query_taxonomy_term_access_alter');
        if (isset($value)) {
            \Drupal::state()->set('taxonomy_test_query_taxonomy_term_access_alter', ++$value);
        }
    }
    
    /**
     * Implements hook_form_BASE_FORM_ID_alter() for the taxonomy term form.
     */
    public function formTaxonomyTermFormAlter(&$form, FormStateInterface $form_state, $form_id) : void {
        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.
     */
    public function taxonomyTermLoad($entities) {
        $value = \Drupal::state()->get('taxonomy_test_taxonomy_term_load');
        // 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('taxonomy_test_taxonomy_term_load', array_unique($value));
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
TaxonomyTestHooks::entityAccess public function Implements hook_entity_access().
TaxonomyTestHooks::formTaxonomyTermFormAlter public function Implements hook_form_BASE_FORM_ID_alter() for the taxonomy term form.
TaxonomyTestHooks::queryAlter public function Implements hook_query_alter().
TaxonomyTestHooks::queryTaxonomyTermAccessAlter public function Implements hook_query_TAG_alter().
TaxonomyTestHooks::queryTermAccessAlter public function Implements hook_query_TAG_alter().
TaxonomyTestHooks::taxonomyTermLoad public function 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.