Install category CMS blocks

Edit on GitHub

A category block is a CMS block that can be embedded into a category template.

To integrate the category blocks, follow the steps:

  1. Install the CmsBlockCategoryConnector module using Composer:
composer require spryker/cms-block-category-connector:"^2.6.0"
  1. To register the CMS block form plugin, add CmsBlockCategoryFormPlugin to the CMS Block GUI dependency provider:

src/Pyz/Zed/CmsBlockGui/CmsBlockGuiDependencyProvider.php

<?php

namespace Pyz\Zed\CmsBlockGui;

use Spryker\Zed\CmsBlockCategoryConnector\Communication\Plugin\CmsBlockCategoryFormPlugin;
use Spryker\Zed\CmsBlockGui\CmsBlockGuiDependencyProvider as SprykerCmsBlockGuiDependencyProvider;

class CmsBlockGuiDependencyProvider extends SprykerCmsBlockGuiDependencyProvider
{
    /**
     * @return array<\Spryker\Zed\CmsBlockGui\Communication\Plugin\CmsBlockFormPluginInterface>
     */
    protected function getCmsBlockFormPlugins(): array
    {
        return array_merge(parent::getCmsBlockFormPlugins(), [
            new CmsBlockCategoryFormPlugin(),
        ]);
    }
}

  1. To register the CMS block form handler plugin, add CmsBlockCategoryConnectorUpdatePlugin to the CMS Block dependency provider:

src/Pyz/Zed/CmsBlock/CmsBlockDependencyProvider.php

<?php

namespace Pyz\Zed\CmsBlock;

use Spryker\Zed\CmsBlock\CmsBlockDependencyProvider as SprykerCmsBlockDependencyProvider;
use Spryker\Zed\CmsBlockCategoryConnector\Communication\Plugin\CmsBlockCategoryConnectorUpdatePlugin;

class CmsBlockDependencyProvider extends SprykerCmsBlockDependencyProvider
{
    /**
     * @return array<\Spryker\Zed\CmsBlockExtension\Dependency\Plugin\CmsBlockUpdatePluginInterface>
     */
    protected function getCmsBlockUpdatePlugins(): array
    {
        return array_merge(parent::getCmsBlockUpdatePlugins(), [
            new CmsBlockCategoryConnectorUpdatePlugin(),
        ]);
    }
}
  1. Register the category relation update plugin:

src/Pyz/Zed/Category/CategoryDependencyProvider.php

<?php

namespace Pyz\Zed\Category;

use Spryker\Zed\Category\CategoryDependencyProvider as SprykerCategoryDependencyProvider;
use Spryker\Zed\CmsBlockCategoryConnector\Communication\Plugin\Category\CmsBlockCategoryCategoryRelationPlugin;

class CategoryDependencyProvider extends SprykerCategoryDependencyProvider
{
    /**
     * @return array<\Spryker\Zed\CategoryExtension\Dependency\Plugin\CategoryRelationUpdatePluginInterface>
     */
    protected function getRelationUpdatePluginStack(): array
    {
        return array_merge(parent::getRelationUpdatePluginStack(), [
            new CmsBlockCategoryCategoryRelationPlugin(),
        ]);
    }
}
  1. Register the category subform and category relation read plugins:
src/Pyz/Zed/CategoryGui/CategoryGuiDependencyProvider.php
<?php

namespace Pyz\Zed\CategoryGui;

use Spryker\Zed\CategoryGui\CategoryGuiDependencyProvider as SpykerCategoryGuiDependencyProvider;
use Spryker\Zed\CmsBlockCategoryConnector\Communication\Plugin\CategoryGui\CmsBlockCategoryRelationReadPlugin;
use Spryker\Zed\CmsBlockCategoryConnector\Communication\Plugin\CategoryGui\CmsBlockSubformCategoryFormPlugin;

/**
 * @method \Spryker\Zed\CategoryGui\CategoryGuiConfig getConfig()
 */
class CategoryGuiDependencyProvider extends SpykerCategoryGuiDependencyProvider
{
    /**
     * @return array<\Spryker\Zed\CategoryGuiExtension\Dependency\Plugin\CategoryFormPluginInterface>
     */
    protected function getCategoryFormPlugins(): array
    {
        return [
            new CmsBlockSubformCategoryFormPlugin(),
        ];
    }

    /**
     * @return array<\Spryker\Zed\CategoryGuiExtension\Dependency\Plugin\CategoryRelationReadPluginInterface>
     */
    protected function getCategoryRelationReadPlugins(): array
    {
        return [
            new CmsBlockCategoryRelationReadPlugin(),
        ];
    }
}
  1. Optional: To show which categories a block is assigned to on the View CMS Block page, register the category list plugin by adding CmsBlockCategoryListViewPlugin to the CMS Block GUI dependency provider:

src/Pyz/Zed/CmsBlockGui/CmsBlockGuiDependencyProvider.php

<?php

namespace Pyz\Zed\CmsBlockGui;

use Spryker\Zed\CmsBlockCategoryConnector\Communication\Plugin\CmsBlockCategoryListViewPlugin;
use Spryker\Zed\CmsBlockGui\CmsBlockGuiDependencyProvider as SprykerCmsBlockGuiDependencyProvider;

class CmsBlockGuiDependencyProvider extends SprykerCmsBlockGuiDependencyProvider
{
    /**
     * @return array<\Spryker\Zed\CmsBlockGui\Communication\Plugin\CmsBlockViewPluginInterface>
     */
    protected function getCmsBlockViewPlugins(): array
    {
        return array_merge(parent::getCmsBlockViewPlugins(), [
            new CmsBlockCategoryListViewPlugin(),
        ]);
    }
}
  1. To show category CMS blocks on category pages, update the catalog.twig template:
{% if category is defined %}
	{{ spyCmsBlock({category: category.id_category}) }}
{% endif %}

Now you can create category CMS blocks and add them to category pages. For instructions, see Create category CMS blocks.

Also, you can define custom positions for category blocks.