0 follower

Final Class Yiisoft\Form\Field\Part\Label

InheritanceYiisoft\Form\Field\Part\Label » Yiisoft\Widget\Widget
Uses TraitsYiisoft\Form\Field\Base\InputData\InputDataTrait

Represents label for a form field.

Method Details

Hide inherited methods

addAttributes() public method

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;
}

            
addClass() public method

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;
}

            
attributes() public method

public self attributes ( array $attributes )
$attributes array

                public function attributes(array $attributes): self
{
    $new = clone $this;
    $new->attributes = $attributes;
    return $new;
}

            
class() public method

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;
}

            
content() public method

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;
}

            
encode() public method

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;
}

            
forId() public method

public self forId ( string|null $id )
$id string|null

                public function forId(?string $id): self
{
    $new = clone $this;
    $new->forId = $id;
    return $new;
}

            
getInputData() protected method
protected Yiisoft\Form\Field\Base\InputData\InputDataInterface getInputData ( )

                final protected function getInputData(): InputDataInterface
{
    if ($this->inputData === null) {
        $this->inputData = new InputData();
    }
    return $this->inputData;
}

            
getThemeConfig() protected static method

protected static array getThemeConfig ( string|null $theme )
$theme string|null

                protected static function getThemeConfig(?string $theme): array
{
    return ThemeContainer::getTheme($theme)?->getLabelConfig() ?? [];
}

            
id() public method

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;
}

            
inputData() public method
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;
}

            
render() public method

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();
}

            
setFor() public method

public self setFor ( boolean $value )
$value boolean

                public function setFor(bool $value): self
{
    $new = clone $this;
    $new->setFor = $value;
    return $new;
}

            
useInputId() public method

public self useInputId ( boolean $value )
$value boolean

                public function useInputId(bool $value): self
{
    $new = clone $this;
    $new->useInputId = $value;
    return $new;
}