0 follower

Final Class Yiisoft\Yii\DataView\GridView\Column\Base\GlobalContext

InheritanceYiisoft\Yii\DataView\GridView\Column\Base\GlobalContext

GlobalContext provides context for rendering and handling grid column headers, footers and container cells.

Public Methods

Hide inherited methods

Method Description Defined By
prepareSortable() Prepare a sortable header cell with appropriate styling and links. Yiisoft\Yii\DataView\GridView\Column\Base\GlobalContext
translate() Translate a message using the grid's translation category. Yiisoft\Yii\DataView\GridView\Column\Base\GlobalContext

Property Details

Hide inherited properties

$sortableLinkAscClass public property
$sortableLinkAttributes public property
$sortableLinkDescClass public property

Method Details

Hide inherited methods

prepareSortable() public method

Prepare a sortable header cell with appropriate styling and links.

public array prepareSortable ( Yiisoft\Yii\DataView\GridView\Column\Base\Cell $cell, string $property )
$cell Yiisoft\Yii\DataView\GridView\Column\Base\Cell

The header cell to prepare.

$property string

The property name for sorting.

return array

Array containing:

  • Modified cell
  • Sort link (or null)
  • Content to prepend
  • Content to append

                public function prepareSortable(Cell $cell, string $property): array
{
    if (
        !in_array($property, $this->allowedProperties, true)
        || $this->sort === null
        || $this->originalSort === null
        || !$this->sort->hasFieldInConfig($property)
    ) {
        return [$cell, null, '', ''];
    }
    $linkAttributes = $this->sortableLinkAttributes;
    $propertyOrder = $this->sort->getOrder()[$property] ?? null;
    if ($propertyOrder === null) {
        $cell = $cell->addClass($this->sortableHeaderClass);
        $prepend = $this->sortableHeaderPrepend;
        $append = $this->sortableHeaderAppend;
    } else {
        $cell = $cell->addClass(
            $propertyOrder === 'asc' ? $this->sortableHeaderAscClass : $this->sortableHeaderDescClass,
        );
        $prepend = $propertyOrder === 'asc' ? $this->sortableHeaderAscPrepend : $this->sortableHeaderDescPrepend;
        $append = $propertyOrder === 'asc' ? $this->sortableHeaderAscAppend : $this->sortableHeaderDescAppend;
        Html::addCssClass(
            $linkAttributes,
            $propertyOrder === 'asc' ? $this->sortableLinkAscClass : $this->sortableLinkDescClass,
        );
    }
    $url = $this->urlCreator === null ? '#' : call_user_func_array(
        $this->urlCreator,
        UrlParametersFactory::create(
            $this->pageToken,
            $this->pageSize,
            $this->getLinkSortValue($this->originalSort, $this->sort, $property),
            $this->urlConfig,
        ),
    );
    return [
        $cell,
        A::tag()->attributes($linkAttributes)->url($url),
        (string) $prepend,
        (string) $append,
    ];
}

            
translate() public method

Translate a message using the grid's translation category.

public string translate ( string|\Stringable $id )
$id string|\Stringable

Message ID to translate.

return string

Translated message.

                public function translate(string|Stringable $id): string
{
    return $this->translator->translate($id, category: $this->translationCategory);
}