Skip to content

[CMS] Add ability to load block and pages by identifiers #10414

@okorshenko

Description

@okorshenko

Description

As a Magento develop I would like to have a @api interface to get CMS pages and blocks by identifiers and store id.

Existing API

Existing API of the CMS module provides an ability to:

  • get page/block by ID (BlockRepositoryInterface::get, PageRepositoryInterface::get)
  • search page/block by search criteria (BlockRepositoryInterface::search, PageRepositoryInterface::search)

Solution

  1. Introduce BlockManagementInterface and PageManagementInterface to provide an ability get CMS pages and blocks by identifiers and store id.
namespace Magento\Cms\Model;
/**
 * @api
 */
interface BlockManagementInterface
{
    /**
     * Load Block data by given Block identifier.
     *
     * @param string $identifier
     * @param int|null $storeId
     * @return \Magento\Cms\Api\Data\BlockInterface
     */
    public function getByIdentifier($identifier, $storeId = null);
}
namespace Magento\Cms\Model;

/**
 * @api
 */
interface PageManagementInterface
{
    /**
     * Load Page data by given Page identifier.
     *
     * @param string $identifier
     * @param int|null $storeId
     * @return \Magento\Cms\Api\Data\PageInterface
     */
    public function getByIdentifier($identifier, $storeId = null);
}
  1. Provide default implemetation for the new interfaces.
  2. If store id is NULL, use current store ID.

Note: All new @api classes must be covered with the tests

Related issues:

  1. There is no ability to pass store ID during getting CMS page/block by identity. #6570
  2. CMS Page and Block - Load by identifier and store id - fix issue 6570 #7417
  3. [Cms] Added a getByIdentifier() method to the BlockRepository #9163
  4. [Cms] Added a getByIdentifier() method to the block reposistory #8858

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions