Trait luya\admin\traits\LazyDataLoadTrait

Implemented byluya\admin\ngrest\plugins\CheckboxList, luya\admin\ngrest\plugins\SelectArray, luya\admin\ngrest\plugins\SelectArrayGently, luya\admin\ngrest\plugins\SortRelationArray
Available since version4.0.0

Trait to enable lazy load for NgRest plugins.

For a example for CheckboxList:

public function ngRestAttributeTypes()
{
    return [
        'genres' => ['checkboxList', 'data' => function () {
              return new Query()->all();
         }],
    ];
}

Protected Methods

Hide inherited methods

Method Description Defined By
lazyLoadData() If the given data is a closure it will call it and return the result of the function. luya\admin\traits\LazyDataLoadTrait

Method Details

Hide inherited methods

lazyLoadData() protected method

If the given data is a closure it will call it and return the result of the function.

Function will only execute if the data are really need to load.

If the given data is no closure it will return the directly data.

$this->lazyLoadData(function () {
     return Query::find()->all();
});
protected mixed|Traversable lazyLoadData ( $data )
$data mixed|Closure

                protected function lazyLoadData($data)
{
    if (is_callable($data)) {
        return call_user_func($data);
    }
    return $data;
}