Abstract Class luya\cms\base\PhpBlock

Inheritanceluya\cms\base\PhpBlock » luya\cms\base\InternalBaseBlock » yii\base\BaseObject
ImplementsArrayAccess, luya\admin\base\TypesInterface, luya\cms\base\BlockInterface, luya\cms\base\PhpBlockInterface, yii\base\Configurable, yii\base\ViewContextInterface
Subclassesluya\cms\frontend\blocks\HtmlBlock, luya\cms\frontend\blocks\MirrorLanguageBlock, luya\cms\frontend\blocks\ModuleBlock
Available since version1.0.0
Source Code https://github.com/luyadev/luya-module-cms/blob/master/src/base/PhpBlock.php

Represents a CMS block with PHP views.

Public Properties

Hide inherited properties

Property Type Description Defined By
$cacheEnabled boolean Enable or disable the block caching luya\cms\base\InternalBaseBlock
$cacheExpiration integer The cache lifetime for this block in seconds (3600 = 1 hour), only affects when cacheEnabled is true. luya\cms\base\InternalBaseBlock
$cacheExpirationTime integer luya\cms\base\InternalBaseBlock
$cfgValues array luya\cms\base\InternalBaseBlock
$configCfgsExport array luya\cms\base\InternalBaseBlock
$configPlaceholdersByRowsExport array Returns an array where each element is a row containing informations about the placeholders. luya\cms\base\InternalBaseBlock
$configPlaceholdersExport array luya\cms\base\InternalBaseBlock
$configVarsExport array luya\cms\base\InternalBaseBlock
$envOptions array Returns an array with key value parings. luya\cms\base\InternalBaseBlock
$extraVarValues array luya\cms\base\InternalBaseBlock
$fieldHelp array An array where the key is the cfg/var field var name and the value the helper text. luya\cms\base\InternalBaseBlock
$isCacheEnabled boolean luya\cms\base\InternalBaseBlock
$isContainer boolean Choose whether block is a layout/container/segmnet/section block or not, Container elements will be optically displayed in a different way for a better user experience. luya\cms\base\InternalBaseBlock
$isDirtyDialogEnabled boolean luya\cms\base\InternalBaseBlock
$module string Containing the name of the environment (used to find the view files to render). luya\cms\base\InternalBaseBlock
$placeholderValues luya\cms\base\InternalBaseBlock
$varValues array luya\cms\base\InternalBaseBlock
$view luya\cms\base\PhpBlockView View Object. luya\cms\base\PhpBlock
$viewPath string The view path that may be prefixed to a relative view name. luya\cms\base\PhpBlock

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
addCfg() Add a cfg variable to the config. luya\cms\base\InternalBaseBlock
addExtraVar() Add an extra var entry. luya\cms\base\InternalBaseBlock
addVar() Add a var variable to the config. luya\cms\base\InternalBaseBlock
admin() luya\cms\base\PhpBlockInterface
blockGroup() Contains the class name for the block group class luya\cms\base\InternalBaseBlock
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
className() Returns the fully qualified name of this class. yii\base\BaseObject
config() Returns the configuration array. luya\cms\base\InternalBaseBlock
createAjaxLink() Return link for usage in ajax request, the link will call the defined callback inside this block. All callback methods must start with callback. An example for a callback method:. luya\cms\base\InternalBaseBlock
extraVars() Define additional variables. luya\cms\base\InternalBaseBlock
frontend() luya\cms\base\PhpBlock
getCacheExpirationTime() The time of cache expiration luya\cms\base\InternalBaseBlock
getCfgValue() Get cfg value. luya\cms\base\InternalBaseBlock
getCfgValues() luya\cms\base\InternalBaseBlock
getConfigCfgsExport() Returns all config cfgs element of key value pairing to pass to the Admin ANGULAR API luya\cms\base\InternalBaseBlock
getConfigPlaceholdersByRowsExport() Returns the placeholder based rows. luya\cms\base\InternalBaseBlock
getConfigPlaceholdersExport() Returns all config placeholders element of key value pairing to pass to the Admin ANGULAR API luya\cms\base\InternalBaseBlock
getConfigVarsExport() Returns all config vars element of key value pairing to pass to the Admin ANGULAR API luya\cms\base\InternalBaseBlock
getEnvOption() Get a env option by $key. If $key does not exist it will return given $default or false. luya\cms\base\InternalBaseBlock
getEnvOptions() Returns all environment/context informations where the block have been placed. luya\cms\base\InternalBaseBlock
getExtraValue() luya\cms\base\InternalBaseBlock
getExtraVarValues() Returns an array of key value pairing with additional informations to pass to the API and frontend. luya\cms\base\InternalBaseBlock
getFieldHelp() Returns an array with additional help informations for specific field (var or cfg). luya\cms\base\InternalBaseBlock
getIsCacheEnabled() Whether cache is enabled for this block or not. luya\cms\base\InternalBaseBlock
getIsContainer() Whether this is a container element or not. Container elements usually have defined placeholders. luya\cms\base\InternalBaseBlock
getIsDirtyDialogEnabled() Whether the dirty marker dialog is enable or not. luya\cms\base\InternalBaseBlock
getPlaceholderValue() luya\cms\base\InternalBaseBlock
getPlaceholderValues() luya\cms\base\InternalBaseBlock
getVarValue() Get var value. luya\cms\base\InternalBaseBlock
getVarValues() luya\cms\base\InternalBaseBlock
getView() View Object getter. luya\cms\base\PhpBlock
getViewFileName() Returns the name of the php file to be rendered. luya\cms\base\InternalBaseBlock
getViewPath() Get relative view path ofr rendering view files. luya\cms\base\PhpBlock
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
icon() Contains the icon luya\cms\base\InternalBaseBlock
init() Initializes the object. yii\base\BaseObject
injectors() Injectors are like huge helper objects which are going to automate functions, configs and variable assignement. luya\cms\base\InternalBaseBlock
isAdminContext() Returns true if block is active in backend. luya\cms\base\InternalBaseBlock
isFrontendContext() Returns true if block is active in frontend. luya\cms\base\InternalBaseBlock
name() Get the name of the block in order to display in administration context. luya\cms\base\BlockInterface
offsetExists() luya\cms\base\InternalBaseBlock
offsetGet() Array Access Get luya\cms\base\InternalBaseBlock
offsetSet() luya\cms\base\InternalBaseBlock
offsetUnset() luya\cms\base\InternalBaseBlock
onRegister() Save the registered assets form block to the cache. luya\cms\base\PhpBlock
onRegisterFromCache() Load the block assets from cache and register to the app view. luya\cms\base\PhpBlock
placeholderRenderIteration() This method is called whenever a block inside a placeholder is rendered. luya\cms\base\InternalBaseBlock
renderAdmin() Get the output in administration context. luya\cms\base\PhpBlock
renderAdminPreview() Create a html img tag and use the preview image at {module}/resources/img/{block-name}.jpg as source. luya\cms\base\InternalBaseBlock
renderFrontend() Get the output in the frontend context. luya\cms\base\PhpBlock
setCfgValues() Set the values for element cfgs with an array key value binding. luya\cms\base\InternalBaseBlock
setEnvOption() Sets a key => value pair in env options. luya\cms\base\InternalBaseBlock
setPlaceholderValues() Set the value from placeholders where the array key is the name of value the content of the placeholder. luya\cms\base\InternalBaseBlock
setVarValues() Set the values for element vars with an array key value binding. luya\cms\base\InternalBaseBlock
setup() This method is run when the block object is initialized in frontend context. luya\cms\base\InternalBaseBlock
variations() Configure Variations. luya\cms\base\InternalBaseBlock

