function EntityTestHooks::entityBaseFieldInfoAlter

Implements hook_entity_base_field_info_alter().

File

core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php, line 97

Class

EntityTestHooks
Hook implementations for entity_test.

Namespace

Drupal\entity_test\Hook

Code

public function entityBaseFieldInfoAlter(&$fields, EntityTypeInterface $entity_type) {
    $state = \Drupal::state();
    if ($entity_type->id() == 'entity_test_mulrev' && ($names = $state->get('entity_test.field_definitions.translatable'))) {
        foreach ($names as $name => $value) {
            $fields[$name]->setTranslatable($value);
        }
    }
    if ($entity_type->id() == 'node' && $state->get('entity_test.node_remove_status_field')) {
        unset($fields['status']);
    }
    if ($entity_type->id() == 'entity_test' && $state->get('entity_test.remove_name_field')) {
        unset($fields['name']);
    }
    // In 8001 we are assuming that a new definition with multiple cardinality has
    // been deployed.
    // @todo Remove this if we end up using state definitions at runtime. See
    //   https://www.drupal.org/node/2554235.
    if ($entity_type->id() == 'entity_test' && $state->get('entity_test.db_updates.entity_definition_updates') == 8001) {
        $fields['user_id']->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    }
}

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