function _entity_test_update_create_test_entities

Creates a given number of 'entity_test_update' entities.

The 'drupal-8.0.0-rc1-filled.standard.entity_test_update.php.gz' db dump was created with the following characteristics:

  • Drupal 8.0.0-rc1 installed with the Standard profile;
  • The 'entity_test_update' module enabled;
  • 102 test entities created and saved.

The 'drupal-8.0.0-rc1-filled.standard.entity_test_update_mul.php.gz' db dump was created with the following characteristics:

  • Drupal 8.0.0-rc1 installed with the Standard profile;
  • Manually edited the annotation of the entity_test_update entity type in order to make it translatable;
  • The entity_test_update and Language module enabled;
  • Romanian language added;
  • 50 test entities created, translated and saved;
  • The Content Translation module enabled and configured for our test entity type. This was enabled after the first 50 entities were created in order to have NULL values for its translation metadata fields (e.g. content_translation_status);
  • 52 more test entities (with the IDs 51 - 102) crated, translated and saved.

The 'drupal-8.0.0-rc1-filled.standard.entity_test_update_mul_rev.php.gz' db dump was created like the multilingual one described above, with one change: The annotation of the entity_test_update entity type was also manually edited in order to make it revisionable.

Parameters

int $start: (optional) The entity ID to start from. Defaults to 1.

int $end: (optional) The entity ID to end with. Defaults to 50.

bool $add_translation: (optional) Whether to create a translation for each entity. If the number of entities is greater than 50, the default translation (en) of the 51st entity and the 52nd translation (ro) are disabled through the 'content_moderation_status' field. Defaults to FALSE.

See also

drupal-8.0.0-rc1-filled.standard.entity_test_update.php.gz

drupal-8.0.0-rc1-filled.standard.entity_test_update_mul.php.gz

File

core/modules/system/tests/modules/entity_test_update/entity_test_update.module, line 105

Code

function _entity_test_update_create_test_entities($start = 1, $end = 50, $add_translation = FALSE) {
    for ($i = $start; $i <= $end; $i++) {
        $entity = EntityTestUpdate::create([
            'id' => $i,
            'name' => $i,
            'test_single_property' => $i . ' - test single property',
            'test_multiple_properties' => [
                [
                    'value1' => $i . ' - test multiple properties - value1',
                    'value2' => $i . ' - test multiple properties - value2',
                ],
            ],
            'test_single_property_multiple_values' => [
                [
                    'value' => $i . ' - test single property multiple values 0',
                ],
                [
                    'value' => $i . ' - test single property multiple values 1',
                ],
            ],
            'test_multiple_properties_multiple_values' => [
                [
                    'value1' => $i . ' - test multiple properties multiple values - value1 0',
                    'value2' => $i . ' - test multiple properties multiple values - value2 0',
                ],
                [
                    'value1' => $i . ' - test multiple properties multiple values - value1 1',
                    'value2' => $i . ' - test multiple properties multiple values - value2 1',
                ],
            ],
            'test_non_rev_field' => $i . ' - test non-revisionable field',
            'test_non_mul_field' => $i . ' - test non-translatable field',
            'test_non_mulrev_field' => $i . ' - test non-translatable and non-revisionable field',
            'field_test_configurable_field' => [
                [
                    'value1' => $i . ' - field test configurable field - value1 0',
                    'value2' => $i . ' - field test configurable field - value2 0',
                ],
                [
                    'value1' => $i . ' - field test configurable field - value1 1',
                    'value2' => $i . ' - field test configurable field - value2 1',
                ],
            ],
            'test_entity_base_field_info' => $i . ' - test entity base field info',
        ]);
        if ($add_translation) {
            $entity->addTranslation('ro', [
                'name' => $i . ' - ro',
                'test_single_property' => $i . ' - test single property - ro',
                'test_multiple_properties' => [
                    [
                        'value1' => $i . ' - test multiple properties - value1 - ro',
                        'value2' => $i . ' - test multiple properties - value2 - ro',
                    ],
                ],
                'test_single_property_multiple_values' => [
                    [
                        'value' => $i . ' - test single property multiple values 0 - ro',
                    ],
                    [
                        'value' => $i . ' - test single property multiple values 1 - ro',
                    ],
                ],
                'test_multiple_properties_multiple_values' => [
                    [
                        'value1' => $i . ' - test multiple properties multiple values - value1 0 - ro',
                        'value2' => $i . ' - test multiple properties multiple values - value2 0 - ro',
                    ],
                    [
                        'value1' => $i . ' - test multiple properties multiple values - value1 1 - ro',
                        'value2' => $i . ' - test multiple properties multiple values - value2 1 - ro',
                    ],
                ],
                'test_non_rev_field' => $i . ' - test non-revisionable field - ro',
                'field_test_configurable_field' => [
                    [
                        'value1' => $i . ' - field test configurable field - value1 0 - ro',
                        'value2' => $i . ' - field test configurable field - value2 0 - ro',
                    ],
                    [
                        'value1' => $i . ' - field test configurable field - value1 1 - ro',
                        'value2' => $i . ' - field test configurable field - value2 1 - ro',
                    ],
                ],
                'test_entity_base_field_info' => $i . ' - test entity base field info - ro',
            ]);
            if ($i == 101) {
                $entity->getTranslation('en')
                    ->set('content_translation_status', FALSE);
            }
            if ($i == 102) {
                $entity->getTranslation('ro')
                    ->set('content_translation_status', FALSE);
            }
        }
        $entity->save();
    }
}

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