Protected Methods

Hide inherited methods

Method Description Defined By
ensureModule() Make sure the module contains its alias prefix @ luya\cms\base\InternalBaseBlock
getPreviewImageSource() Path to the preview image. luya\cms\base\InternalBaseBlock
injectorSetup() Setup injectors. luya\cms\base\InternalBaseBlock

Constants

Hide inherited constants

Constant Value Description Defined By
INJECTOR_CFG 'cfg' luya\cms\base\InternalBaseBlock
INJECTOR_VAR 'var' luya\cms\base\InternalBaseBlock

Property Details

Hide inherited properties

$view public property

View Object.

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

            
addCfg() public method

Defined in: luya\cms\base\InternalBaseBlock::addCfg()

Add a cfg variable to the config.

public void addCfg ( array $cfgConfig, $append false )
$cfgConfig array
$append

                public function addCfg(array $cfgConfig, $append = false)
{
    $count = count($this->_cfgs);
    $iteration = $append ? $count + 1000 : $count;
    $this->_cfgs[$iteration] = (new BlockCfg($cfgConfig))->toArray();
}

            
addExtraVar() public method

Defined in: luya\cms\base\InternalBaseBlock::addExtraVar()

Add an extra var entry.

If the extra var is defined in extraVars() the key will be overriden.

