entity_test_bundle_class.module

Same filename and directory in other branches
  1. 10 core/modules/system/tests/modules/entity_test_bundle_class/entity_test_bundle_class.module
  2. 11.x core/modules/system/tests/modules/entity_test_bundle_class/entity_test_bundle_class.module

Support module for testing entity bundle classes.

File

core/modules/system/tests/modules/entity_test_bundle_class/entity_test_bundle_class.module

View source
<?php


/**
 * @file
 * Support module for testing entity bundle classes.
 */
use Drupal\entity_test_bundle_class\Entity\EntityTestAmbiguousBundleClass;
use Drupal\entity_test_bundle_class\Entity\EntityTestBundleClass;
use Drupal\entity_test_bundle_class\Entity\EntityTestUserClass;
use Drupal\entity_test_bundle_class\Entity\EntityTestVariant;
use Drupal\entity_test_bundle_class\Entity\NonInheritingBundleClass;

/**
 * Implements hook_entity_bundle_info_alter().
 */
function entity_test_bundle_class_entity_bundle_info_alter(&$bundles) {
    if (!empty($bundles['entity_test']['bundle_class'])) {
        $bundles['entity_test']['bundle_class']['class'] = EntityTestBundleClass::class;
    }
    if (\Drupal::state()->get('entity_test_bundle_class_enable_ambiguous_entity_types', FALSE)) {
        $bundles['entity_test']['bundle_class_2']['class'] = EntityTestBundleClass::class;
        $bundles['entity_test']['entity_test_no_label']['class'] = EntityTestAmbiguousBundleClass::class;
        $bundles['entity_test_no_label']['entity_test_no_label']['class'] = EntityTestAmbiguousBundleClass::class;
    }
    if (\Drupal::state()->get('entity_test_bundle_class_non_inheriting', FALSE)) {
        $bundles['entity_test']['bundle_class']['class'] = NonInheritingBundleClass::class;
    }
    if (\Drupal::state()->get('entity_test_bundle_class_enable_user_class', FALSE)) {
        $bundles['user']['user']['class'] = EntityTestUserClass::class;
    }
    if (\Drupal::state()->get('entity_test_bundle_class_does_not_exist', FALSE)) {
        $bundles['entity_test']['bundle_class']['class'] = '\\Drupal\\Core\\NonExistentClass';
    }
}

/**
 * Implements hook_entity_type_alter().
 */
function entity_test_bundle_class_entity_type_alter(&$entity_types) {
    
    /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
    if (\Drupal::state()->get('entity_test_bundle_class_override_base_class', FALSE) && isset($entity_types['entity_test'])) {
        $entity_types['entity_test']->setClass(EntityTestVariant::class);
    }
}

Functions

Title Deprecated Summary
entity_test_bundle_class_entity_bundle_info_alter Implements hook_entity_bundle_info_alter().
entity_test_bundle_class_entity_type_alter Implements hook_entity_type_alter().

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