Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, I've noticed a issue with Map field in ajax calls
Steps to reproduce:
1. Create a custom field type that have an Map property
2. Attach this field type on one entity
3. Attach also a file definition on this entity
4. Save a new entity with data inside the map field
5. Try to edit that entity and attach something on the file field, it will return this error
Comment | File | Size | Author |
---|---|---|---|
#2 | drupal_error-on-map-field-2874458-1-8.patch | 1 KB | guilopes |
Comments
Comment #2
guilopes CreditAttribution: guilopes at Media.Monks commentedComment #3
guilopes CreditAttribution: guilopes at Media.Monks commentedComment #4
BerdirDo you have a backtrace for that error?
Comment #5
guilopes CreditAttribution: guilopes at Media.Monks commentedyeah, this backtrace is on Drupal 8.2.8, but the same error should be on Drupal 8.4.x-dev because the validation still the same.
Comment #6
guilopes CreditAttribution: guilopes at Media.Monks commentedany update here?
Comment #7
guilopes CreditAttribution: guilopes at Media.Monks commentedIs someone responsible for this component? If so, What It is missing to be merged?
Comment #9
Joao Sausen CreditAttribution: Joao Sausen at Dexa commentedI have the same problem here, in my case I have created a FieldType with a dataDefinition of type Map, when creating that field in a node, or any other entity, the same error happened to me.
The patch on #2 works here.
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@guilopes and @Joao Sausen, how are you defining the map property in your custom field type?
If the answer is
DataDefinition::create('map')
, that's why you are getting this exception. Map properties have to be defined withMapDataDefinition::create()
.See
\Drupal\link\Plugin\Field\FieldType\LinkItem::propertyDefinitions()
for an example.Comment #12
kpv CreditAttribution: kpv at DrupalBASE commentedCan we get this point documented? Because it is really confusing that even though there is a
DataDefinition::create($type)
method it can't be used to create data of some Data Types,map
specifically. What should be documented is the reason WHY can't it be used, sinceDataDefinition::create($type)
can be mistakenly thought as a general purpose way to create data of ANY type.Also if it is not so, shouldn't it throw a warning then?
Comment #13
guilopes CreditAttribution: guilopes commentedif it's not suppose to create with DataDefinition::create('map') it should generate an exception at least, not create the field and not work properly. Is it make sense?
Comment #16
whiklojI am trying to create a single computed field and have hit this same error.
Error: Call to undefined method Drupal\\Core\\TypedData\\DataDefinition::getPropertyDefinitions() in /var/www/html/drupal/web/core/lib/Drupal/Core/Field/FieldItemBase.php on line 50
Seemingly because there is no getPropertyDefinitions() method defined in the DataDefinitionInterface.
I was trying to extend a simple URI as the FieldType, and in the propertyDefinitions set the class and computed
But it always explodes because the DataDefinition doesn't have that method.
Am I missing something obvious here?
Comment #20
AporieI stepped into the same issue, only in my case it's for a field type with an DataDefinition "entity reference".
Trying to bypass the issue using #10 comment leads me to another issue:
got suffixed by the create function with _reference, but this plugin doesn't exist:
\Drupal::typedDataManager()->createDataDefinition('entity:my_custom_entity')
--> returns a data definition.\Drupal::typedDataManager()->createDataDefinition('entity:my_custom_entity_reference')
--> returns "plugin not found".The workaround:
[EDIT]
Actually the proper way to do that is to directly extend Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem.
@see Drupal\file\Plugin\Field\FieldType\FileItem
Comment #23
webberly CreditAttribution: webberly commentedI get the same error in d9.2 when making a compound field extending the entityreference field.
One of them is for the contrib telephone field and the second is a list of options.
$properties['telephone'] = DataDefinition::create('field_item:telephone')
->setLabel(t('Telephone'))
->setRequired(TRUE);
$properties['status'] = DataDefinition::create('field_item:list_integer')
->setLabel(t('Status'))
->setSetting('allowed_values',['0'=> 'unverified', '1'=> 'verified'] )
->setRequired(TRUE);
Comment #24
BerdirThat's because you can't do that. You can't make another field type a property of yours, they are different things. What you can do is copy the property definitions of them into yours. But you'll also need to duplicate all the other related code, like checking for empty, widgets and formatters as you can't have multiple properties with the same name for obvious reasons.