public void addExtraVar ( $key, $value )
$key string
$value mixed

                public function addExtraVar($key, $value)
{
    $this->_extraVars[$key] = $value;
}

            
addVar() public method

Defined in: luya\cms\base\InternalBaseBlock::addVar()

Add a var variable to the config.

public void addVar ( array $varConfig, $append false )
$varConfig array
$append

                public function addVar(array $varConfig, $append = false)
{
    $count = count($this->_vars);
    $iteration = $append ? $count + 1000 : $count;
    $this->_vars[$iteration] = (new BlockVar($varConfig))->toArray();
}

            
admin() public abstract method
public abstract void admin ( )

                public function admin();

            
blockGroup() public method (available since version 1.0.0)

Defined in: luya\cms\base\InternalBaseBlock::blockGroup()

Contains the class name for the block group class

public string blockGroup ( )
return string

The classname on which the block should be stored in.

                public function blockGroup()
{
    return MainGroup::class;
}

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

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

            
config() public abstract method

Defined in: luya\cms\base\InternalBaseBlock::config()

Returns the configuration array.

An array with either var, cfg or placeholder. An example with vars with a required text input:

return [
    'vars' => [
        [
            'var' => 'userInputText',
            'label' => 'Description of userInputText',
            'type' => self::TYPE_TEXT,
            'required' => true,
        ]
    ]
];
public abstract array config ( )

                abstract public function config();

            
createAjaxLink() public method

Defined in: luya\cms\base\InternalBaseBlock::createAjaxLink()

Return link for usage in ajax request, the link will call the defined callback inside this block. All callback methods must start with callback. An example for a callback method:.

public function callbackTestAjax($arg1)
{
    return 'hello callback test ajax with argument: arg1 ' . $arg1;
}

The above defined callback link can be created with the follow code:

$this->createAjaxLink('TestAjax', ['arg1' => 'My Value for Arg1']);

The most convient way to assign the variable is via extraVars

public function extraVars()
{
    return [
        'ajaxLinkToTestAjax' => $this->createAjaxLink('TestAjax', ['arg1' => 'Value for Arg1']),
    ];
}
public string createAjaxLink ( $callbackName, array $params = [] )
$callbackName string

The callback name in uppercamelcase to call. The method must exists in the block class.

$params array

A list of parameters who have to match the argument list in the method.

ensureModule() protected method

Defined in: luya\cms\base\InternalBaseBlock::ensureModule()

Make sure the module contains its alias prefix @

protected string ensureModule ( )
return string

The module name with alias prefix @.

                protected function ensureModule()
{
    $moduleName = $this->module;
    if (substr($moduleName, 0, 1) !== '@') {
        $moduleName = '@'.$moduleName;
    }
    return $moduleName;
}

            
extraVars() public method

Defined in: luya\cms\base\InternalBaseBlock::extraVars()

Define additional variables.

public array extraVars ( )

                public function extraVars()
{
    return [];
}

            
frontend() public method

public void frontend ( )

                public function frontend()
{
    return $this->view->render($this->getViewFileName('php'), [], $this);
}

            
getCacheExpirationTime() public method

Defined in: luya\cms\base\InternalBaseBlock::getCacheExpirationTime()

The time of cache expiration

public integer getCacheExpirationTime ( )

                public function getCacheExpirationTime()
{
    return $this->cacheExpiration;
}

            
getCfgValue() public method

Defined in: luya\cms\base\InternalBaseBlock::getCfgValue()

Get cfg value.

If the key does not exist in the array, is an empty string or null the default value will be returned.

public mixed getCfgValue ( $key, $default false )
$key string

The name of the key you want to retrieve

$default mixed

A default value that will be returned if the key isn't found or empty.

                public function getCfgValue($key, $default = false)
{
    return (isset($this->_cfgValues[$key]) && $this->_cfgValues[$key] != '') ? $this->_cfgValues[$key] : $default;
}

            
getCfgValues() public method
public array getCfgValues ( )

                public function getCfgValues()
{
    return $this->_cfgValues;
}

            
getConfigCfgsExport() public method

