protected function DateTestBase::createField in Drupal 8
Same name in this branch
- 8 core/modules/datetime/src/Tests/DateTestBase.php \Drupal\datetime\Tests\DateTestBase::createField()
- 8 core/modules/datetime/tests/src/Functional/DateTestBase.php \Drupal\Tests\datetime\Functional\DateTestBase::createField()
Same name and namespace in other branches
- 9 core/modules/datetime/tests/src/Functional/DateTestBase.php \Drupal\Tests\datetime\Functional\DateTestBase::createField()
Creates a date test field.
1 call to DateTestBase::createField()
- DateTestBase::setUp in core/
modules/ datetime/ tests/ src/ Functional/ DateTestBase.php
File
- core/
modules/ datetime/ tests/ src/ Functional/ DateTestBase.php, line 113
Class
- DateTestBase
- Provides a base class for testing Datetime field functionality.
Namespace
Drupal\Tests\datetime\FunctionalCode
protected function createField() {
$field_name = mb_strtolower($this
->randomMachineName());
$field_label = Unicode::ucfirst(mb_strtolower($this
->randomMachineName()));
$type = $this
->getTestFieldType();
$widget_type = $formatter_type = $type . '_default';
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => $type,
'settings' => [
'datetime_type' => DateTimeItem::DATETIME_TYPE_DATE,
],
]);
$this->fieldStorage
->save();
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'label' => $field_label,
'bundle' => 'entity_test',
'description' => 'Description for ' . $field_label,
'required' => TRUE,
]);
$this->field
->save();
EntityFormDisplay::load('entity_test.entity_test.default')
->setComponent($field_name, [
'type' => $widget_type,
])
->save();
$this->displayOptions = [
'type' => $formatter_type,
'label' => 'hidden',
'settings' => [
'format_type' => 'medium',
] + $this->defaultSettings,
];
EntityViewDisplay::create([
'targetEntityType' => $this->field
->getTargetEntityTypeId(),
'bundle' => $this->field
->getTargetBundle(),
'mode' => 'full',
'status' => TRUE,
])
->setComponent($field_name, $this->displayOptions)
->save();
}