Problem/Motivation
When using smart_date_recur sub-module, following logic within SmartDateWidgetBase is executed:
<?php
<?php
class SmartDateWidgetBase {
/**
* {@inheritdoc}
*/
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
// ...
if (!($entity instanceof EntityInterface)) {
$entity = $form_state->getformObject()->getEntity();
}
$entity_type = $entity->getEntityTypeId();
$bundle = $entity->bundle();
$field_name = $field_def->getName();
smart_date_recur_generate_rows($values, $entity_type, $bundle, $field_name, $month_limit);
}
return $values;
}
}
?>This part was once addressed by #3405129: Wrong parent entity if use recurring date inside inline form but only for Inline Entity Form. The same problem (fatal error) occurs when using Smart Date fields within Paragraphs.
Steps to reproduce
1. Create any node type using a Paragraphs reference
2. Create paragraph type using a Smart Date field with recurring feature. The node type should be allowed to reference to this paragraph type.
3. Create a node of the created type and add a date value with recurring enabled (e.g. daily until a specified date). Save the node via its form.
4. Configure the display of the paragraph type to render the date value using the recurring widget.
5. Open up the node page to render the node including the paragraph and see the fatal error occur.
Proposed resolution
Not sure why we need to get the entity object from the form. Instead we could just use the field definition's stored entity type and bundle?
<?php
<?php
class SmartDateWidgetBase {
/**
* {@inheritdoc}
*/
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
// ... no need to get the entity object at all.
$entity_type = $field_def->getEntityTypeId();
$bundle = $field_def->bundle();
$field_name = $field_def->getName();
smart_date_recur_generate_rows($values, $entity_type, $bundle, $field_name, $month_limit);
}
return $values;
}
}
?>Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3608985-wrong-entity-type-on-recurring.patch | 1.5 KB | mxh |
Issue fork smart_date-3608985
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mxh commentedAttached a patch reflecting the proposed solution from the IS. The patch was created using 4.2.x branch. Feel free to convert this into an MR.
Comment #3
mandclu commentedComment #6
mandclu commentedThanks for suggesting this improved approach. Merged in.