Class luya\admin\ngrest\render\RenderCrud

Inheritanceluya\admin\ngrest\render\RenderCrud » luya\admin\ngrest\base\Render » yii\base\BaseObject
Implementsluya\admin\ngrest\render\RenderCrudInterface, luya\admin\ngrest\render\RenderInterface, yii\base\Configurable, yii\base\ViewContextInterface
Available since version1.0.0
Source Code https://github.com/luyadev/luya-module-admin/blob/master/src/ngrest/render/RenderCrud.php

Render the Crud view.

Public Properties

Hide inherited properties

Property Type Description Defined By
$activePoolConfig array luya\admin\ngrest\render\RenderCrud
$activeWindows array luya\admin\ngrest\render\RenderCrud
$apiEndpoint string luya\admin\ngrest\render\RenderCrud
$awFormView string The view file for active window form rendering. luya\admin\ngrest\render\RenderCrud
$buttons array An array with all buttons for this crud luya\admin\ngrest\render\RenderCrud
$config luya\admin\ngrest\ConfigInterface luya\admin\ngrest\base\Render
$crudFormView string The view file for create and update form rendering. luya\admin\ngrest\render\RenderCrud
$description string A description for the CRUD Title which is display below the title. luya\admin\ngrest\render\RenderCrud
$isInline boolean Determine whether this ngrest config is runing as inline window mode (a modal dialog with the crud inside) or not. luya\admin\ngrest\render\RenderCrud
$model luya\admin\ngrest\base\NgRestModelInterface luya\admin\ngrest\render\RenderCrud
$modelSelection string|boolean luya\admin\ngrest\render\RenderCrud
$orderBy string Angular order by statements like +id or -name. luya\admin\ngrest\render\RenderCrud
$primaryKey string luya\admin\ngrest\render\RenderCrud
$relationCall array luya\admin\ngrest\render\RenderCrud
$settingButtonDefinitions array luya\admin\ngrest\render\RenderCrud
$view luya\admin\ngrest\render\RenderCrudView luya\admin\ngrest\render\RenderCrud
$viewPath string The view path that may be prefixed to a relative view name. luya\admin\ngrest\render\RenderCrud

Public Methods

Hide inherited methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
apiQueryString() Generate the api query string for a certain context type luya\admin\ngrest\render\RenderCrud
canCreate() Whether create permission is granted. luya\admin\ngrest\render\RenderCrud
canDelete() Whether delete permission is granted. luya\admin\ngrest\render\RenderCrud
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
canUpdate() Whether update permission is granted. luya\admin\ngrest\render\RenderCrud
className() Returns the fully qualified name of this class. yii\base\BaseObject
forEachGroups() Generate an array with elements grouped by groups (...). luya\admin\ngrest\render\RenderCrud
generateDownloadAttributes() Generates an array with all attributes an the corresponding label. luya\admin\ngrest\render\RenderCrud
generatePluginHtml() Generate the HTML code for the plugin element based on the current context. luya\admin\ngrest\render\RenderCrud
getActivePoolConfig() Returns the pool config array for the current active pool if any. luya\admin\ngrest\render\RenderCrud
getActiveWindows() Short hand method to get all active windows (if available). luya\admin\ngrest\render\RenderCrud
getApiEndpoint() Returns the api endpoint, but can add appendix. luya\admin\ngrest\render\RenderCrud
getButtons() Collection all the buttons in the crud list. luya\admin\ngrest\render\RenderCrud
getColors() Returns an array with color properties of the ngRest field luya\admin\ngrest\render\RenderCrud
getCompositionKeysForButtonActions() luya\admin\ngrest\render\RenderCrud
getConfig() Get current config Context. luya\admin\ngrest\base\Render
getConfigButtonCondition() Get the ng-show condition for a update or delete buttons luya\admin\ngrest\render\RenderCrud
getFields() Short hand method to get all fields for a certain type context luya\admin\ngrest\render\RenderCrud
getIcon() Returns the icon name of the ngRest field luya\admin\ngrest\render\RenderCrud
getIsInline() Get whether the inline mode is enabled or not. luya\admin\ngrest\render\RenderCrud
getModel() luya\admin\ngrest\render\RenderCrud
getModelSelection() Model selection value from setter method. luya\admin\ngrest\render\RenderCrud
getOrderBy() Returns the current order by state. luya\admin\ngrest\render\RenderCrud
getPrimaryKey() Returns the primary key from the config. luya\admin\ngrest\render\RenderCrud
getRelationCall() Get an array with all relations luya\admin\ngrest\render\RenderCrud
getSettingButtonDefinitions() Get an array with additionals button definitions. luya\admin\ngrest\render\RenderCrud
getView() Returns the current view object. luya\admin\ngrest\render\RenderCrud
getViewPath() luya\admin\ngrest\render\RenderCrud
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
i18nNgModelString() Generate the ngrest model for an i18n field luya\admin\ngrest\render\RenderCrud
init() Initializes the object. yii\base\BaseObject
isHiddenInList() Indicates whether the field should be hidden from the list. luya\admin\ngrest\render\RenderCrud
isSortable() Indicates whether the current plugin config is sortable or not. luya\admin\ngrest\render\RenderCrud
listContextVariablize() Evaluates the condition from a list context. A condition like {field} == true would return item.field == true. luya\admin\ngrest\render\RenderCrud
ngModelString() Get the ngRestModel string for a certain attribute luya\admin\ngrest\render\RenderCrud
render() Renders the current ngrest renderer. luya\admin\ngrest\render\RenderCrud
renderElementPlugins() Render the input element luya\admin\ngrest\render\RenderCrud
setConfig() Set current config Context. luya\admin\ngrest\base\Render
setIsInline() Setter method for inline mode. luya\admin\ngrest\render\RenderCrud
setModel() Set the current ngrest model for the crud. luya\admin\ngrest\render\RenderCrud
setModelSelection() Model preselection value when using ngrest relation calls. luya\admin\ngrest\render\RenderCrud
setRelationCall() Set an array with relations. luya\admin\ngrest\render\RenderCrud
setSettingButtonDefinitions() Optional definitions for settings button. Those definitions are made in the ngrest crud controller. luya\admin\ngrest\render\RenderCrud
setView() Set crud render view object luya\admin\ngrest\render\RenderCrud

