0 follower

Class Yiisoft\FormModel\FieldFactory

InheritanceYiisoft\FormModel\FieldFactory

FieldFactory is a factory to ease creation of fields of various builtin types.

Protected Properties

Hide inherited properties

Property Type Description Defined By
$defaultTheme string|null Yiisoft\FormModel\FieldFactory

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\FormModel\FieldFactory
button() Create a button field. Yiisoft\FormModel\FieldFactory
buttonGroup() Create a button group field. Yiisoft\FormModel\FieldFactory
checkbox() Create a checkbox field. Yiisoft\FormModel\FieldFactory
checkboxList() Create checkboxes list field. Yiisoft\FormModel\FieldFactory
date() Create a date field. Yiisoft\FormModel\FieldFactory
dateTimeLocal() Create a local date and time field. Yiisoft\FormModel\FieldFactory
email() Create an email field. Yiisoft\FormModel\FieldFactory
error() Create an error for a field. Yiisoft\FormModel\FieldFactory
errorSummary() Create errors summary field. Yiisoft\FormModel\FieldFactory
fieldset() Create a fieldset. Yiisoft\FormModel\FieldFactory
file() Create a file upload field. Yiisoft\FormModel\FieldFactory
hidden() Create a hidden field. Yiisoft\FormModel\FieldFactory
hint() Create a field hint. Yiisoft\FormModel\FieldFactory
image() Create an image. Yiisoft\FormModel\FieldFactory
label() Create a field label. Yiisoft\FormModel\FieldFactory
number() Create a number field. Yiisoft\FormModel\FieldFactory
password() Create a password field. Yiisoft\FormModel\FieldFactory
radioList() Create a radio list field. Yiisoft\FormModel\FieldFactory
range() Create a range field. Yiisoft\FormModel\FieldFactory
resetButton() Create a reset button. Yiisoft\FormModel\FieldFactory
select() Create a select field. Yiisoft\FormModel\FieldFactory
submitButton() Create a submit button. Yiisoft\FormModel\FieldFactory
telephone() Create a phone number field. Yiisoft\FormModel\FieldFactory
text() Create a text field. Yiisoft\FormModel\FieldFactory
textarea() Create a text area field. Yiisoft\FormModel\FieldFactory
time() Create a time field. Yiisoft\FormModel\FieldFactory
url() Create a URL input field. Yiisoft\FormModel\FieldFactory

Property Details

Hide inherited properties

$defaultTheme protected property
protected string|null $defaultTheme null

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string|null $defaultTheme null )
$defaultTheme string|null

Default theme to use when it is not specified explicitly.

                final public function __construct(
    protected readonly ?string $defaultTheme = null,
) {
}

            
button() public method

Create a button field.

public \Yiisoft\Form\Field\Button button ( string|null $content null, array $config = [], string|null $theme null )
$content string|null

Button content.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function button(?string $content = null, array $config = [], ?string $theme = null): Button
{
    $field = Button::widget(config: $config, theme: $theme ?? $this->defaultTheme);
    if ($content !== null) {
        $field = $field->content($content);
    }
    return $field;
}

            
buttonGroup() public method

Create a button group field.

public \Yiisoft\Form\Field\ButtonGroup buttonGroup ( array $config = [], string|null $theme null )
$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function buttonGroup(array $config = [], ?string $theme = null): ButtonGroup
{
    return ButtonGroup::widget(config: $config, theme: $theme ?? $this->defaultTheme);
}

            
checkbox() public method

Create a checkbox field.

