Class luya\admin\ngrest\render\RenderCrud
Render the Crud view.
Public Properties
Public 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
Method | Description | Defined By |
---|---|---|
can() | Checks whether a given type can or can not. | luya\admin\ngrest\render\RenderCrud |
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
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
}
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.
A description for the CRUD Title which is display below the title.
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.
Angular order by statements like +id
or -name
.
public void setSettingButtonDefinitions ( array $buttons )
The view path that may be prefixed to a relative view name.
Method Details
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()");
}
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();
}
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);
}
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.
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;
}
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);
}
}
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.
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);
}
}
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, '', '&');
}
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];
}
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);
}
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);
}
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);
}
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);
}
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);
}
::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();
}
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;
}
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;
}
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);
}
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] ?? [];
}
Short hand method to get all active windows (if available).
public array getActiveWindows ( ) |
public function getActiveWindows()
{
return ($activeWindows = $this->config->getPointer('aw')) ? $activeWindows : [];
}
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;
}
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;
}
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 |
---|
public function getColors(array $item)
{
$config = Config::createField($item);
$cellColor = $config->cellColor;
if ($cellColor === '' or $cellColor === null) {
$cellColor = false;
}
return [
'cellColor' => $cellColor
];
}
public void getCompositionKeysForButtonActions ( $modelPrefix ) | ||
$modelPrefix | string |
In common case its |
public function getCompositionKeysForButtonActions($modelPrefix)
{
$output = [];
foreach ($this->config->getPrimaryKey() as $key) {
$output[] = $modelPrefix . '.' . $key;
}
return "[". implode(",", $output) . "]";
}
Defined in: luya\admin\ngrest\base\Render::getConfig()
Get current config Context.
public luya\admin\ngrest\ConfigInterface getConfig ( ) |
public function getConfig()
{
return $this->_config;
}
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 |
---|---|---|
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 '';
}
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];
}
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;
}
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;
}
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;
}
Model selection value from setter method.
public string|boolean getModelSelection ( ) |
public function getModelSelection()
{
return $this->_modelSelection;
}
Returns the current order by state.
public string getOrderBy ( ) | ||
return | string |
Angular order by statements like |
---|
public function getOrderBy()
{
if ($this->getConfig()->getDefaultOrderField() === false) {
return false;
}
return $this->getConfig()->getDefaultOrderDirection() . $this->getConfig()->getDefaultOrderField();
}
Returns the primary key from the config.
public string getPrimaryKey ( ) |
public function getPrimaryKey()
{
return implode(",", $this->config->getPrimaryKey());
}
Get an array with all relations
public array getRelationCall ( ) |
public function getRelationCall()
{
return $this->_relationCall;
}
Get an array with additionals button definitions.
public array getSettingButtonDefinitions ( ) |
public function getSettingButtonDefinitions()
{
return $this->_settingButtonDefinitions;
}
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;
}
public string getViewPath ( ) | ||
return | string |
The view path that may be prefixed to a relative view name. |
---|
public function getViewPath()
{
return '@admin/views/ngrest';
}
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);
}
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);
}
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.'\']';
}
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()
{
}
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;
}
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;
}
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);
}
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;
}
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);
}
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;
}
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;
}
Setter method for inline mode.
public void setIsInline ( $inline ) | ||
$inline | boolean |
public function setIsInline($inline)
{
$this->_isInline = $inline;
}
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;
}
Model preselection value when using ngrest relation calls.
public void setModelSelection ( $selection ) | ||
$selection | string |
public function setModelSelection($selection)
{
$this->_modelSelection = $selection;
}
Set an array with relations.
public void setRelationCall ( array $options ) | ||
$options | array |
public function setRelationCall(array $options)
{
$this->_relationCall = $options;
}
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;
}
Set crud render view object
public void setView ( $value ) | ||
$value |
public function setView($value)
{
$this->_view = Instance::ensure($value, '\yii\base\View');
}