Protected Methods

Hide inherited methods

Method Description Defined By
can() Checks whether a given type can or can not. luya\admin\ngrest\render\RenderCrud

Constants

Hide inherited constants

Constant Value Description Defined By
TYPE_CREATE 'create' luya\admin\ngrest\render\RenderCrud
TYPE_LIST 'list' luya\admin\ngrest\render\RenderCrud
TYPE_UPDATE 'update' luya\admin\ngrest\render\RenderCrud

Property Details

Hide inherited properties

$activePoolConfig public read-only property (available since version 2.0.0)
$activeWindows public read-only property
$apiEndpoint public read-only property
public string getApiEndpoint ( $append null )
$awFormView public property (available since version 2.0.0)

The view file for active window form rendering. Aliases are supported. By default the location for this file is the viewPath {@see \luya\admin\ngrest\render\getViewPath()}

NOT RECOMMENDED to override {@see crudFormView}

public string $awFormView '_awform'
$buttons public read-only property

An array with all buttons for this crud

public array getButtons ( )
$crudFormView public property (available since version 2.0.0)

The view file for create and update form rendering. Aliases are supported. By default the location for this file is the viewPath {@see \luya\admin\ngrest\render\getViewPath()}

IMPORTANT NOTE. You can use this property to customize the form, but only if you know what you're doing. This approach is discouraged by LUYA maintainers. One of the strongest arguments for the LUYA admin is that you can run composer update, and you get fresh updates, improvements UI fixes, new button s, etc. - if you override the view files a next update can break the application, as there's no backward compatibility guarantee in view files and UI-controllers.

public string $crudFormView '_crudform'
$description public property (available since version 3.2.0)

A description for the CRUD Title which is display below the title.

public string $description null
$isInline public property

Determine whether this ngrest config is runing as inline window mode (a modal dialog with the crud inside) or not. When inline mode is enabled some features like ESC-Keys and URL chaning must be disabled.

public boolean getIsInline ( )
public void setIsInline ( $inline )
$model public property
$modelSelection public property
public string|boolean getModelSelection ( )
public void setModelSelection ( $selection )
$orderBy public read-only property

Angular order by statements like +id or -name.

