for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\Form\Widget;
use InvalidArgumentException;
use Yiisoft\Form\Helper\HtmlForm;
use Yiisoft\Html\Tag\CustomTag;
/**
* The widget for hint form.
*
* @psalm-suppress MissingConstructor
*/
final class Hint extends AbstractWidget
{
private ?string $hint = '';
private string $tag = 'div';
* Set hint text.
* @param string|null $value
* @return static
public function hint(?string $value): self
$new = clone $this;
$new->hint = $value;
return $new;
}
* Set the container tag name for the hint.
* @param string $value Container tag name. Set to empty value to render error messages without container tag.
public function tag(string $value): self
$new->tag = $value;
* Generates a hint tag for the given form attribute.
* @return string the generated hint tag.
protected function run(): string
if ($new->tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
if ($new->hint === '') {
$new->hint = HtmlForm::getAttributeHint($new->getFormModel(), $new->getAttribute());
return (!empty($new->hint))
? CustomTag::name($new->tag)
->attributes($new->attributes)
->content($new->hint)
->encode($new->getEncode())
->render()
: '';