metadata = $metadata; $this->formulaManager = $formulaManager; $this->log = $log; } /** * @param array $options */ public function beforeSave(Entity $entity, array $options): void { if (!empty($options['skipFormula'])) { return; } $scriptList = $this->metadata->get(['formula', $entity->getEntityType(), 'beforeSaveScriptList'], []); $variables = (object) []; foreach ($scriptList as $script) { try { $this->formulaManager->run($script, $entity, $variables); } catch (Exception $e) { $this->log->error('Formula failed: ' . $e->getMessage()); } } $customScript = $this->metadata->get(['formula', $entity->getEntityType(), 'beforeSaveCustomScript']); if ($customScript) { try { $this->formulaManager->run($customScript, $entity, $variables); } catch (Exception $e) { $this->log->error('Formula failed: ' . $e->getMessage()); } } } }