/** * Create an HTML element. * @param string $tag Tag. * @param string[] $attributes Attributes, see {@see Html::readAttributes}. * @return Html Html node. */ public function create($tag, $attributes = array()) { $html = new Html($tag); $html->attr($attributes); return $html; }
/** * Close this field. * @return Field|null This field or null if already closed. */ public function end() { if (!$this->open) { return null; } $this->open = false; $this->Form->end(); if ($this->prop('defaultContent') !== 'none') { $label = null; if ($this->hasProp('label')) { $label = $this['label']; if (is_array($label)) { $this->prepend($this->label(null, $label)); } else { if (!empty($label)) { $this->prepend($this->label($label)); } } } else { $this->prepend($this->label()); } if ($this->prop('input') !== '') { if ($this->hasProp('type')) { $type = $this['type']; $this->append($this->Form->{$type}($this->field, $this->prop('input'))); } else { $this->append($this->Form->input($this->field, $this->prop('input'))); } } $helpDiv = new Html('div'); $helpDiv->addClass('help'); if ($this->hasProp('help')) { $helpDiv->attr($this['help']); } if ($this->Form->isInvalid($this->field)) { $helpDiv->html($this->Form->error($this->field)); $this->append($helpDiv->toString()); } else { if ($this->hasProp('description')) { $helpDiv->html($this['description']); $this->append($helpDiv->toString()); } } } return $this; }