Class luya\cms\frontend\blocks\MirrorLanguageBlock
Mirror Language Content.
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 |
admin() | luya\cms\frontend\blocks\MirrorLanguageBlock | |
blockGroup() | Contains the class name for the block group class | luya\cms\frontend\blocks\MirrorLanguageBlock |
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\frontend\blocks\MirrorLanguageBlock |
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\frontend\blocks\MirrorLanguageBlock | |
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\frontend\blocks\MirrorLanguageBlock |
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\frontend\blocks\MirrorLanguageBlock |
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
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
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);
}
}
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();
}
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;
}
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();
}
public void admin ( ) |
public function admin()
{
if (empty($this->getVarValue('language'))) {
return '<div>'.Module::t('block_mirror_admin_empty_language').'</div>';
}
return '<div>'.Module::t('block_mirror_admin_configured_language', ['name' => Lang::find()->where(['id' => $this->getVarValue('language')])->select(['name'])->scalar()]).'</div>';
}
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 DevelopmentGroup::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 array config ( ) |
public function config()
{
return [
'vars' => [
['var' => 'language', 'label' => Module::t('block_mirror_config_language_label'), 'type' => self::TYPE_SELECT, 'options' => BlockHelper::selectArrayOption(Lang::find()->select(['name', 'id'])->indexBy('id')->column())],
],
];
}
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. |
public function createAjaxLink($callbackName, array $params = [])
{
$params['callback'] = Inflector::camel2id($callbackName);
$params['id'] = $this->getEnvOption('id', 0);
return Url::toAjax('cms/block/index', $params);
}
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;
}
Defined in: luya\cms\base\InternalBaseBlock::extraVars()
Define additional variables.
public array extraVars ( ) |
public function extraVars()
{
return [];
}
public void frontend ( ) |
public function frontend()
{
$langId = $this->getVarValue('language');
// if no language is selected, just do nothing
if (empty($langId)) {
return;
}
if ($langId == Yii::$app->adminLanguage->activeId) {
return Yii::debug('Circular content mirroring detected.', __METHOD__);
}
$item = NavItemPageBlockItem::find()
->select(['placeholder_var', 'nav_item_page_id'])
->where(['id' => $this->getEnvOption('id')])
->asArray()
->one();
// unabel to find item, just do nothing
if (!$item) {
return;
}
$navItemId = NavItemPage::find()->where(['id' => $item['nav_item_page_id']])->select(['nav_item_id'])->scalar();
$navId = NavItem::find()->where(['id' => $navItemId])->select(['nav_id'])->scalar();
$navItem = NavItem::find()->where(['nav_id' => $navId, 'nav_item_type' => NavItem::TYPE_PAGE, 'lang_id' => $langId])->one();
if ($navItem) {
return $navItem->type->renderPlaceholder($item['placeholder_var']);
}
}
Defined in: luya\cms\base\InternalBaseBlock::getCacheExpirationTime()
The time of cache expiration
public integer getCacheExpirationTime ( ) |
public function getCacheExpirationTime()
{
return $this->cacheExpiration;
}
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;
}
Defined in: luya\cms\base\InternalBaseBlock::getCfgValues()
public array getCfgValues ( ) |
public function getCfgValues()
{
return $this->_cfgValues;
}
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);
}
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;
}
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;
}
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);
}
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;
}
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;
}
Defined in: luya\cms\base\InternalBaseBlock::getExtraValue()
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;
}
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;
}
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 [];
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
Defined in: luya\cms\base\InternalBaseBlock::getVarValues()
public array getVarValues ( ) |
public function getVarValues()
{
return $this->_varValues;
}
Defined in: luya\cms\base\PhpBlock::getView()
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;
}
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;
}
Defined in: luya\cms\base\PhpBlock::getViewPath()
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';
}
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()
{
}
Defined in: luya\cms\base\InternalBaseBlock::injectorSetup()
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;
}
}
}
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 [];
}
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;
}
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;
}
Get the name of the block in order to display in administration context.
public void name ( ) |
public function name()
{
return Module::t('block_mirror_language_name');
}
Defined in: luya\cms\base\InternalBaseBlock::offsetExists()
public void offsetExists ( $offset ) | ||
$offset |
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->_injectorObjects[$offset]);
}
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;
}
Defined in: luya\cms\base\InternalBaseBlock::offsetSet()
public void offsetSet ( $offset, $value ) | ||
$offset | ||
$value |
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->_injectorObjects[$offset] = $value;
}
Defined in: luya\cms\base\InternalBaseBlock::offsetUnset()
public void offsetUnset ( $offset ) | ||
$offset |
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->_injectorObjects[$offset]);
}
Defined in: luya\cms\base\PhpBlock::onRegister()
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);
}
}
Defined in: luya\cms\base\PhpBlock::onRegisterFromCache()
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);
}
}
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();
}
Defined in: luya\cms\base\PhpBlock::renderAdmin()
Get the output in administration context.
public string renderAdmin ( ) |
public function renderAdmin()
{
$this->injectorSetup();
return $this->admin();
}
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;
}
Defined in: luya\cms\base\PhpBlock::renderFrontend()
Get the output in the frontend context.
public string renderFrontend ( ) |
public function renderFrontend()
{
$this->injectorSetup();
return $this->frontend();
}
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;
}
}
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;
}
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. |
public function setPlaceholderValues(array $placeholders)
{
$this->_placeholderValues = $placeholders;
}
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;
}
}
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()
{
}
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()));
}