Final Class Yiisoft\Form\Field\Part\Label
| Inheritance | Yiisoft\Form\Field\Part\Label » Yiisoft\Widget\Widget |
|---|---|
| Uses Traits | Yiisoft\Form\Field\Base\InputData\InputDataTrait |
Represents label for a form field.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| addAttributes() | Yiisoft\Form\Field\Part\Label | |
| addClass() | Add one or more CSS classes to the tag. | Yiisoft\Form\Field\Part\Label |
| attributes() | Yiisoft\Form\Field\Part\Label | |
| class() | Replace tag CSS classes with a new set of classes. | Yiisoft\Form\Field\Part\Label |
| content() | Yiisoft\Form\Field\Part\Label | |
| encode() | Whether content should be HTML-encoded. | Yiisoft\Form\Field\Part\Label |
| forId() | Yiisoft\Form\Field\Part\Label | |
| id() | Set tag ID. | Yiisoft\Form\Field\Part\Label |
| inputData() | Yiisoft\Form\Field\Base\InputData\InputDataTrait | |
| render() | Yiisoft\Form\Field\Part\Label | |
| setFor() | Yiisoft\Form\Field\Part\Label | |
| useInputId() | Yiisoft\Form\Field\Part\Label |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| getInputData() | Yiisoft\Form\Field\Base\InputData\InputDataTrait | |
| getThemeConfig() | Yiisoft\Form\Field\Part\Label |
Method Details
| public self addAttributes ( array $attributes ) | ||
| $attributes | array | |
public function addAttributes(array $attributes): self
{
$new = clone $this;
$new->attributes = array_merge($this->attributes, $attributes);
return $new;
}
Add one or more CSS classes to the tag.
| public self addClass ( string|null $class ) | ||
| $class | string|null |
One or many CSS classes. |
public function addClass(?string ...$class): self
{
$new = clone $this;
Html::addCssClass($new->attributes, $class);
return $new;
}
| public self attributes ( array $attributes ) | ||
| $attributes | array | |
public function attributes(array $attributes): self
{
$new = clone $this;
$new->attributes = $attributes;
return $new;
}
Replace tag CSS classes with a new set of classes.
| public self class ( string|null $class ) | ||
| $class | string|null |
One or many CSS classes. |
public function class(?string ...$class): self
{
$new = clone $this;
$new->attributes['class'] = array_filter($class, static fn ($c) => $c !== null);
return $new;
}
| public self content ( string|\Stringable|null $content ) | ||
| $content | string|\Stringable|null | |
public function content(string|Stringable|null $content): self
{
$new = clone $this;
$new->content = $content;
return $new;
}
Whether content should be HTML-encoded.
| public self encode ( boolean $value ) | ||
| $value | boolean | |
public function encode(bool $value): self
{
$new = clone $this;
$new->encode = $value;
return $new;
}
| public self forId ( string|null $id ) | ||
| $id | string|null | |
public function forId(?string $id): self
{
$new = clone $this;
$new->forId = $id;
return $new;
}
| protected Yiisoft\Form\Field\Base\InputData\InputDataInterface getInputData ( ) |
final protected function getInputData(): InputDataInterface
{
if ($this->inputData === null) {
$this->inputData = new InputData();
}
return $this->inputData;
}
| protected static array getThemeConfig ( string|null $theme ) | ||
| $theme | string|null | |
protected static function getThemeConfig(?string $theme): array
{
return ThemeContainer::getTheme($theme)?->getLabelConfig() ?? [];
}
Set tag ID.
| public self id ( string|null $id ) | ||
| $id | string|null |
Tag ID. |
public function id(?string $id): self
{
$new = clone $this;
$new->attributes['id'] = $id;
return $new;
}
| public Yiisoft\Form\Field\Part\Label inputData ( Yiisoft\Form\Field\Base\InputData\InputDataInterface $inputData ) | ||
| $inputData | Yiisoft\Form\Field\Base\InputData\InputDataInterface | |
final public function inputData(InputDataInterface $inputData): static
{
$new = clone $this;
$new->inputData = $inputData;
return $new;
}
| public string render ( ) |
public function render(): string
{
$content = $this->content ?? $this->getInputData()->getLabel();
if (empty($content)) {
return '';
}
$labelAttributes = $this->attributes;
if ($this->setFor && !isset($labelAttributes['for'])) {
$id = $this->forId;
if ($id === null && $this->useInputId) {
$id = $this->getInputData()->getId();
}
if ($id !== null) {
$labelAttributes['for'] = $id;
}
}
$tag = Html::label($content)->addAttributes($labelAttributes);
if (!$this->encode) {
$tag = $tag->encode(false);
}
return $tag->render();
}
| public self setFor ( boolean $value ) | ||
| $value | boolean | |
public function setFor(bool $value): self
{
$new = clone $this;
$new->setFor = $value;
return $new;
}
| public self useInputId ( boolean $value ) | ||
| $value | boolean | |
public function useInputId(bool $value): self
{
$new = clone $this;
$new->useInputId = $value;
return $new;
}
Signup or Login in order to comment.