Class luya\admin\ngrest\ConfigBuilder

Inheritanceluya\admin\ngrest\ConfigBuilder
Implementsluya\admin\ngrest\ConfigBuilderInterface
Available since version1.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

Hide inherited 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

Public Methods

Hide inherited 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

Hide inherited properties

$aw public property

Set the pointer to aw and return the ConfigBuilder for this pointer.

$config protected property
protected $config = []
$create public property

Set the pointer to create and return the ConfigBuilder for this pointer.

$delete public property

Define whether the delete button is availabe or not

public boolean $delete null
$field protected property
protected $field null
$list public property

Set the pointer to list and return the ConfigBuilder for this pointer.

$ngRestModelClass public property

When the ConfigBuilder is created, this property must be fulfilled by the constructor:

public string $ngRestModelClass null
$pointer protected property
protected $pointer null
$update public property

Set the pointer to update and return the ConfigBuilder for this pointer.

Method Details

Hide inherited methods

__call() public method

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);
}

            
__construct() public method

public void __construct ( $ngRestModelClass )
$ngRestModelClass

                public function __construct($ngRestModelClass)
{
    $this->ngRestModelClass = $ngRestModelClass;
}

            
__get() public method

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;
}

            
__set() public method

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;
    }
}

            
addPlugin() public method (available since version 1.0.0)

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;
}

            
copyFrom() public method

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);
}

            
extraField() public method

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;
}

            
field() public method

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;
}

            
getConfig() public method

public void getConfig ( )

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

            
load() public method (available since version 1.0.0)

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:

  • a string: representing the class name of the object to be created
  • a configuration array: the array must contain a class element which is treated as the object class, and the rest of the name-value pairs will be used to initialize the corresponding object properties
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;
}

            
prepandAdminPlugin() public method (available since version 1.0.0)

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);
}