for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\Form\Field\Part;
use Stringable;
use Yiisoft\Form\Field\Base\FormAttributeTrait;
use Yiisoft\Html\Tag\Label as LabelTag;
use Yiisoft\Widget\Widget;
final class Label extends Widget
{
use FormAttributeTrait;
private bool $setForAttribute = true;
private ?string $forId = null;
private bool $useInputIdAttribute = true;
/**
* @var string|Stringable|null
*/
private $content = null;
private bool $encode = true;
public function setForAttribute(bool $value): self
$new = clone $this;
$new->setForAttribute = $value;
return $new;
}
* @return static
public function forId(?string $id): self
$new->forId = $id;
public function useInputIdAttribute(bool $value): self
$new->useInputIdAttribute = $value;
* @param string|Stringable|null $content
*
public function content($content): self
$new->content = $content;
* Whether content should be HTML-encoded.
* @param bool $value
public function encode(bool $value): self
$new->encode = $value;
protected function run(): string
$tag = LabelTag::tag()->content(
$this->content ?? $this->getAttributeLabel()
);
if ($this->setForAttribute) {
$id = $this->forId;
if ($id === null && $this->useInputIdAttribute) {
$id = $this->getInputId();
if ($id !== null) {
$tag = $tag->forId($id);
if (!$this->encode) {
$tag = $tag->encode(false);
return $tag->render();