function EntityTestConstraintViolation::baseFieldDefinitions
Same name in other branches
- 9 core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraintViolation.php \Drupal\entity_test\Entity\EntityTestConstraintViolation::baseFieldDefinitions()
- 8.9.x core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraintViolation.php \Drupal\entity_test\Entity\EntityTestConstraintViolation::baseFieldDefinitions()
- 11.x core/modules/system/tests/modules/entity_test/src/Entity/EntityTestConstraintViolation.php \Drupal\entity_test\Entity\EntityTestConstraintViolation::baseFieldDefinitions()
Overrides EntityTest::baseFieldDefinitions
File
-
core/
modules/ system/ tests/ modules/ entity_test/ src/ Entity/ EntityTestConstraintViolation.php, line 34
Class
- EntityTestConstraintViolation
- Defines the test entity class for testing entity constraint violations.
Namespace
Drupal\entity_test\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['name']->setDisplayOptions('form', [
'type' => 'string',
'weight' => 0,
]);
$fields['name']->addConstraint('FieldWidgetConstraint', []);
// Add a field that uses a widget with a custom implementation for
// \Drupal\Core\Field\WidgetInterface::errorElement().
$fields['test_field'] = BaseFieldDefinition::create('integer')->setLabel(t('Test field'))
->setDisplayOptions('form', [
'type' => 'number',
'weight' => 1,
])
->addConstraint('FieldWidgetConstraint', []);
return $fields;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.