0 follower

Final Class Yiisoft\Yii\DataView\GridView\Column\ActionButton

InheritanceYiisoft\Yii\DataView\GridView\Column\ActionButton

ActionButton represents a button in an action column of a grid.

// Simple button with static content and URL
$button = new ActionButton(
    content: '✎',
    url: '/edit',
    title: 'Edit',
);

// Button with dynamic URL based on row data
$button = new ActionButton(
    content: '❌',
    url: static function (array|object $data, DataContext $context): string {
        return '/delete/' . $data['id'];
    },
    title: 'Delete',
);

// Button with dynamic content and attributes
$button = new ActionButton(
    content: static function (array|object $data, DataContext $context): string {
        return $data['active'] ? 'Deactivate' : 'Activate';
    },
    url: '/toggle',
    attributes: ['data-confirm' => 'Are you sure?'],
    class: 'btn btn-sm',
);

// Button with dynamic CSS classes
$button = new ActionButton(
    content: '🔎',
    url: '/view',
    title: 'View',
    class: static function (array|object $data, DataContext $context): string {
        return $data['active'] ? 'btn-success' : 'btn-secondary';
    },
);

Property Details

Hide inherited properties

$attributes public property
public \Closure|array|null $attributes null
$class public property
public \Closure|string|array|false|null $class false
$content public property
public \Closure|string|\Stringable $content ''
$overrideAttributes public property
$title public property
public ?string $title null
$url public property
public \Closure|string|null $url null

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Closure|string|\Stringable $content '', Closure|string|null $url null, array|Closure|null $attributes null, array|Closure|false|string|null $class false, string|null $title null, boolean $overrideAttributes false )
$content Closure|string|\Stringable

Button content. To prevent HTML encoding use {@see \Yiisoft\Html\NoEncode::string()}. If closure is used, its signature is: function(array|object $data, DataContext $context): string|Stringable.

$url Closure|string|null

Button URL. If closure is used, its signature is: function(array|object $data, DataContext $context): string.

$attributes array|Closure|null

HTML attributes. If closure is used, its signature is: function(array|object $data, DataContext $context): array.

$class array|Closure|false|string|null

CSS class(es). If closure is used, its signature is: function(array|object $data, DataContext $context): string|array<string|null>|null.

$title string|null

Button title attribute.

$overrideAttributes boolean

Whether to override default attributes with custom ones instead of merging.

                public function __construct(
    public readonly Closure|string|Stringable $content = '',
    public readonly Closure|string|null $url = null,
    public readonly Closure|array|null $attributes = null,
    public readonly Closure|string|array|false|null $class = false,
    public readonly ?string $title = null,
    public readonly bool $overrideAttributes = false,
) {}