public function Webform::postSave in Webform 8.5
Same name and namespace in other branches
- 6.x src/Entity/Webform.php \Drupal\webform\Entity\Webform::postSave()
Acts on a saved entity before the insert or update hook is invoked.
Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.
Overrides ConfigEntityBundleBase::postSave
File
- src/
Entity/ Webform.php, line 2313
Class
- Webform
- Defines the webform entity.
Namespace
Drupal\webform\EntityCode
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// Because webform are not fieldable, when a webform is saved not all
// config/content entity related caches need to be cleared.
// parent::postSave($storage, $update);
/**************************************************************************/
$this
->invalidateTagsOnSave($update);
$entity_type_manager = $this
->entityTypeManager();
$bundle_of = $this
->getEntityType()
->getBundleOf();
if (!$update) {
\Drupal::service('entity_bundle.listener')
->onBundleCreate($this
->id(), $bundle_of);
}
else {
// Invalidate the render cache of entities for which this entity
// is a bundle.
if ($entity_type_manager
->hasHandler($bundle_of, 'view_builder')) {
$entity_type_manager
->getViewBuilder($bundle_of)
->resetCache();
}
// Webform does not not clear field definitions on every change.
// @see \Drupal\Core\Entity\EntityFieldManager::clearCachedFieldDefinitions
// Entity bundle field definitions may depend on bundle settings.
// \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$this
->entityTypeBundleInfo()
->clearCachedBundles();
}
/**************************************************************************/
// Update paths.
$this
->updatePaths();
// Invoke handler element CRUD methods.
// Note: Comparing parsed YAML since the actual YAML formatting could be
// different.
$elements_original = $this
->getElementsOriginalDecoded() ?: [];
$elements = $this
->getElementsDecoded() ?: [];
if ($elements_original !== $elements) {
$elements_original = WebformElementHelper::getFlattened($elements_original);
$elements = WebformElementHelper::getFlattened($elements);
// Handle create element.
$created_elements = array_diff_key($elements, $elements_original) ?: [];
foreach ($created_elements as $element_key => $element) {
$this
->invokeHandlers('createElement', $element_key, $element);
}
// Handle delete element.
$deleted_elements = array_diff_key($elements_original, $elements) ?: [];
foreach ($deleted_elements as $element_key => $element) {
$this
->invokeHandlers('deleteElement', $element_key, $element);
}
// Handle update element.
foreach ($elements as $element_key => $element) {
if (isset($elements_original[$element_key]) && $elements_original[$element_key] !== $element) {
$this
->invokeHandlers('updateElement', $element_key, $element, $elements_original[$element_key]);
}
}
// Invalidate library_info cache tag if any updated or deleted elements
// has assets (CSS or JavaScript).
// @see webform_library_info_build()
/** @var \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager */
$element_manager = \Drupal::service('plugin.manager.webform.element');
$checked_elements = $created_elements + $deleted_elements;
foreach ($checked_elements as $element_key => $element) {
$element_plugin = $element_manager
->getElementInstance($element, $this);
if ($element_plugin instanceof WebformElementAssetInterface && $element_plugin
->hasAssets()) {
Cache::invalidateTags([
'library_info',
]);
break;
}
}
}
// Reset elements.
$this
->resetElements();
$this->elementsOriginal = $this->elements;
// Reset settings.
$this->settingsOriginal = $this->settings;
// Clear updating flag.
$this
->setUpdating(FALSE);
}