computed_field-8.x-2.x-dev/tests/modules/test_computed_field_plugins/src/Plugin/ComputedField/TestString.php
tests/modules/test_computed_field_plugins/src/Plugin/ComputedField/TestString.php
<?php
namespace Drupal\test_computed_field_plugins\Plugin\ComputedField;
use Drupal\computed_field\Attribute\ComputedField;
use Drupal\computed_field\Field\ComputedFieldDefinitionWithValuePluginInterface;
use Drupal\computed_field\Plugin\ComputedField\ComputedFieldBase;
use Drupal\computed_field\Plugin\ComputedField\SingleValueTrait;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Computed field which outputs a simple string.
*/
#[ComputedField(
id: "test_string",
label: new TranslatableMarkup("Test string"),
field_type: "string",
)]
class TestString extends ComputedFieldBase {
use SingleValueTrait;
/**
* {@inheritdoc}
*/
public function singleComputeValue(EntityInterface $host_entity, ComputedFieldDefinitionWithValuePluginInterface $computed_field_definition): mixed {
return 'cake!';
}
}
