protected function createComponentListingForm() { $form = $this->listingFormFactory->create(); if ($this->listing !== null) { // Edit $form['month']->setItems([$this->listing->month => TimeUtils::getMonthName($this->listing->month)]); $form['year']->setItems([$this->listing->year => $this->listing->year]); $form['description']->setDefaultValue($this->listing->description); $form['hourlyWage']->setDefaultValue($this->listing->hourlyWage != 0 ? $this->listing->hourlyWage : null); $form['save']->caption = 'Uložit výčetku'; } else { // New Listing $currentDate = new \DateTime('now'); $year = $this->presenter->getParameter('year') != null ? $this->presenter->getParameter('year') : $currentDate->format('Y'); $month = $this->presenter->getParameter('month') != null ? $this->presenter->getParameter('month') : $currentDate->format('n'); try { $form['month']->setDefaultValue($month); $form['year']->setDefaultValue($year); } catch (InvalidArgumentException $e) { $form->addError('Lze vybírat pouze z hodnot, které jsou dostupné ve formuláři.'); } } $form->onSuccess[] = [$this, 'processForm']; return $form; }
protected function createComponentForm() { $comp = $this->listingFormFactory->create(); $monthNumber = $this->listing->getMonth(); $comp['month']->setItems([$monthNumber => TimeUtils::getMonthName($monthNumber)]); $comp['year']->setItems([$this->listing->getYear() => $this->listing->getYear()]); $comp['save']->caption = 'Vytvořit kopii'; $comp->onSuccess[] = [$this, 'processForm']; return $comp; }