public string getOrderBy ( )
$primaryKey public read-only property
$relationCall public property
public array getRelationCall ( )
public void setRelationCall ( array $options )
$settingButtonDefinitions public property
$view public property
$viewPath public read-only property

The view path that may be prefixed to a relative view name.

public string getViewPath ( )

Method Details

Hide inherited methods

__call() public method

Defined in: yii\base\BaseObject::__call()

Calls the named method which is not a class method.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

public mixed __call ( $name, $params )
$name string

The method name

$params array

Method parameters

return mixed

The method return value

throws yii\base\UnknownMethodException

when calling unknown method

                public function __call($name, $params)
{
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__construct() public method

Defined in: yii\base\BaseObject::__construct()

Constructor.

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call init().

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.
public void __construct ( $config = [] )
$config array

Name-value pairs that will be used to initialize the object properties

                public function __construct($config = [])
{
    if (!empty($config)) {
        Yii::configure($this, $config);
    }
    $this->init();
}

            
__get() public method

Defined in: yii\base\BaseObject::__get()

Returns the value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $object->property;.

See also __set().

public mixed __get ( $name )
$name string

The property name

return mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is write-only

                public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter();
    } elseif (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

            
__isset() public method

Defined in: yii\base\BaseObject::__isset()

Checks if a property is set, i.e. defined and not null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($object->property).

Note that if the property is not defined, false will be returned.

See also https://www.php.net/manual/en/function.isset.php.

public boolean __isset ( $name )
$name string

The property name or the event name

return boolean

Whether the named property is set (not null).

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    return false;
}

            
__set() public method

Defined in: yii\base\BaseObject::__set()

Sets value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $object->property = $value;.

See also __get().

public void __set ( $name, $value )
$name string

The property name or the event name

$value mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is read-only

                public function __set($name, $value)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter($value);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    } else {
        throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
    }
}

            
__unset() public method

Defined in: yii\base\BaseObject::__unset()

Sets an object property to null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($object->property).

Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.

See also https://www.php.net/manual/en/function.unset.php.

public void __unset ( $name )
$name string

The property name

throws yii\base\InvalidCallException

if the property is read only.

                public function __unset($name)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter(null);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
    }
}

            
apiQueryString() public method

Generate the api query string for a certain context type

public string apiQueryString ( $type )
$type string

                public function apiQueryString($type)
{
    // basic query
    $query = ['ngrestCallType' => $type];
    $fields = [];
    foreach ($this->model->primaryKey() as $n) {
        $fields[] = $n;
    }
    // see if we have fields for this type
    if (count($this->getFields($type)) > 0) {
        foreach ($this->getFields($type) as $field) {
            $fields[] = $field;
        }
    }
    // do we have extra fields to expand
    if ((is_countable($this->config->getPointerExtraFields($type)) ? count($this->config->getPointerExtraFields($type)) : 0) > 0) {
        $query['expand'] = implode(',', $this->config->getPointerExtraFields($type));
    }
    array_unique($fields);
    $query['fields'] = implode(",", $fields);
    if (Yii::$app->request->get('pool')) {
        $query['pool'] = Yii::$app->request->get('pool');
    }
    // return url decoded string from http_build_query
    return http_build_query($query, '', '&');
}

            
can() protected method

Checks whether a given type can or can not.

protected boolean can ( $type )
$type string

                protected function can($type)
{
    if (!array_key_exists($type, $this->_canTypes)) {
        $this->_canTypes[$type] = Yii::$app->auth->matchApi(Yii::$app->adminuser->getId(), $this->config->apiEndpoint, $type);
    }
    return $this->_canTypes[$type];
}

            
canCreate() public method

Whether create permission is granted.

public boolean canCreate ( )
return boolean

Whether current user can create items.

                public function canCreate()
{
    return $this->can(Auth::CAN_CREATE);
}

            
canDelete() public method

Whether delete permission is granted.

public boolean canDelete ( )
return boolean

Whether current user can update items.

                public function canDelete()
{
    return $this->can(Auth::CAN_DELETE);
}

            
canGetProperty() public method

Defined in: yii\base\BaseObject::canGetProperty()

Returns a value indicating whether a property can be read.

A property is readable if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also canSetProperty().

public boolean canGetProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be read

                public function canGetProperty($name, $checkVars = true)
{
    return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}

            
