public function FieldCreationTrait::createMinisiteField in Mini site 8
Creates a new ministe field.
Parameters
string $name: The name of the new field (all lowercase), exclude the "field_" prefix.
string $entity_type: The entity type.
string $bundle: The bundle that this field will be added to.
array $storage_settings: A list of field storage settings that will be added to the defaults.
array $field_settings: A list of instance settings that will be added to the instance defaults.
array $widget_settings: A list of widget settings that will be added to the widget defaults.
Return value
\Drupal\field\FieldStorageConfigInterface The minisite field.
3 calls to FieldCreationTrait::createMinisiteField()
- FieldValidationTest::testFieldAllowedExtensions in tests/
src/ Functional/ FieldValidationTest.php - Test setting extensions on field configuration page.
- FieldValidationTest::testValidateArchiveFormat in tests/
src/ Functional/ FieldValidationTest.php - Tests the archive format on minisite field.
- FieldValidationTest::testValidateRequired in tests/
src/ Functional/ FieldValidationTest.php - Tests the required property on minisite field.
File
- tests/
src/ Functional/ FieldCreationTrait.php, line 33
Class
- FieldCreationTrait
- Provides methods for creating minisite fields.
Namespace
Drupal\Tests\minisite\FunctionalCode
public function createMinisiteField($name, $entity_type, $bundle, array $storage_settings = [], array $field_settings = [], array $widget_settings = []) {
/** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
$field_storage = FieldStorageConfig::create([
'entity_type' => $entity_type,
'field_name' => $name,
'type' => 'minisite',
'settings' => $storage_settings,
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
]);
$field_storage
->save();
$this
->attachMinisiteField($name, $entity_type, $bundle, $field_settings, $widget_settings);
return $field_storage;
}