setName($name); } } /** * @return string */ public function getName() { return $this->name; } /** * @param string $name * * @return $this */ public function setName($name) { $this->name = strtolower(preg_replace('/([^a-zA-Z0-9_\-%])/', '', $name)); return $this; } /** * @return string */ public function getId() { return !$this->id ? ('element-' . $this->name) : $this->id; } /** * @param string $id * * @return $this */ public function setId($id) { $this->id = $id; return $this; } /** * @return string */ public function getLabel() { return $this->label; } /** * @param string $label * * @return $this */ public function setLabel($label) { $this->label = $label; return $this; } /** * @return string */ public function getClass() { return $this->class; } /** * @param string $class * * @return $this */ public function setClass($class) { $this->class = $class; return $this; } /** * @return string */ public function getContainerClass() { return $this->containerClass; } /** * @param string $class * * @return $this */ public function setContainerClass($class) { $this->containerClass = $class; return $this; } /** * @param Element $parent * * @return $this */ public function setParent(Element $parent) { $this->parent = $parent; return $this; } /** * @param string $viewFile * * @return string */ public function render($viewFile = null) { if (is_null($viewFile)) { $class = explode('\\', get_called_class()); $viewFile = end($class); } $view = new View('Form/' . $viewFile); $view->name = $this->getName(); $view->id = $this->getId(); $view->label = $this->getLabel(); $view->class = $this->getClass(); $view->containerClass = $this->getContainerClass(); $view->parent = $this->parent; $this->onPreRender($view); return $view->render(); } /** * @param View $view */ abstract protected function onPreRender(View &$view); }