<?php
namespace App\Mvc\View; trait FormTrait { protected $formClassName='View_Utils_FormAdmin'; protected $hasOptions = false; protected function render_getForm($formValues) { if (!$this->formClassName) { throw new \Exception('You did not set the `formClassName` class attribute for the class `'.get_called_class().'`.'); } $namespace = getClassNamespace(get_called_class()); $className = "\\{$namespace}\\{$this->formClassName}"; $formMngObj = new $className($this->controller); if ($formValues!==null) { $formMngObj->setValues($formValues); } if ($this->input['formSubmitButtonName']) { $formMngObj->setSubmitButtonName($this->input['formSubmitButtonName']); } $form = $formMngObj->getForm(); if ($formValues && $this->input['formSubmitButtonName'] && !($formValues[$this->input['formSubmitButtonName']]??null)) { $form->setFocus(true); } return $form; } protected function assignMessages(?\Engine\Form\General $form, \MessageStack $showMessage) { if ($this->messagesCollector) { if (!$form) { $showMessage->addFromMessageCollector($this->messagesCollector); return; } foreach ($this->messagesCollector->getMessages() as $msg) { $element = null; $container = null; if ($form && $msg->getField()) { list($element, $container) = $form->findFirstElementAndContainerByElementName($msg->getField()); if ($element && get_class($element)=='Engine\Form\Input\Hidden') { $element = null; $container = null; } } if ($element) { $element->addMessage($msg->getType(), $msg->getText()); if ($container) { do { if ($container->getCollapsible()) { $container->setCollapsed(false); } $container = $container->getParent(); } while($container); } } else { $text = $msg->getText(); if ($msg->getField()) { $text .= sprintf(' (%s)', $msg->getField()); } if ($form) { $form->getMessagesObj()->Set($msg->getType(), $text); } else { $showMessage->getMessagesObj()->Set($msg->getType(), $text); } } } } } public function getOptions(\App\Mvc\View\Utils\RowOptions\Container\Simple $options) { } public function hasOptions() { return $this->hasOptions; } } 