Defined in: luya\cms\base\InternalBaseBlock::getConfigCfgsExport()

Returns all config cfgs element of key value pairing to pass to the Admin ANGULAR API

public array getConfigCfgsExport ( )

                public function getConfigCfgsExport()
{
    $config = $this->config();
    if (isset($config['cfgs'])) {
        foreach ($config['cfgs'] as $item) {
            $iteration = count($this->_cfgs) + 500;
            $this->_cfgs[$iteration] = (new BlockCfg($item))->toArray();
        }
    }
    ksort($this->_cfgs);
    return array_values($this->_cfgs);
}

            
getConfigPlaceholdersByRowsExport() public method

Defined in: luya\cms\base\InternalBaseBlock::getConfigPlaceholdersByRowsExport()

Returns the placeholder based rows.

This is used to render the grid system in the admin ui.

The array which is returned contains rows which contains cols.

return [
    [], // row 1
    [], // row 2
];

each row can contain columns

return [
    [ // row 1
        ['var' => 'left', 'col' => 6],
        ['var' => 'right', 'col' => 6]
    ],
    [ // row 2
        ['var' => 'bottom', 'col' => 12]
    ],
];
public array getConfigPlaceholdersByRowsExport ( )
return array

Returns an array where each element is a row containing informations about the placeholders.

                public function getConfigPlaceholdersByRowsExport()
{
    $array = array_key_exists('placeholders', $this->config()) ? $this->config()['placeholders'] : [];
    $rows = [];
    foreach ($array as $holder) {
        if (isset($holder['var'])) {
            $holder['cols'] = 12;
            $rows[] = [$holder];
        } else {
            $rows[] = $holder;
        }
    }
    return $rows;
}

            
getConfigPlaceholdersExport() public method

Defined in: luya\cms\base\InternalBaseBlock::getConfigPlaceholdersExport()

Returns all config placeholders element of key value pairing to pass to the Admin ANGULAR API

public array getConfigPlaceholdersExport ( )

                public function getConfigPlaceholdersExport()
{
    $array = array_key_exists('placeholders', $this->config()) ? $this->config()['placeholders'] : [];
    $holders = [];
    foreach ($array as $holder) {
        if (isset($holder['var'])) {
            $holders[] = $holder;
        } else {
            foreach ($holder as $columnHolder) {
                $holders[] = $columnHolder;
            }
        }
    }
    return $holders;
}

            
getConfigVarsExport() public method

Defined in: luya\cms\base\InternalBaseBlock::getConfigVarsExport()

Returns all config vars element of key value pairing to pass to the Admin ANGULAR API

public array getConfigVarsExport ( )

                public function getConfigVarsExport()
{
    $config = $this->config();
    if (isset($config['vars'])) {
        foreach ($config['vars'] as $item) {
            $iteration = count($this->_vars) + 500;
            $this->_vars[$iteration] = (new BlockVar($item))->toArray();
        }
    }
    ksort($this->_vars);
    return array_values($this->_vars);
}

            
getEnvOption() public method

Defined in: luya\cms\base\InternalBaseBlock::getEnvOption()

Get a env option by $key. If $key does not exist it will return given $default or false.

public mixed getEnvOption ( $key, $default false )
$key
$default mixed

                public function getEnvOption($key, $default = false)
{
    return (array_key_exists($key, $this->_envOptions)) ? $this->_envOptions[$key] : $default;
}

            
getEnvOptions() public method

Defined in: luya\cms\base\InternalBaseBlock::getEnvOptions()

Returns all environment/context informations where the block have been placed.

public array getEnvOptions ( )
return array

Returns an array with key value parings.

                public function getEnvOptions()
{
    return $this->_envOptions;
}

            
getExtraValue() public method
public string|mixed getExtraValue ( $key, $default false )
$key string
$default string

                public function getExtraValue($key, $default = false)
{
    if (!$this->_assignExtraVars) {
        $this->getExtraVarValues();
        $this->_assignExtraVars = true;
    }
    return $this->_extraVars[$key] ?? $default;
}

            
getExtraVarValues() public method

Defined in: luya\cms\base\InternalBaseBlock::getExtraVarValues()

Returns an array of key value pairing with additional informations to pass to the API and frontend.

public array getExtraVarValues ( )

                public function getExtraVarValues()
{
    $this->_extraVars = ArrayHelper::merge($this->extraVars(), $this->_extraVars);
    return $this->_extraVars;
}

            
getFieldHelp() public method

