PHP code example of brandcom / cakephp-content-blocks

1. Go to this page and download the library: Download brandcom/cakephp-content-blocks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brandcom / cakephp-content-blocks example snippets


$this->belongsTo('Blocks', [
    'foreignKey' => 'content_blocks_block_id',
    'className' => 'ContentBlocks.Blocks',
]);

<?= $this->cell("ContentBlocks.BlocksAdmin", ['entityOrKey' => $article]) 

<?= $this->cell("ContentBlocks.BlocksAdmin", ['entityOrKey' => 'my_custom_key']) 


/**
 * @var \App\Model\Entity\TextContentBlock $block
 */

<?= $this->cell("ContentBlocks.BlocksArea", ['entity' => $article]) 

public function getFields(): array
{
    return array_merge(
        parent::getFields(),
        [
            'title' => [
                'label' => __("Block Title"),
            ],
            'style' => [
                'label' => __("Choose a style for this block."),
                'options' => [
                    'default' => __("Default Style"),
                    'funky' => __("Other cool Style"),
                ],
            ],
        ]
    );
}

public function getHiddenFields(): array
{
    return array_merge(
        parent::getHiddenFields(),
        [
            'some_field',
            'another_hidden_field',
        ]
    );
}

public function beforeFind(Event $event, Query $query): Query
{
    return $query->contain([
        'Images',
    ]);
}

public function getManagedModels(): array
{
    return [
        "SliderBlockSlides,"
    ];
}

public function getViewVariables($entity): array
{
    $vars = parent::getViewVariables($entity);

    return [
        'article' => $vars['owner'],
        'random' => "This is just a string",
        'someOtherVariable' => $this->getSomeOtherVariable($entity),
    ];
}

protected function getDisallowedEntities(): array
{
    return [
        "Articles",
        "Jobs",
    ];
}

protected function getAllowedEntities(): array
{
    return [
        "BlogPosts",
    ];
}

public function getContentBlocksViewUrl(Block $block): array
{
    $anchor = $block->html_anchor ?: "content-block-" . $block->id;

    return [
        'prefix' => false,
        'plugin' => false,
        'controller' => 'Articles',
        'action' => 'view',
        $this->slug,
        '#' => $anchor,
    ];
}