Class luya\admin\ngrest\ConfigBuilder
Inheritance | luya\admin\ngrest\ConfigBuilder |
---|---|
Implements | luya\admin\ngrest\ConfigBuilderInterface |
Available since version | 1.0.0 |
Source Code | https://github.com/luyadev/luya-module-admin/blob/master/src/ngrest/ConfigBuilder.php |
Config Builder class to make the NgRest Configs
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$aw | luya\admin\ngrest\ConfigBuilder | Set the pointer to aw and return the ConfigBuilder for this pointer. | luya\admin\ngrest\ConfigBuilder |
$create | luya\admin\ngrest\ConfigBuilder | Set the pointer to create and return the ConfigBuilder for this pointer. | luya\admin\ngrest\ConfigBuilder |
$delete | boolean | Define whether the delete button is availabe or not | luya\admin\ngrest\ConfigBuilder |
$list | luya\admin\ngrest\ConfigBuilder | Set the pointer to list and return the ConfigBuilder for this pointer. | luya\admin\ngrest\ConfigBuilder |
$ngRestModelClass | string | When the ConfigBuilder is created, this property must be fulfilled by the constructor: | luya\admin\ngrest\ConfigBuilder |
$update | luya\admin\ngrest\ConfigBuilder | Set the pointer to update and return the ConfigBuilder for this pointer. | luya\admin\ngrest\ConfigBuilder |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
$config | luya\admin\ngrest\ConfigBuilder | ||
$field | luya\admin\ngrest\ConfigBuilder | ||
$pointer | luya\admin\ngrest\ConfigBuilder |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Assign a Plugin to a pointer['field']. Example of using plugin | luya\admin\ngrest\ConfigBuilder |
__construct() | luya\admin\ngrest\ConfigBuilder | |
__get() | Set the pointer of the current object (example $config->list) se pointer['key'] = $key. | luya\admin\ngrest\ConfigBuilder |
__set() | Maig setter function, defines whether a pointer exists or not, if not existing it will be created. | luya\admin\ngrest\ConfigBuilder |
addPlugin() | Add a Plugin to the current field pointer plugins array. | luya\admin\ngrest\ConfigBuilder |
copyFrom() | Copy from a pointer into another with optional removal of fields, the copie will applied to the current active pointer. | luya\admin\ngrest\ConfigBuilder |
extraField() | Define an extra field. | luya\admin\ngrest\ConfigBuilder |
field() | Define a field. | luya\admin\ngrest\ConfigBuilder |
getConfig() | luya\admin\ngrest\ConfigBuilder | |
load() | Creates a new active window object using the given configuration. | luya\admin\ngrest\ConfigBuilder |
prepandAdminPlugin() | Use the admin ngrest plugin base namespace as default | luya\admin\ngrest\ConfigBuilder |
Property Details
Set the pointer to aw and return the ConfigBuilder for this pointer.
Set the pointer to create and return the ConfigBuilder for this pointer.
Define whether the delete button is availabe or not
Set the pointer to list and return the ConfigBuilder for this pointer.
When the ConfigBuilder is created, this property must be fulfilled by the constructor:
Set the pointer to update and return the ConfigBuilder for this pointer.
Method Details
Assign a Plugin to a pointer['field']. Example of using plugin
->create->field('mytext')->textarea(['placeholer' => 'example']);
this will call
$this->addPlugin('textarea', ['placeholder' => 'example']);
public luya\admin\ngrest\ConfigBuilder __call ( $name, $args ) | ||
$name | string | |
$args | array | |
throws | luya\Exception |
---|
public function __call($name, $args)
{
$args = $args[0] ?? [];
if (!is_array($args)) {
throw new Exception("Ngrest plugin constructors must be provided as array config. Error in $name: $args");
}
return $this->addPlugin($this->prepandAdminPlugin($name), $args);
}
public void __construct ( $ngRestModelClass ) | ||
$ngRestModelClass |
public function __construct($ngRestModelClass)
{
$this->ngRestModelClass = $ngRestModelClass;
}
Set the pointer of the current object (example $config->list) se pointer['key'] = $key.
public luya\admin\ngrest\ConfigBuilder __get ( $key ) | ||
$key | string | |
throws | luya\Exception |
---|
public function __get($key)
{
if (!in_array($key, $this->_pointersMap)) {
throw new Exception("the requested pointer $key does not exists in the pointer map config");
}
if (!array_key_exists($key, $this->config)) {
$this->config[$key] = [];
}
$this->pointer = $key;
return $this;
}
Maig setter function, defines whether a pointer exists or not, if not existing it will be created.
public void __set ( $key, $value ) | ||
$key | string | |
$value | mixed |
public function __set($key, $value)
{
if (!array_key_exists($key, $this->config)) {
$this->config[$key] = $value;
}
}
Add a Plugin to the current field pointer plugins array.
public luya\admin\ngrest\ConfigBuilder addPlugin ( $name, array $args ) | ||
$name | string |
The name of the ngrest\plugin |
$args | array |
public function addPlugin($name, array $args)
{
$plugin = ['class' => $name, 'args' => $args];
$this->config[$this->pointer][$this->field]['type'] = $plugin;
return $this;
}
Copy from a pointer into another with optional removal of fields, the copie will applied to the current active pointer.
public void copyFrom ( $key, $removeFields = [] ) | ||
$key | string |
The pointer to copy from |
$removeFields | array |
public function copyFrom($key, $removeFields = [])
{
$temp = $this->config[$key];
foreach ($removeFields as $name) {
if (array_key_exists($name, $temp)) {
unset($temp[$name]);
}
}
$this->config[$this->pointer] = ArrayHelper::merge($this->config[$this->pointer], $temp);
}
Define an extra field.
public luya\admin\ngrest\ConfigBuilder extraField ( $name, $alias, $i18n = false ) | ||
$name | string | |
$alias | string | |
$i18n | boolean |
public function extraField($name, $alias, $i18n = false)
{
$this->config[$this->pointer][$name] = [
'name' => $name, 'i18n' => $i18n, 'alias' => (is_null($alias)) ? $name : $alias, 'type' => null, 'extraField' => true,
];
$this->field = $name;
return $this;
}
Define a field.
public luya\admin\ngrest\ConfigBuilder field ( $name, $alias = null, $i18n = false ) | ||
$name | string | |
$alias | string | |
$i18n | boolean |
public function field($name, $alias = null, $i18n = false)
{
$this->config[$this->pointer][$name] = [
'name' => $name,
'i18n' => $i18n,
'alias' => (is_null($alias)) ? $name : $alias,
'type' => null,
'extraField' => false,
];
$this->field = $name;
return $this;
}
Creates a new active window object using the given configuration.
Below are some usage examples:
// create an object using a class name
load('app\modules\foobar\test\MyActiveWindow');
// create an object using a configuration array
load([
'class' => 'app\modules\foobar\test\MyActiveWindow',
'property1' => 'value for property 1'
]);
public $this load ( $objectType ) | ||
$objectType | string|array |
The object type. This can be specified in one of the following forms:
|
throws | luya\Exception |
---|
public function load($objectType)
{
$config = [];
if ($this->pointer !== 'aw') {
throw new Exception('Register method can only be used in a pointer context.');
}
$object = Yii::createObject($objectType);
if (is_string($objectType)) {
$config['class'] = $objectType;
} else {
$config = $objectType;
}
$config['ngRestModelClass'] = $this->ngRestModelClass;
$this->config[$this->pointer][$object->getHashName()] = [
'objectConfig' => $config,
'label' => $object->getLabel(),
'icon' => $object->getIcon(),
];
return $this;
}
Use the admin ngrest plugin base namespace as default
public string prepandAdminPlugin ( $name ) | ||
$name | string |
public function prepandAdminPlugin($name)
{
return '\\luya\\admin\\ngrest\\plugins\\'.ucfirst($name);
}