authorize('catalog.manage'); if ($serviceUnit === null) { return; } $summary = $catalogQueries->findServiceUnit($serviceUnit); abort_if($summary === null, 404); $this->serviceUnitId = $summary->id; $this->form->name = $summary->name; $this->isShared = $summary->isShared; $this->usesStock = $summary->usesStock; } public function save(AddServiceUnit $addServiceUnit, RenameCatalogItem $renameItem, SetServiceUnitUsesStock $setUsesStock): void { $this->authorize('catalog.manage'); $name = $this->form->validatedName(); try { if ($this->serviceUnitId === null) { $id = $addServiceUnit->execute($name); $setUsesStock->execute($id, $this->usesStock); session()->flash('status', __('catalog.status.created', ['name' => trim($name)])); } else { $renameItem->execute(CatalogLevel::ServiceUnit, $this->serviceUnitId, $name); $setUsesStock->execute($this->serviceUnitId, $this->usesStock && ! $this->isShared); session()->flash('status', __('catalog.status.updated', ['name' => trim($name)])); } } catch (CatalogItemNotFound) { abort(404); } catch (DomainException $exception) { $this->form->showDomainError($exception); return; } $this->redirectRoute('catalog.index', navigate: true); } public function heading(): string { return __($this->serviceUnitId === null ? 'catalog.service_units.create_title' : 'catalog.service_units.edit_title'); } public function render(): mixed { return $this->view()->title($this->heading()); } }; ?>