- Issue created by @hershy.k
- Status changed to Needs work
over 1 year ago 9:33pm 9 March 2023 - πΊπΈUnited States sker101 NYC
In my opinion, the code located at line 81 of docroot/modules/contrib/webform/src/Plugin/Field/FieldFormatter/WebformEntityReferenceFormatterBase.php is likely causing custom modules to encounter issues when attempting to save the webform entity.
if (isset($item->open) || isset($item->close) || isset($item->status)) { $entity->setOverride(); }
To elaborate, this code ensures that the render cache of the referenced entity can be cached by providing constant values for certain fields from the entity reference item. Additionally, setting the override to TRUE prevents the status of the main webform from being affected by the value of the entity reference item.
Therefore, for custom modules, resetting setOverride() to FALSE should be safe during a "hook_entity_node_presave" or "hook_entity_save" hook, provided they can handle the reversion of the status value appropriately.
- Status changed to Closed: won't fix
over 1 year ago 1:26pm 26 May 2023 - πΊπΈUnited States jrockowitz Brooklyn, NY
I am going to recommend you use \Drupal\webform\Entity\Webform::resetSettings to allow the webform to be saved programmatically.
/** * Implements hook_entity_presave(). */ function nyun_webform_node_presave(EntityInterface $node) { if ($node->bundle() === 'webform_sample') { $webform = $node->field_we->entity; $webform->set('title', 'Sample me!'); $webform->resetSettings(); $webform->save(); } }
- πΊπΈUnited States hershy.k
@jrockowitz - perhaps this should be documented somewhere in webform's cookbook for developers?
- πΊπΈUnited States jrockowitz Brooklyn, NY
@hershey.k It can be documented in the cookbook. The key thing to explain is you only need to call
$webform->resetSettings();
if you are getting the webform entity directly from a webform field. This feels like an edge case.