Class luya\cms\base\BlockVariationRegister

Inheritanceluya\cms\base\BlockVariationRegister
Available since version1.0.0
Source Code https://github.com/luyadev/luya-module-cms/blob/master/src/base/BlockVariationRegister.php

Generate Block Flavor Variations.

The register output generates:

textBlock::class => [
    'variation1' => [
        'title' => 'Variation Auswahl für Fetti Font Css Class',
        'cfgs' => ['cssClass' => 'fetti-font-css-class'],
        'vars' => ['textType' => 1],
        'is_default' => 0
    ],
]

In order to configure the blockVariations property of the cms admin module:

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(),

Protected Properties

Hide inherited properties

Property Type Description Defined By
$block luya\cms\base\InternalBaseBlock Internal base block from where the BlockFlavor has been instantiatet. luya\cms\base\BlockVariationRegister

Property Details

Hide inherited properties

$block protected property

Internal base block from where the BlockFlavor has been instantiatet.

Method Details

Hide inherited methods

__construct() public method

public void __construct ( luya\cms\base\InternalBaseBlock $block )
$block luya\cms\base\InternalBaseBlock

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

            
add() public method

Register a new flavor.

public luya\cms\base\BlockVariationRegister add ( $identifier, $title )
$identifier string
$title string

                public function add($identifier, $title)
{
    $identifier = Inflector::slug($identifier);
    $this->_variations[$identifier] = [
        'title' => $title,
        'cfgs' => [],
        'vars' => [],
        'extras' => [],
        'is_default' => false,
    ];
    $this->_tempIdentifier = $identifier;
    return $this;
}

            
asDefault() public method (available since version 1.0.8)

Add option to register a variations as default.

This means that when a cfg or value has no user input data, this value will be used.

This implementation does not check whether another variation has the default check, so make sure that only a single entry can be the default entry.

public luya\cms\base\BlockVariationRegister asDefault ( )

                public function asDefault()
{
    $this->_variations[$this->_tempIdentifier]['is_default'] = true;
    return $this;
}

            
cfgs() public method

Flavor CFG variables.

public luya\cms\base\BlockVariationRegister cfgs ( array $config )
$config array

                public function cfgs(array $config)
{
    $this->_variations[$this->_tempIdentifier]['cfgs'] = $config;
    return $this;
}

            
extras() public method

Flavor EXTRA variables.

public luya\cms\base\BlockVariationRegister extras ( array $config )
$config array

                public function extras(array $config)
{
    $this->_variations[$this->_tempIdentifier]['extras'] = $config;
    return $this;
}

            
register() public method

public array register ( )

                public function register()
{
    return [$this->block->className() => $this->_variations];
}

            
vars() public method

Flavor VAR variables.

public luya\cms\base\BlockVariationRegister vars ( array $config )
$config array

                public function vars(array $config)
{
    $this->_variations[$this->_tempIdentifier]['vars'] = $config;
    return $this;
}