index-main/kirby/src/Form/Mixin/Label.php

33 lines
642 B
PHP
Raw Normal View History

2025-10-03 07:46:23 +02:00
<?php
namespace Kirby\Form\Mixin;
use Kirby\Toolkit\Str;
/**
* @package Kirby Form
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier
* @license https://opensource.org/licenses/MIT
*/
trait Label
{
/**
* The field label can be set as string or associative array with translations
*/
protected string|null $label;
public function label(): string|null
{
return $this->stringTemplate(
$this->label ?? Str::ucfirst($this->name())
);
}
protected function setLabel(array|string|null $label = null): void
{
$this->label = $this->i18n($label);
}
}