canSetProperty() public method

Defined in: yii\base\BaseObject::canSetProperty()

Returns a value indicating whether a property can be set.

A property is writable if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also canGetProperty().

public boolean canSetProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be written

                public function canSetProperty($name, $checkVars = true)
{
    return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}

            
canUpdate() public method

Whether update permission is granted.

public boolean canUpdate ( )
return boolean

Whether current user can update items.

                public function canUpdate()
{
    return $this->can(Auth::CAN_UPDATE);
}

            
className() public static method
Deprecated since 2.0.14. On PHP >=5.5, use ::class instead.

Defined in: yii\base\BaseObject::className()

Returns the fully qualified name of this class.

public static string className ( )
return string

The fully qualified name of this class.

                public static function className()
{
    return get_called_class();
}

            
forEachGroups() public method

Generate an array with elements grouped by groups (...).

public array forEachGroups ( $pointer )
$pointer string

                public function forEachGroups($pointer)
{
    $data = [];
    foreach ($this->evalGroupFields($this->config->getPointer($pointer)) as $group) {
        $data[] = [
            'fields' => $this->config->getFields($pointer, $group[0]),
            'name' => $group[1],
            'collapsed' => isset($group['collapsed']) ? (bool) $group['collapsed'] : false,
            'is_default' => isset($group['is_default']) ? (bool) $group['is_default'] : false,
        ];
    }
    return $data;
}

            
generateDownloadAttributes() public method (available since version 1.2.2)

Generates an array with all attributes an the corresponding label.

public array generateDownloadAttributes ( )

                public function generateDownloadAttributes()
{
    $exportAttributes = $this->model->ngRestExport();
    $fields = empty($exportAttributes) ? $this->model->attributes() : array_keys($exportAttributes);
    $attributes = [];
    foreach ($fields as $key) {
        $attributes[$key] = $this->model->getAttributeLabel($key);
    }
    asort($attributes);
    return $attributes;
}

            
generatePluginHtml() public method (available since version 2.0)

Generate the HTML code for the plugin element based on the current context.

public string generatePluginHtml ( array $element, $configContext )
$element array
$configContext string

                public function generatePluginHtml(array $element, $configContext)
{
    if ($element['i18n'] && $configContext !== self::TYPE_LIST) {
        return $this->view->render('_crudform_i18n_pluginhtml', [
            'element' => $element,
            'configContext' => $configContext,
            'languages' => Yii::$app->adminLanguage->languages,
            'helpButtonHtml' => $this->createFieldHelpButton($element, $configContext),
            'isRequired' => $this->getModel()->isAttributeRequired($element['name']),
        ]);
    }
    $ngModel = $this->ngModelString($configContext, $element['name']);
    return $this->createFieldHelpButton($element, $configContext) .
        $this->renderElementPlugins($configContext, $element['type'], Inflector::slug($ngModel), $element['name'], $ngModel, $element['alias'], false);
}

            
getActivePoolConfig() public method (available since version 2.0.0)

Returns the pool config array for the current active pool if any.

public array getActivePoolConfig ( )

                public function getActivePoolConfig()
{
    $pools = $this->getModel()->ngRestPools();
    $pool = Yii::$app->request->get('pool');
    return $pools[$pool] ?? [];
}

            
getActiveWindows() public method

Short hand method to get all active windows (if available).

public array getActiveWindows ( )

                public function getActiveWindows()
{
    return ($activeWindows = $this->config->getPointer('aw')) ? $activeWindows : [];
}

            
getApiEndpoint() public method

Returns the api endpoint, but can add appendix.

public string getApiEndpoint ( $append null )
$append

                public function getApiEndpoint($append = null)
{
    if ($append) {
        $append = '/' . ltrim($append, '/');
    }
    return 'admin/'.$this->getConfig()->getApiEndpoint() . $append;
}

            
getButtons() public method

Collection all the buttons in the crud list.

each items required the following keys (ngClick, icon, label):

return [
    ['ngClick' => 'toggle(...)', 'icon' => 'fa fa-fw fa-edit', 'label' => 'Button Label']
];
public array getButtons ( )
return array

An array with all buttons for this crud