Defined in: luya\cms\base\InternalBaseBlock::getFieldHelp()

Returns an array with additional help informations for specific field (var or cfg).

public array getFieldHelp ( )
return array

An array where the key is the cfg/var field var name and the value the helper text.

                public function getFieldHelp()
{
    return [];
}

            
getIsCacheEnabled() public method

Defined in: luya\cms\base\InternalBaseBlock::getIsCacheEnabled()

Whether cache is enabled for this block or not.

public boolean getIsCacheEnabled ( )

                public function getIsCacheEnabled()
{
    return $this->cacheEnabled;
}

            
getIsContainer() public method

Defined in: luya\cms\base\InternalBaseBlock::getIsContainer()

Whether this is a container element or not. Container elements usually have defined placeholders.

public boolean getIsContainer ( )

                public function getIsContainer()
{
    return $this->isContainer;
}

            
getIsDirtyDialogEnabled() public method

Defined in: luya\cms\base\InternalBaseBlock::getIsDirtyDialogEnabled()

Whether the dirty marker dialog is enable or not.

This can be usefull when working with blocks which does not require any input data, so therefore it does not require a dirty marked dialog.

public boolean getIsDirtyDialogEnabled ( )

                public function getIsDirtyDialogEnabled()
{
    return true;
}

            
getPlaceholderValue() public method
public boolean getPlaceholderValue ( $placholder )
$placholder \luya\cms\base\unknown

                public function getPlaceholderValue($placholder)
{
    return $this->getPlaceholderValues()[$placholder] ?? false;
}

            
getPlaceholderValues() public method
public void getPlaceholderValues ( )

                public function getPlaceholderValues()
{
    return $this->_placeholderValues;
}

            
getPreviewImageSource() protected method (available since version 1.0.8)

Defined in: luya\cms\base\InternalBaseBlock::getPreviewImageSource()

Path to the preview image.

protected void getPreviewImageSource ( )

                protected function getPreviewImageSource()
{
    $imageName = $this->getViewFileName('jpg');
    $reflector = new \ReflectionClass($this);
    $dirPath = dirname($reflector->getFileName(), 2);
    $imagePath = $dirPath . '/images/blocks/' . $imageName;
    // file get content resolved Yii aliases.
    $data = FileHelper::getFileContent($imagePath);
    if ($data) {
        return 'data:image/jpg;base64,' . base64_encode($data);
    }
    return false;
}

            
getVarValue() public method

Defined in: luya\cms\base\InternalBaseBlock::getVarValue()

Get var value.

If the key does not exist in the array, is an empty string or null the default value will be returned.

public mixed getVarValue ( $key, $default false )
$key string

The name of the key you want to retrieve

$default mixed

A default value that will be returned if the key isn't found or empty.

                public function getVarValue($key, $default = false)
{
    return (isset($this->_varValues[$key]) && $this->_varValues[$key] != '') ? $this->_varValues[$key] : $default;
}

            
getVarValues() public method
public array getVarValues ( )

                public function getVarValues()
{
    return $this->_varValues;
}

            
getView() public method

View Object getter.

public luya\cms\base\PhpBlockView getView ( )

                public function getView()
{
    if ($this->_view === null) {
        $this->_view = Yii::createObject(PhpBlockView::class);
    }
    return $this->_view;
}

            
getViewFileName() public method

Defined in: luya\cms\base\InternalBaseBlock::getViewFileName()

Returns the name of the php file to be rendered.

public string getViewFileName ( $extension )
$extension
return string

The name of the php file (example.php)

                public function getViewFileName($extension)
{
    $className = get_class($this);
    if (preg_match('/\\\\([\w]+)$/', $className, $matches)) {
        $className = $matches[1];
    }
    return $className.'.'.$extension;
}

            
getViewPath() public method

Get relative view path ofr rendering view files.

See also yii\base\ViewContextInterface.

public string getViewPath ( )
return string

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

                public function getViewPath()
{
    if (empty($this->module)) {
        $class = new ReflectionClass($this);
        return dirname($class->getFileName()) . DIRECTORY_SEPARATOR . 'views';
    }
    return $this->ensureModule() . '/views/blocks';
}

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

            
icon() public method

Defined in: luya\cms\base\InternalBaseBlock::icon()

Contains the icon

