I am creating a custom multi-value fieldtype for some functionality that I need.
I have been using the drupal core 'telephone' module and the contrib 'address' module as reference, but am running into some issues.
In the src/Plugins/Field/FieldType.php definition, there is a propertyDefinitions()
method used to define the properties of a field.
The default value provided in the scaffolding provided by Drupal Console provides it as
$properties['value'] = DataDefinition::create('string')->setLabel(t('Default value));
However, 'value' isn't the correct property.
The field is setup to be a select list of available options, and a textfield that takes a value.
In the schema() method, I have this:
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = [
'columns' => [
'format' => [
'type' => 'varchar',
'length' => 3,
],
'aph_number' => [
'type' => 'varchar',
'length' => 255,
],
],
];
return $schema;
Where as 'format' is a property of one of the fields (stored as 'field_name__format' in the database), and 'aph_number' (stored as field_name__aph_number' in the database).
My property definitions I am using are these:
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = [];
$properties['format'] = DataDefinition::create('string')
->setLabel(t('Format'));
$properties['aph_number'] = DataDefinition::create('string')
->setLabel(t('APH Number'));
return $properties;
}
Which, whe looking at the 'address' field is how you define properties for a field.
When I enable the module and add the newly created field to a piece of content, I get a Drupal error, and in watchdog, it gives me this:
InvalidArgumentException: Property value is unknown. in Drupal\Core\TypedData\TypedDataManager->getPropertyInstance()
If I change 'format' and 'aph_number' to 'value' in the $properties array, the error goes away, but I don't want the 'value' property to be available on this field, I want the ones I provided.
I have been unable to find any information online regarding this, and in looking at the two modules I am using as reference, this is correct.
Could somebody possibly help me with this?
mainPropertyName()
and returnNULL
(or one of your properties if that makes more sense)?