throws yii\base\InvalidConfigException

                public function getButtons()
{
    // if already assigned return the resutl
    if ($this->_buttons) {
        return $this->_buttons;
    }
    $buttons = [];
    // ngrest relation buttons
    foreach ($this->getConfig()->getRelations() as $rel) {
        $api = Yii::$app->adminmenu->getApiDetail($rel['apiEndpoint']);
        if (!$api) {
            throw new InvalidConfigException("The configured api relation '{$rel['apiEndpoint']}' does not exists in the menu elements. Maybe you have no permissions to access this API.");
        }
        $label = empty($rel['tabLabelAttribute']) ? "'{$rel['label']}'" : 'item.'.$rel['tabLabelAttribute'];
        $buttons[] = [
            'ngShow' => 'true',
            'ngClick' => 'addAndswitchToTab(item.'.$this->getPrimaryKey().', \''.$api['route'].'\', \''.$rel['arrayIndex'].'\', '.$label.', \''.$rel['modelClass'].'\')',
            'icon' => 'chrome_reader_mode',
            'label' => $rel['label'],
        ];
    }
    // get all activeWindows assign to the crud
    foreach ($this->getActiveWindows() as $hash => $config) {
        if ((isset($config['objectConfig']['permissionLevel']) && $config['objectConfig']['permissionLevel'] == '') || $this->can($config['objectConfig']['permissionLevel'] ?? Auth::CAN_UPDATE)) {
            $buttons[] = [
                'ngShow' => $this->listContextVariablize($config['objectConfig']['condition'] ?? ''),
                'ngClick' => 'getActiveWindow(\''.$hash.'\', '.$this->getCompositionKeysForButtonActions('item').')',
                'icon' => $config['objectConfig']['icon'] ?? $config['icon'],
                'label' => $config['objectConfig']['label'] ?? $config['label'],
            ];
        }
    }
    // add active buttons.
    foreach ($this->config->getActiveButtons() as $btn) {
        if (($btn['permissionLevel'] == '') || ($btn['permissionLevel'] !== '' && $this->can($btn['permissionLevel']))) {
            $buttons[] = [
                'ngShow' => $this->listContextVariablize($btn['condition']),
                'ngClick' => "callActiveButton('{$btn['hash']}', ".$this->getCompositionKeysForButtonActions('item').", \$event)",
                'icon' => $btn['icon'],
                'label' => $btn['label'],
            ];
        }
    }
    // check if deletable is enabled
    if ($this->config->isDeletable() && $this->can(Auth::CAN_DELETE)) {
        $buttons[] = [
            'ngShow' => $this->listContextVariablize($this->getConfigButtonCondition('delete')),
            'ngClick' => 'deleteItem('.$this->getCompositionKeysForButtonActions('item').')',
            'icon' => 'delete',
            'label' => '',
        ];
    }
    // do we have an edit button
    if (count($this->getFields('update')) > 0 && $this->can(Auth::CAN_UPDATE)) {
        $buttons[] = [
            'ngShow' => $this->listContextVariablize($this->getConfigButtonCondition('update')),
            'ngClick' => 'toggleUpdate('.$this->getCompositionKeysForButtonActions('item').')',
            'icon' => 'mode_edit',
            'label' => '',
        ];
    }
    $this->_buttons = $buttons;
    return $buttons;
}

            
getColors() public method (available since version 4.1.0)

Returns an array with color properties of the ngRest field

cellColor - the color of the CRUD table cell highlightColor - the background color of the text or similar (will be implemented later) textColor - the color of the text or similar (will be implemented later)

public array getColors ( array $item )
$item array
return array

Returns an array with key cellColor.

                public function getColors(array $item)
{
    $config = Config::createField($item);
    $cellColor = $config->cellColor;
    if ($cellColor === '' or $cellColor === null) {
        $cellColor = false;
    }
    return [
        'cellColor' => $cellColor
    ];
}

            
getCompositionKeysForButtonActions() public method

public void getCompositionKeysForButtonActions ( $modelPrefix )
$modelPrefix string

In common case its item.

                public function getCompositionKeysForButtonActions($modelPrefix)
{
    $output = [];
    foreach ($this->config->getPrimaryKey() as $key) {
        $output[] = $modelPrefix . '.' . $key;
    }
    return "[". implode(",", $output) . "]";
}

            
getConfig() public method

Defined in: luya\admin\ngrest\base\Render::getConfig()

