Skip to content
Snippets Groups Projects
Commit ba265ecd authored by Brad Jones's avatar Brad Jones
Browse files

Update test entity

parent a770acad
No related branches found
No related tags found
No related merge requests found
name: OpenApi Test Resources
type: module
description: Resource dependecies for running tests for the OpenApi Module.
description: Resource dependencies for running tests for the OpenApi Module.
core: 8.x
core_version_requirement: '^8 || ^9'
package: Testing
......@@ -83,6 +83,10 @@ class OpenApiTestEntity extends ContentEntityBase implements OpenApiTestEntityIn
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['json_data'] = BaseFieldDefinition::create('openapi_json_backed_test')
->setLabel(t('JSON-backed data'))
->setRequired(TRUE);
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
$fields['menu_link'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Menu link'))
......
......
<?php
declare(strict_types=1);
namespace Drupal\openapi_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\MapItem;
use Drupal\Core\Serialization\Attribute\JsonSchema;
/**
* Field type with JSON data storage.
*
* @FieldType(
* id = "openapi_json_backed_test",
* label = @Translation("JSON-backed field (test)"),
* description = @Translation("A field containing JSON-backed properties."),
* )
*/
class JsonBackedPropertiesItem extends MapItem {
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'json_value' => [
'type' => 'json',
],
],
];
}
/**
* {@inheritdoc}
*/
#[JsonSchema([
'type' => 'object',
'properties' => [
'property1' => ['type' => 'string'],
'property2' => ['type' => 'boolean'],
],
])]
public function getValue() {
return parent::getValue();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment