Smartdate does not work on Custom Entities generated by Drupal Console.
I added a custom field:
$fields['any_name'] = BaseFieldDefinition::create('smartdate')
->setLabel(t('Smart Date'))
->setRevisionable(TRUE)
->setDisplayOptions('view', [
'type' => 'smartdate_default',
'label' => 'above',
'weight' => 7,
])
->setDisplayOptions('form', array(
'type' => 'smartdate_default',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
During installation, I did not get any errors.
I opened add-form for my custom entity and got:
The website encountered an unexpected error. Please try again later.
And in the log messages I have this error:
Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::getThirdPartySetting() in Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formElement() (line 29 of ../web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php)
Am I missing some configurations in Display Options for view and form?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | smart_date-custom_entities-3114330-9.patch | 5.06 KB | dwkitchen |
| #6 | Screen Shot 2020-02-21 at 10.33.02.png | 49.6 KB | alvarito75 |
| #6 | Screen Shot 2020-02-21 at 10.24.42.png | 17.71 KB | alvarito75 |
Comments
Comment #2
alvarito75 commentedComment #3
mandclu commentedPlease try the attached patch. Note that if you want to use the recurring date functionality provided by smart_date_recur you need to explicitly declare that your field allows recurring dates, which you would do by adding
->setSetting('allow_recurring', TRUE)to your field definition code.Comment #4
alvarito75 commentedThanks mandclu.
I applied the patch and get this error:
I had to add the proper use statements though.
Comment #5
mandclu commentedThis patch adds use statements, and also sets defaults for the field widget's default_duration_increments and default_duration. If you are setting these and they're not getting passed through properly, it's possible they're returned by BaseFieldDefinition in a different structure than FieldConfigInterface, in which case it would be helpful if you could post a dump (var_dump or kint or similar) of the value you see from
$this->fieldDefinition->getDefaultValueLiteral()within SmartDateWidgetBase->formElement().Comment #6
alvarito75 commentedHi, Martin, I applied the patch and it did not work though.
This is the output I got:
And the output from
I attached two images.
And I also changed this:
to this, I removed the array value.
after doing this I could see the add-form for my entity, but it did not save the entity, so I got a different error:
FYI, I'm still using the same structure above.
And I created my custom entity with Drupal console and the entity has bundles.
Comment #7
mandclu commentedComment #8
dwkitchen commentedEDIT: Yes same issue can load the form but can't save the entity, patch on the way.
Here is my field definition in
baseFieldDefinitions()for my entityComment #9
dwkitchen commentedI don't really like that the FieldWidget is checking for the ThirdParty setting in the main definition.
I'm sure the Smart Date Recur module should be altering the Widget. However here is a widget that allows the recur setting in both the render and the save.
Comment #10
dwkitchen commentedComment #11
mandclu commentedI see what you mean, but as much as I could I wanted to keep the code to support recurring functionality self contained in its own submodule. The code in this latest patch looks good to me, but I don't have a custom entity handy to test this against.
If someone could either move this to RTBC or provide an entity definition I can use to test it, I would be happy to get this merged in.
Also, I greatly appreciate your fix here, but this is a good example of where including an interdiff would have been helpful.
Comment #12
mandclu commentedComment #13
niklanI can confirm that this error occurs on custom entities. Patch solve the problem.
Comment #15
mandclu commentedThanks everyone for helping to move this to completion. Merged in, should have a new release that includes this shortly.