Get current config Context.

public luya\admin\ngrest\ConfigInterface getConfig ( )

                public function getConfig()
{
    return $this->_config;
}

            
getConfigButtonCondition() public method (available since version 4.0.0)

Get the ng-show condition for a update or delete buttons

Conditions needs to be defined in the model's ngRestScopes() along with fields definition indexed by buttonCondition and provided as a string or a [field=>value] array.

public function ngRestScopes()
{
    return [
      ['update', ['field1', 'field2', 'field3'], ['buttonCondition' => ['{created_by}' => Yii::$app->adminuser->id]] ],
      ['delete', true, ['buttonCondition' => ['{created_by}' => Yii::$app->adminuser->id]] ]
    ]
}

Conditions may be defined also in the model ngRestConfigOptions() along with other options Example :

public function ngRestConfigOptions()
{
    return [
        // ...
        'buttonsCondition' => [
            [ ['update', 'delete'], '{created_by}=='. \Yii::$app->adminuser->id  ],
        ],
    ];
}

This will add an ng-Show = "item.created_by==1" for instance if the logged user is the admin.

public string getConfigButtonCondition ( $scope )
$scope string

The scope aka button context like 'create' or 'update'

return string

Returns the condition with replaced field context like item.create_id== 1 or 'true'

throws yii\base\InvalidConfigException

                public function getConfigButtonCondition($scope)
{
    $buttonConditionConfigOption = $this->config->getOption('buttonCondition');
    // return empty string of no condition is defined
    if (empty($buttonConditionConfigOption)) {
        return '';
    }
    if (!is_array($buttonConditionConfigOption)) { // throw exception if configuration is wrong
        throw new InvalidConfigException(sprintf("Invalid buttonsCondition ngRestConfigOptions definition for '%s' scope.", $scope));
    }
    foreach ($buttonConditionConfigOption as $arrayConfig) {
        // take the first entry of the array config as the config scope
        // and check whether it applys to the given scppe
        $configScope = !is_array($arrayConfig[0]) ? [$arrayConfig[0]] : $arrayConfig[0];
        if (in_array($scope, $configScope)) {
            if (!isset($arrayConfig[1])) {
                throw new InvalidConfigException("Invalid buttonsCondition ngRestConfigOptions definition. buttonsCondition must be an array with two elements similar to ngRestScopes. Ex. `[ ['update', 'delete'], '{fieldname} == 1'´]`");
            }
            return $arrayConfig[1];
        }
    }
    return '';
}

            
getFields() public method

Short hand method to get all fields for a certain type context

public array getFields ( $type )
$type string

                public function getFields($type)
{
    if (!array_key_exists($type, $this->_fields)) {
        $fields = [];
        if ($this->config->hasPointer($type)) {
            foreach ($this->config->getPointer($type) as $item) {
                $fields[] = $item['name'];
            }
        }
        $this->_fields[$type] = $fields;
    }
    return $this->_fields[$type];
}

            
getIcon() public method (available since version 4.2.0)

Returns the icon name of the ngRest field

public mixed getIcon ( array $item )
$item array
return mixed

Returns the icon name based on https://material.io/icons or false if no icon is specified for this field.

                public function getIcon(array $item)
{
    $config = Config::createField($item);
    return empty($config->icon) ? false : $config->icon;
}

            
getIsInline() public method

Get whether the inline mode is enabled or not.

public boolean getIsInline ( )
return boolean

Determine whether this ngrest config is runing as inline window mode (a modal dialog with the crud inside) or not. When inline mode is enabled some features like ESC-Keys and URL chaning must be disabled.

                public function getIsInline()
{
    return $this->_isInline;
}

            
getModel() public method (available since version 1.2.2)

public luya\admin\ngrest\base\NgRestModelInterface getModel ( )
return luya\admin\ngrest\base\NgRestModelInterface

Returns the current ngrest model object.

                public function getModel()
{
    return $this->_model;
}

            
getModelSelection() public method

Model selection value from setter method.

public string|boolean getModelSelection ( )

                public function getModelSelection()
{
    return $this->_modelSelection;
}

            
getOrderBy() public method

Returns the current order by state.

public string getOrderBy ( )
return string