public void icon ( )

                public function icon()
{
    return;
}

            
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()
{
}

            
injectorSetup() protected method
protected void injectorSetup ( )

                protected function injectorSetup()
{
    if ($this->_injectorObjects === null) {
        foreach ($this->injectors() as $varName => $injector) {
            $injector->setContext($this);
            $injector->varName = $varName;
            $injector->setup();
            $this->_injectorObjects[$injector->varName] = $injector;
        }
    }
}

            
injectors() public method

Defined in: luya\cms\base\InternalBaseBlock::injectors()

Injectors are like huge helper objects which are going to automate functions, configs and variable assignement.

An example of an Injector which builds a select dropdown and assigns the active query data into the extra vars foobar.

public function injectors()
{
    return [
        'foobar' => new cms\injector\ActiveQueryCheckboxInjector([
            'query' => MyModel::find()->where(['id' => 1]),
            'type' => self::INJECTOR_VAR, // could be self::INJECTOR_CFG,
            'varLabel' => 'The Field Label',
        ]);
    ];
}

Now the generated injector ActiveQueryCheckbox is going to grab all informations from the defined query and assign them into the extra var foobar. Now you can access $this->extraValue('foobar') which returns all seleced rows from the checkbox you have assigend.

In order to access the injectors object api you can use the ArrayAccess getter method like $this['foobar'] and you can access the public method for this Injector.

public void injectors ( )

                public function injectors()
{
    return [];
}

            
isAdminContext() public method

Defined in: luya\cms\base\InternalBaseBlock::isAdminContext()

Returns true if block is active in backend.

public boolean isAdminContext ( )

                public function isAdminContext()
{
    return ($this->getEnvOption('context', false) === 'admin') ? true : false;
}

            
isFrontendContext() public method

Defined in: luya\cms\base\InternalBaseBlock::isFrontendContext()

Returns true if block is active in frontend.

public boolean isFrontendContext ( )

                public function isFrontendContext()
{
    return ($this->getEnvOption('context', false) === 'frontend') ? true : false;
}

            
name() public abstract method

Defined in: luya\cms\base\BlockInterface::name()

Get the name of the block in order to display in administration context.

public abstract void name ( )

                public function name();

            
offsetExists() public method
public void offsetExists ( $offset )
$offset

                #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
    return isset($this->_injectorObjects[$offset]);
}

            
offsetGet() public method

Defined in: luya\cms\base\InternalBaseBlock::offsetGet()

Array Access Get

public luya\cms\base\BaseBlockInjector offsetGet ( $offset )
$offset string

The name of the registered Injector name.

                #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
    return $this->_injectorObjects[$offset] ?? null;
}

            
offsetSet() public method
public void offsetSet ( $offset, $value )
$offset
$value

                #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
    $this->_injectorObjects[$offset] = $value;
}

            
offsetUnset() public method
public void offsetUnset ( $offset )
$offset

                #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
    unset($this->_injectorObjects[$offset]);
}

            
onRegister() public method (available since version 1.0.5)

Save the registered assets form block to the cache.

public void onRegister ( )

                public function onRegister()
{
    if ($this->isCachingEnabled()) {
        $phpBlockView = $this->getView();
        $blockId = $this->getEnvOption('id');
        $cacheKeyAssets = ['blockassets', $blockId];
        $cacheKeyAssetBundles = ['blockassetbundles', $blockId];
        $assets = Yii::$app->cache->getOrSet($cacheKeyAssets, [$phpBlockView, 'getBlockAssets'], $this->getCacheExpirationTime());
        $assetBundles = Yii::$app->cache->getOrSet($cacheKeyAssetBundles, [$phpBlockView, 'getAssetBundleNames'], $this->getCacheExpirationTime());
        /**
         * @todo i think this is not need because in PhpBlockView::init() the EVENT_AFTER_RENDER is listen also.
         */
        PhpBlockView::registerToAppView($assets, $assetBundles);
    }
}

            
onRegisterFromCache() public method (available since version 1.0.5)

Load the block assets from cache and register to the app view.

public void onRegisterFromCache ( )

                public function onRegisterFromCache()
{
    if ($this->isCachingEnabled()) {
        $blockId = $this->getEnvOption('id');
        $cacheKeyAssets = ['blockassets', $blockId];
        $cacheKeyAssetBundles = ['blockassetbundles', $blockId];
        $assets = Yii::$app->cache->get($cacheKeyAssets) ?: [];
        $assetBundles = Yii::$app->cache->get($cacheKeyAssetBundles) ?: [];
        PhpBlockView::registerToAppView($assets, $assetBundles);
    }
}

            
placeholderRenderIteration() public method (available since version 1.0.9)

