*/ class Label extends AbstractVisibleHtml { /** * Поле, к которому привязана текстовая метка * @var AbstractField */ private $field = null; private $text = ''; public function __construct(AbstractField $field) { $this->field = $field; } /** * Текст метки поля * @return string */ public function text() { return $this->text; } /** * Устанавливает новый текст для метки поля * @param string $newText * @throws FieldException */ public function setText($newText) { if (!is_string($newText) && !is_numeric($newText)) { throw new FieldException('Incorrect field label text: `' . strval($newText) . '`'); } $this->text = Utils::cleanString($newText); } public function getAssociativeAttributes() { $attributes = parent::getAssociativeAttributes(); if ($this->field->hasId()) { $attributes['for'] = $this->field->idWithFormPrefix(); } else { $attributes['for'] = $this->field->nameWithFormPrefix(); } return $attributes; } }