Angular order by statements like +id or -name.

                public function getOrderBy()
{
    if ($this->getConfig()->getDefaultOrderField() === false) {
        return false;
    }
    return $this->getConfig()->getDefaultOrderDirection() . $this->getConfig()->getDefaultOrderField();
}

            
getPrimaryKey() public method

Returns the primary key from the config.

public string getPrimaryKey ( )

                public function getPrimaryKey()
{
    return implode(",", $this->config->getPrimaryKey());
}

            
getRelationCall() public method

Get an array with all relations

public array getRelationCall ( )

                public function getRelationCall()
{
    return $this->_relationCall;
}

            
getSettingButtonDefinitions() public method

Get an array with additionals button definitions.

public array getSettingButtonDefinitions ( )

                public function getSettingButtonDefinitions()
{
    return $this->_settingButtonDefinitions;
}

            
getView() public method

Returns the current view object.

public luya\admin\ngrest\render\RenderCrudView getView ( )

                public function getView()
{
    if ($this->_view === null) {
        $this->_view = new RenderCrudView();
    }
    return $this->_view;
}

            
getViewPath() public method

public string getViewPath ( )
return string

The view path that may be prefixed to a relative view name.

                public function getViewPath()
{
    return '@admin/views/ngrest';
}

            
hasMethod() public method

Defined in: yii\base\BaseObject::hasMethod()

Returns a value indicating whether a method is defined.

The default implementation is a call to php function method_exists(). You may override this method when you implemented the php magic method __call().

public boolean hasMethod ( $name )
$name string

The method name

return boolean

Whether the method is defined

                public function hasMethod($name)
{
    return method_exists($this, $name);
}

            
hasProperty() public method

Defined in: yii\base\BaseObject::hasProperty()

Returns a value indicating whether a property is defined.

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also:

public boolean hasProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property is defined

                public function hasProperty($name, $checkVars = true)
{
    return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}

            
i18nNgModelString() public method

Generate the ngrest model for an i18n field

public string i18nNgModelString ( $configContext, $attribute, $lang )
$configContext string
$attribute string
$lang string

                public function i18nNgModelString($configContext, $attribute, $lang)
{
    $context = $configContext == self::TYPE_LIST ? "item." : "data.{$configContext}.";
    return $context . $attribute.'[\''.$lang.'\']';
}

            
init() public method

Defined in: yii\base\BaseObject::init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )

                public function init()
{
}

            
isHiddenInList() public method (available since version 2.0.0)

Indicates whether the field should be hidden from the list.

public boolean isHiddenInList ( array $item )
$item array

                public function isHiddenInList(array $item)
{
    $config = Config::createField($item);
    return $config->hideInList;
}

            
isSortable() public method (available since version 2.0.0)

Indicates whether the current plugin config is sortable or not.

public boolean isSortable ( array $item )
$item array

                public function isSortable(array $item)
{
    $config = Config::createField($item);
    return $config->getSortField() ? true : false;
}

            
listContextVariablize() public method

Evaluates the condition from a list context. A condition like {field} == true would return item.field == true.

public string listContextVariablize ( $condition )
$condition \luya\admin\ngrest\render\type
return string

List context based condition

                public function listContextVariablize($condition)
{
    if (empty($condition)) {
        return 'true';
    }
    // prepend context to $field if in format '{fieldname}'
    return Angular::variablizeContext(Plugin::LIST_CONTEXT_PREFIX, $condition, false);
}

            
ngModelString() public method

Get the ngRestModel string for a certain attribute

public string ngModelString ( $configContext, $attribute )
$configContext string
$attribute string

                public function ngModelString($configContext, $attribute)
{
    return $configContext == self::TYPE_LIST ? 'item.'.$attribute : 'data.'.$configContext.'.'.$attribute;
}

            
render() public method

Renders the current ngrest renderer.

public void render ( )

                public function render()
{
    return $this->view->render('crud', [
        'canCreate' => $this->can(Auth::CAN_CREATE),
        'canUpdate' => $this->can(Auth::CAN_UPDATE),
        'canDelete' => $this->can(Auth::CAN_DELETE),
        'config' => $this->config,
        'isInline' => $this->getIsInline(),
        'modelSelection' => $this->getModelSelection(),
        'hasActiveSelections' => count($this->config->getActiveSelections()),
        'relationCall' => $this->getRelationCall(), // this is currently only used for the crud relation view file, there for split the RenderCrud into two sepeare renderes.
        'currentMenu' => Yii::$app->adminmenu->getApiDetail($this->getConfig()->getApiEndpoint(), Yii::$app->request->get('pool')),
        'downloadAttributes' => $this->generateDownloadAttributes(),
    ], $this);
}

            
renderElementPlugins() public method

