function RESTTestBase::configEntityValues

Provides an array of suitable property values for a config entity type.

Config entities have some common keys that need to be created. Required properties differ among config entity types, so we keep a minimum mapping here.

Parameters

string $entity_type_id: The ID of the type of entity that should be created.

Return value

array An array of values keyed by property name.

1 call to RESTTestBase::configEntityValues()
RESTTestBase::entityValues in core/modules/rest/src/Tests/RESTTestBase.php
Provides an array of suitable property values for an entity type.

File

core/modules/rest/src/Tests/RESTTestBase.php, line 613

Class

RESTTestBase
Test helper class that provides a REST client method to send HTTP requests.

Namespace

Drupal\rest\Tests

Code

protected function configEntityValues($entity_type_id) {
    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
    $keys = $entity_type->getKeys();
    $values = [];
    // Fill out known key values that are shared across entity types.
    foreach ($keys as $key) {
        if ($key === 'id' || $key === 'label') {
            $values[$key] = $this->randomMachineName();
        }
    }
    // Add extra values for particular entity types.
    switch ($entity_type_id) {
        case 'block':
            $values['plugin'] = 'system_powered_by_block';
            break;
    }
    return $values;
}

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