public \Yiisoft\Form\Field\Checkbox checkbox ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function checkbox(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Checkbox {
    return Checkbox::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
checkboxList() public method

Create checkboxes list field.

public \Yiisoft\Form\Field\CheckboxList checkboxList ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function checkboxList(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): CheckboxList {
    return CheckboxList::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
date() public method

Create a date field.

public \Yiisoft\Form\Field\Date date ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function date(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Date {
    return Date::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
dateTimeLocal() public method

Create a local date and time field.

public \Yiisoft\Form\Field\DateTimeLocal dateTimeLocal ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function dateTimeLocal(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): DateTimeLocal {
    return DateTimeLocal::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
email() public method

Create an email field.

public \Yiisoft\Form\Field\Email email ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function email(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Email {
    return Email::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
error() public method

Create an error for a field.

public \Yiisoft\Form\Field\Part\Error error ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to create error for.

$property string

Model property name to create error for.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function error(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Error {
    return Error::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
errorSummary() public method

Create errors summary field.

public \Yiisoft\Form\Field\ErrorSummary errorSummary ( Yiisoft\FormModel\FormModelInterface|null $formModel null, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface|null

Model to take errors from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function errorSummary(
    ?FormModelInterface $formModel = null,
    array $config = [],
    ?string $theme = null,
): ErrorSummary {
    $widget = ErrorSummary::widget(config: $config, theme: $theme ?? $this->defaultTheme);
    if ($formModel !== null) {
        $widget = $widget->errors(
            $formModel->isValidated()
                ? $formModel->getValidationResult()->getErrorMessagesIndexedByProperty()
                : []
        );
    }
    return $widget;
}

            
fieldset() public method

Create a fieldset.

public \Yiisoft\Form\Field\Fieldset fieldset ( array $config = [], string|null $theme null )
$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function fieldset(array $config = [], ?string $theme = null): Fieldset
{
    return Fieldset::widget(config: $config, theme: $theme ?? $this->defaultTheme);
}

            
file() public method

Create a file upload field.

public \Yiisoft\Form\Field\File file ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function file(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): File {
    return File::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
hidden() public method

Create a hidden field.

public \Yiisoft\Form\Field\Hidden hidden ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function hidden(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Hidden {
    return Hidden::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
hint() public method

Create a field hint.

public \Yiisoft\Form\Field\Part\Hint hint ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to create hint for.

$property string

Model property name to create hint for.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function hint(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Hint {
    return Hint::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
image() public method

Create an image.

public \Yiisoft\Form\Field\Image image ( string|null $url null, array $config = [], string|null $theme null )
$url string|null

"src" of the image.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function image(?string $url = null, array $config = [], ?string $theme = null): Image
{
    $field = Image::widget(config: $config, theme: $theme ?? $this->defaultTheme);
    if ($url !== null) {
        $field = $field->src($url);
    }
    return $field;
}

            
label() public method

Create a field label.

public \Yiisoft\Form\Field\Part\Label label ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to create label for.

$property string

Model property name to create label for.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function label(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Label {
    return Label::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
number() public method

Create a number field.

public \Yiisoft\Form\Field\Number number ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function number(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Number {
    return Number::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
password() public method

Create a password field.

public \Yiisoft\Form\Field\Password password ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function password(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Password {
    return Password::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
radioList() public method

Create a radio list field.

public \Yiisoft\Form\Field\RadioList radioList ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function radioList(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): RadioList {
    return RadioList::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
range() public method

Create a range field.

public \Yiisoft\Form\Field\Range range ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function range(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Range {
    return Range::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
resetButton() public method

Create a reset button.

public \Yiisoft\Form\Field\ResetButton resetButton ( string|null $content null, array $config = [], string|null $theme null )
$content string|null

Button content.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function resetButton(
    ?string $content = null,
    array $config = [],
    ?string $theme = null,
): ResetButton {
    $field = ResetButton::widget(config: $config, theme: $theme ?? $this->defaultTheme);
    if ($content !== null) {
        $field = $field->content($content);
    }
    return $field;
}

            
select() public method

Create a select field.

public \Yiisoft\Form\Field\Select select ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function select(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Select {
    return Select::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
submitButton() public method

Create a submit button.

public \Yiisoft\Form\Field\SubmitButton submitButton ( string|null $content null, array $config = [], string|null $theme null )
$content string|null

Button content.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function submitButton(
    ?string $content = null,
    array $config = [],
    ?string $theme = null,
): SubmitButton {
    $field = SubmitButton::widget(config: $config, theme: $theme ?? $this->defaultTheme);
    if ($content !== null) {
        $field = $field->content($content);
    }
    return $field;
}

            
telephone() public method

Create a phone number field.

public \Yiisoft\Form\Field\Telephone telephone ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function telephone(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Telephone {
    return Telephone::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
text() public method

Create a text field.

public \Yiisoft\Form\Field\Text text ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function text(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Text {
    return Text::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
textarea() public method

Create a text area field.

public \Yiisoft\Form\Field\Textarea textarea ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function textarea(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Textarea {
    return Textarea::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
time() public method

Create a time field.

public \Yiisoft\Form\Field\Time time ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function time(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Time {
    return Time::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
url() public method

Create a URL input field.

public \Yiisoft\Form\Field\Url url ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public function url(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Url {
    return Url::widget(config: $config, theme: $theme ?? $this->defaultTheme)
        ->inputData(new FormModelInputData($formModel, $property));
}