Abstract Class luya\cms\base\InternalBaseBlock
Concret Block implementation based on BlockInterface.
This is an use case for the block implemenation as InternBaseBlock fro two froms of implementations.
- {{\luya\cms\base\PhpBlock}}
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 |
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 |
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 |
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 | |
getViewFileName() | Returns the name of the php file to be rendered. | luya\cms\base\InternalBaseBlock |
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() | Will called when the block is saved to the cache. | luya\cms\base\InternalBaseBlock |
onRegisterFromCache() | Will called when the block is loaded from the cache. | luya\cms\base\InternalBaseBlock |
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\BlockInterface |
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\BlockInterface |
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
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
Constant | Value | Description | Defined By |
---|---|---|---|
INJECTOR_CFG | 'cfg' | luya\cms\base\InternalBaseBlock | |
INJECTOR_VAR | 'var' | luya\cms\base\InternalBaseBlock |
Property Details
Enable or disable the block caching
The cache lifetime for this block in seconds (3600 = 1 hour), only affects when cacheEnabled is true. 0 means never expire.
Returns an array where each element is a row containing informations about the placeholders.
Returns an array with key value parings.
An array where the key is the cfg/var field var name and the value the helper text.
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. Container block will not display isDirty colorizing.
Containing the name of the environment (used to find the view files to render). The
module(Name) can be started with the Yii::getAlias() prefix @
, otherwhise the @
will be
added automatically. Since version 3.1.0 its possible to set null
or empty string in order to lookup
view files in the same folder where the block is located. With version 4.0 null is the default value.
app
: The alias mode allows you to map the view files to a certain alias@app
: Either alias with prefixed @ or not is possiblenull
: Empty or null will lookup the view files in the same folder where block is located (sub folder views).
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);
}
}
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();
}
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;
}
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();
}
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;
}
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);
}
::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();
}
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();
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. |
public function createAjaxLink($callbackName, array $params = [])
{
$params['callback'] = Inflector::camel2id($callbackName);
$params['id'] = $this->getEnvOption('id', 0);
return Url::toAjax('cms/block/index', $params);
}
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;
}
The time of cache expiration
public integer getCacheExpirationTime ( ) |
public function getCacheExpirationTime()
{
return $this->cacheExpiration;
}
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;
}
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);
}
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;
}
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;
}
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);
}
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;
}
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;
}
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;
}
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;
}
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 [];
}
Whether cache is enabled for this block or not.
public boolean getIsCacheEnabled ( ) |
public function getIsCacheEnabled()
{
return $this->cacheEnabled;
}
Whether this is a container element or not. Container elements usually have defined placeholders.
public boolean getIsContainer ( ) |
public function getIsContainer()
{
return $this->isContainer;
}
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;
}
public boolean getPlaceholderValue ( $placholder ) | ||
$placholder | \luya\cms\base\unknown |
public function getPlaceholderValue($placholder)
{
return $this->getPlaceholderValues()[$placholder] ?? false;
}
public void getPlaceholderValues ( ) |
public function getPlaceholderValues()
{
return $this->_placeholderValues;
}
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;
}
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;
}
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;
}
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);
}
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()
{
}
Setup injectors.
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 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 [];
}
Returns true if block is active in backend.
public boolean isAdminContext ( ) |
public function isAdminContext()
{
return ($this->getEnvOption('context', false) === 'admin') ? true : false;
}
Returns true if block is active in frontend.
public boolean isFrontendContext ( ) |
public function isFrontendContext()
{
return ($this->getEnvOption('context', false) === 'frontend') ? true : false;
}
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();
public void offsetExists ( $offset ) | ||
$offset |
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->_injectorObjects[$offset]);
}
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;
}
public void offsetSet ( $offset, $value ) | ||
$offset | ||
$value |
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->_injectorObjects[$offset] = $value;
}
public void offsetUnset ( $offset ) | ||
$offset |
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->_injectorObjects[$offset]);
}
Will called when the block is saved to the cache.
public void onRegister ( ) |
public function onRegister()
{
}
Will called when the block is loaded from the cache.
public void onRegisterFromCache ( ) |
public function onRegisterFromCache()
{
}
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();
}
Defined in: luya\cms\base\BlockInterface::renderAdmin()
Get the output in administration context.
public abstract string renderAdmin ( ) |
public function renderAdmin();
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;
}
Defined in: luya\cms\base\BlockInterface::renderFrontend()
Get the output in the frontend context.
public abstract string renderFrontend ( ) |
public function renderFrontend();
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;
}
}
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;
}
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. |
public function setPlaceholderValues(array $placeholders)
{
$this->_placeholderValues = $placeholders;
}
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;
}
}
This method is run when the block object is initialized in frontend context.
public void setup ( ) |
public function setup()
{
}
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()));
}