Render the input element

public string renderElementPlugins ( $configContext, $typeConfig, $uniqueId, $attribute, $ngRestModel, $label, $elmni18n )
$configContext string
$typeConfig array
$uniqueId string

Example unique field id: id="id-50eef582a7330e93b86b55ffed379965"

$attribute string
$ngRestModel string
$label string
$elmni18n boolean
return string

The rendered element

                public function renderElementPlugins($configContext, $typeConfig, $uniqueId, $attribute, $ngRestModel, $label, $elmni18n)
{
    $args = $typeConfig['args'];
    $args['renderContext'] = $this;
    $obj = NgRest::createPluginObject($typeConfig['class'], $attribute, $label, $elmni18n, $args);
    if ($obj->readonly && $configContext == self::TYPE_UPDATE) {
        $html = $obj->renderList($uniqueId, $ngRestModel);
    } else {
        $method = 'render'.ucfirst($configContext);
        $html = $obj->$method($uniqueId, $ngRestModel);
    }
    // parsed the element output content to a string
    $content = is_array($html) ? implode(" ", $html) : $html;
    // wrapp a new tag around fields which are required.
    if ($configContext !== self::TYPE_LIST) {
        $isRequired = $this->getModel()->isAttributeRequired($attribute);
        if ($isRequired) {
            $content = '<span class="bold-form-label">'.$content.'</span>';
        }
    }
    // if read only, wrap from group around read only value:
    if ($obj->readonly && $configContext == self::TYPE_UPDATE) {
        $content = '<div class="form-group form-side-by-side">
            <div class="form-side form-side-label">'.$label.'</div>
            <div class="form-side">'.$content.'</div>
        </div>';
    }
    return $content;
}

            
setConfig() public method

Defined in: luya\admin\ngrest\base\Render::setConfig()

Set current config Context.

public void setConfig ( luya\admin\ngrest\ConfigInterface $config )
$config luya\admin\ngrest\ConfigInterface

                public function setConfig(ConfigInterface $config)
{
    $this->_config = $config;
}

            
setIsInline() public method

Setter method for inline mode.

public void setIsInline ( $inline )
$inline boolean

                public function setIsInline($inline)
{
    $this->_isInline = $inline;
}

            
setModel() public method (available since version 1.2.2)

Set the current ngrest model for the crud.

public void setModel ( luya\admin\ngrest\base\NgRestModelInterface $model )
$model luya\admin\ngrest\base\NgRestModelInterface

                public function setModel(NgRestModelInterface $model)
{
    $this->_model = $model;
}

            
setModelSelection() public method

Model preselection value when using ngrest relation calls.

public void setModelSelection ( $selection )
$selection string

                public function setModelSelection($selection)
{
    $this->_modelSelection = $selection;
}

            
setRelationCall() public method

Set an array with relations.

public void setRelationCall ( array $options )
$options array

                public function setRelationCall(array $options)
{
    $this->_relationCall = $options;
}

            
setSettingButtonDefinitions() public method

Optional definitions for settings button. Those definitions are made in the ngrest crud controller.

public void setSettingButtonDefinitions ( array $buttons )
$buttons array

                public function setSettingButtonDefinitions(array $buttons)
{
    $elements = [];
    foreach ($buttons as $config) {
        $innerContent = '<i class="material-icons">' . ArrayHelper::getValue($config, 'icon', 'extension') .'</i><span> '. $config['label'] . '</span>';
        $tagName = ArrayHelper::remove($config, 'tag', 'a');
        if (!array_key_exists('class', $config)) {
            $config['class'] = 'dropdown-item';
        }
        $elements[] = Html::tag($tagName, $innerContent, $config);
    }
    $this->_settingButtonDefinitions= $elements;
}

            
setView() public method (available since version 2.0.0)

Set crud render view object

public void setView ( $value )
$value

                public function setView($value)
{
    $this->_view = Instance::ensure($value, '\yii\base\View');
}