Skip to content
Snippets Groups Projects
Commit efa9d6d7 authored by Eduarda Lentz Rodrigues da Silva's avatar Eduarda Lentz Rodrigues da Silva
Browse files

ZERO-162 Created repo and updated other files with right information

parent 4c9811e4
No related branches found
No related tags found
1 merge request!46ZERO-162-changes
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Api;
interface CmsBlockRepositoryInterface
{
/**
* Get CMS Block data by its identifier.
*
* @param string $identifier
* @return array
*/
public function getByIdentifier(string $identifier): array;
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Query;
use Magento\Framework\App\State;
use Firegento\ContentProvisioning\Api\CmsBlockRepositoryInterface;
class GetCmsBlockByIdentifier
{
private $cmsBlockRepository;
public function __construct(
CmsBlockRepositoryInterface $cmsBlockRepository
) {
$this->cmsBlockRepository = $cmsBlockRepository;
}
protected function execute(string $key)
{
$blockData = $this->cmsBlockRepository->getByIdentifier($key);
if (empty($blockData)) {
throw new NotFoundException(__('Block with key %1 not found.', $key));
}
return $blockData;
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Repository;
use Firegento\ContentProvisioning\Api\CmsBlockRepositoryInterface;
use Magento\Framework\App\ResourceConnection;
class CmsBlockRepository implements CmsBlockRepositoryInterface
{
/**
* @var ResourceConnection
*/
private $resource;
/**
* CmsBlockRepository constructor.
*
* @param ResourceConnection $resource
*/
public function __construct(
ResourceConnection $resource
) {
$this->resource = $resource;
}
/**
* Get CMS Block data by its identifier.
*
* @param string $identifier
* @return array
*/
public function getByIdentifier(string $identifier): array
{
$connection = $this->resource->getConnection();
$tableName = $this->resource->getTableName('cms_block'); // Get table with prefix
$sql = "SELECT * FROM $tableName WHERE identifier = :identifier";
$bind = ['identifier' => $identifier];
$result = $connection->fetchRow($sql, $bind); // Fetch a single row
return $result ? $result : [];
}
}
\ No newline at end of file
......@@ -148,4 +148,10 @@
</argument>
</arguments>
</type>
<type name="Firegento\ContentProvisioning\Api\CmsBlockRepositoryInterface">
<arguments>
<argument name="resource" xsi:type="object">Magento\Framework\App\ResourceConnection</argument>
</arguments>
</type>
<preference for="Firegento\ContentProvisioning\Api\CmsBlockRepositoryInterface" type="Firegento\ContentProvisioning\Model\Repository\CmsBlockRepository" />
</config>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment