0 follower

Final Class Yiisoft\Yii\DataView\DetailView\DataField

InheritanceYiisoft\Yii\DataView\DetailView\DataField

DataField represents a field configuration for Yiisoft\Yii\DataView\DetailView\DetailView widget.

This class defines how a single field should be displayed in a Yiisoft\Yii\DataView\DetailView\DetailView

Property Details

Hide inherited properties

$fieldAttributes public property
$label public property
public string|null $label null
$labelAttributes public property
$labelEncode public property
public boolean $labelEncode true
$property public property
public string|null $property null
$value public property
public mixed $value null
$valueAttributes public property
$valueEncode public property
public boolean|null $valueEncode null
$visible public property
public boolean $visible true

Method Details

Hide inherited methods

__construct() public method

public __construct( string|null $property null, string|null $label null, boolean $labelEncode true, array|Closure $labelAttributes = [], mixed $value null, boolean|null $valueEncode null, array|Closure $valueAttributes = [], array|Closure $fieldAttributes = [], boolean $visible true ): mixed
$property string|null

Property name in the data object or key name in the data array. Optional if $value is set explicitly.

$label string|null

Field label. If not set, $property or empty string is used.

$labelEncode boolean

Whether the label is HTML encoded

$labelAttributes array|Closure

An array of label's HTML attribute values indexed by attribute names or a function accepting data and returning the array. *

$value mixed

The field value. It can be:

  • null if the value should be retrieved from the data object using the property name;
  • a closure that will be called to get the value, format: function (GetValueContext $context): mixed;
  • other value that will be used as is.
$valueEncode boolean|null

Whether the value is HTML encoded. Supported values:

  • null: stringable objects implementing \Yiisoft\Yii\DataView\DetailView\NoEncodeStringableInterface aren't encoded, everything else is encoded (default behavior);
  • true: any content is encoded, regardless of type;
  • false: nothing is encoded, use with caution and only for trusted content.
$valueAttributes array|Closure

An array of value's HTML attribute values indexed by attribute names or a function accepting data and returning the array.

$fieldAttributes array|Closure

An array of label's HTML attribute values indexed by attribute names or a function accepting data and returning the array.

$visible boolean

Whether the field is visible.

                public function __construct(
    public readonly ?string $property = null,
    public readonly ?string $label = null,
    public readonly bool $labelEncode = true,
    public readonly array|Closure $labelAttributes = [],
    public readonly mixed $value = null,
    public readonly ?bool $valueEncode = null,
    public readonly array|Closure $valueAttributes = [],
    public readonly array|Closure $fieldAttributes = [],
    public readonly bool $visible = true,
) {
    if ($property === null && $value === null) {
        throw new InvalidArgumentException('Either "property" or "value" must be set.');
    }
}