getComponents()) as $_component) { // redrawHandlery jsou umele vlozene, takze nechceme, aby ovlivnovali poradi if ($_component->getOption('redrawHandler') === true) { continue; } $lastComponent = $_component; break; } $insertAfter = $this->lastSection?->getOption('insertAfter') !== $lastComponent && ($lastComponent instanceof Container ? $lastComponent->getCurrentGroup() : $lastComponent->getOption('section')) === $this->getCurrentGroup() ? $lastComponent : $this->lastSection; if ($this->getCurrentGroup()) { $section = $this->getCurrentGroup()->addSection($this, $this->getForm()->ancestorGroups, $name); } else { $section = new Section($this, $this->getForm()->ancestorGroups, $name); $this->sections[] = $section; } if ($name) { if (!preg_match(self::NameRegexp, $name)) { throw new InvalidArgumentException("Component name must be non-empty alphanumeric string, '$name' given."); } if (isset($this->allSections[$name])) { throw new Exception("Section $name already exists."); } $this->allSections[$name] = $section; } $this->setCurrentGroup($section); $this->getForm()->ancestorGroups[] = $section; $section->setOption('insertAfter', $insertAfter); $section->setOption('blockName', $blockName?->getName()); $section->setWatchForRedraw($watchForRedraw); $section->setValidationScope($validationScope); $factory && $factory($section); $this->lastSection = $section; array_pop($this->getForm()->ancestorGroups); $this->setCurrentGroup($this->getForm()->ancestorGroups ? end($this->getForm()->ancestorGroups) : null); if ($section->getWatchForRedraw()) { $redrawHandlers = []; if ($section->getWatchForRedraw() instanceof SubmitterControl) { $_controlName = $section->getWatchForRedraw()->getName(); $this->redrawHandlers[$_controlName] = $section->getWatchForRedraw(); $redrawHandlers[] = $this->redrawHandlers[$_controlName]; } else { foreach ($section->getWatchForRedraw() as $_control) { $_controlName = $_control->getName(); if (!isset($this->redrawHandlers[$_controlName])) { $this->redrawHandlers[$_controlName] = $this->addSubmit('_redraw' . ucfirst($_controlName)); } if ($this->redrawHandlers[$_controlName]->getValidationScope() !== null) { $this->redrawHandlers[$_controlName]->setValidationScope(array_merge($this->redrawHandlers[$_controlName]->getValidationScope(), $section->getValidationScope())); } else { $this->redrawHandlers[$_controlName]->setValidationScope($section->getValidationScope()); } $this->redrawHandlers[$_controlName]->setOption('redrawHandler', true); $this->redrawHandlers[$_controlName]->onClick[] = function () use ($onRedraw, $section) { $onRedraw && $onRedraw(); $this->getForm()->getParent()->redrawControl($section->getHtmlId()); }; $_control->setHtmlAttribute('data-adt-redraw-snippet', $this->redrawHandlers[$_controlName]->getHtmlName()); $redrawHandlers[] = $this->redrawHandlers[$_controlName]; } } $section->setOption('redrawHandlers', $redrawHandlers); } return $section; } /** * @return Section[] */ public function getSections(): array { return $this->allSections; } }