Defined in: luya\cms\base\InternalBaseBlock::placeholderRenderIteration()

This method is called whenever a block inside a placeholder is rendered.

This allows you to change the render behavior of every block inside a placeholder. An example of adding a wrapper div to the iteration:

public function placeholderRenderIteration(BlockInterface $block)
{
     return '<div class="block-wrapper">'.$block->renderFrontend().'</div>';
}

This also allows you to determined whether the block should be rendered or not as the response is the content of the block inside the placholder.

public string placeholderRenderIteration ( luya\cms\base\BlockInterface $block )
$block luya\cms\base\BlockInterface

                public function placeholderRenderIteration(BlockInterface $block)
{
    return $block->renderFrontend();
}

            
renderAdmin() public method

Get the output in administration context.

public string renderAdmin ( )

                public function renderAdmin()
{
    $this->injectorSetup();
    return $this->admin();
}

            
renderAdminPreview() public method (available since version 1.0.8)

Defined in: luya\cms\base\InternalBaseBlock::renderAdminPreview()

Create a html img tag and use the preview image at {module}/resources/img/{block-name}.jpg as source.

If no image source exists, it will return false.

public string|boolean renderAdminPreview ( )
return string|boolean

False if no preview available, otherwise the html img as string.

                public function renderAdminPreview()
{
    $image = $this->getPreviewImageSource();
    if ($image) {
        return Html::img($image);
    }
    return false;
}

            
renderFrontend() public method

Get the output in the frontend context.

public string renderFrontend ( )

                public function renderFrontend()
{
    $this->injectorSetup();
    return $this->frontend();
}

            
setCfgValues() public method

Defined in: luya\cms\base\InternalBaseBlock::setCfgValues()

Set the values for element cfgs with an array key value binding.

public void setCfgValues ( array $values )
$values array

An array where key is the name of the cfg-element and value the content.

                public function setCfgValues(array $values)
{
    foreach ($values as $key => $value) {
        $this->_cfgValues[$key] = $value;
    }
}

            
setEnvOption() public method

Defined in: luya\cms\base\InternalBaseBlock::setEnvOption()

Sets a key => value pair in env options.

public void setEnvOption ( $key, $value )
$key string

The string to be set as key

$value mixed

The value that will be stored associated with the given key

                public function setEnvOption($key, $value)
{
    $this->_envOptions[$key] = $value;
}

            
setPlaceholderValues() public method

Defined in: luya\cms\base\InternalBaseBlock::setPlaceholderValues()

Set the value from placeholders where the array key is the name of value the content of the placeholder.

public void setPlaceholderValues ( array $placeholders )
$placeholders array

An array with placeholders where key is name and the value the content e.g. ['content' => 'The placheholder Content'].

                public function setPlaceholderValues(array $placeholders)
{
    $this->_placeholderValues = $placeholders;
}

            
setVarValues() public method

Defined in: luya\cms\base\InternalBaseBlock::setVarValues()

Set the values for element vars with an array key value binding.

public void setVarValues ( array $values )
$values array

An array where key is the name of the var-element and value the content.

                public function setVarValues(array $values)
{
    foreach ($values as $key => $value) {
        $this->_varValues[$key] = $value;
    }
}

            
setup() public method (available since version 3.4.0)

Defined in: luya\cms\base\InternalBaseBlock::setup()

This method is run when the block object is initialized in frontend context.

public void setup ( )

                public function setup()
{
}

            
variations() public static method

Defined in: luya\cms\base\InternalBaseBlock::variations()

Configure Variations.

TextBlock::variations()
    ->add('bold', 'Bold Font with Markdown')->cfgs(['cssClass' => 'bold-font-class'])->vars(['textType' => 1])
    ->add('italic', 'Italic Font')->cfgs(['cssClass' => 'italic-font-class'])
    ->register(),
VideoBlock::variations()
    ->add('bold', 'Bold Videos')->cfgs([])->register(),
public static luya\cms\base\BlockVariationRegister variations ( )

                public static function variations()
{
    /** @phpstan-ignore-next-line */
    return (new BlockVariationRegister(new static()));
}