You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB
PHP

<?php
namespace Artmark\Forms;
/**
* Description of Label
*
* @author Andrey Pokidov <pokidov@e-traffic.ru>
*/
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;
}
}