Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
BlockRepository Class Reference
Inheritance diagram for BlockRepository:
BlockRepositoryInterface

Public Member Functions

 __construct (ResourceBlock $resource, BlockFactory $blockFactory, \Magento\Cms\Api\Data\BlockInterfaceFactory $dataBlockFactory, BlockCollectionFactory $blockCollectionFactory, Data\BlockSearchResultsInterfaceFactory $searchResultsFactory, DataObjectHelper $dataObjectHelper, DataObjectProcessor $dataObjectProcessor, StoreManagerInterface $storeManager, CollectionProcessorInterface $collectionProcessor=null)
 
 save (Data\BlockInterface $block)
 
 getById ($blockId)
 
 delete (Data\BlockInterface $block)
 
 deleteById ($blockId)
 
- Public Member Functions inherited from BlockRepositoryInterface
 getList (\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 

Protected Attributes

 $resource
 
 $blockFactory
 
 $blockCollectionFactory
 
 $searchResultsFactory
 
 $dataObjectHelper
 
 $dataObjectProcessor
 
 $dataBlockFactory
 

Detailed Description

Class BlockRepository @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 25 of file BlockRepository.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ResourceBlock  $resource,
BlockFactory  $blockFactory,
\Magento\Cms\Api\Data\BlockInterfaceFactory  $dataBlockFactory,
BlockCollectionFactory  $blockCollectionFactory,
Data\BlockSearchResultsInterfaceFactory  $searchResultsFactory,
DataObjectHelper  $dataObjectHelper,
DataObjectProcessor  $dataObjectProcessor,
StoreManagerInterface  $storeManager,
CollectionProcessorInterface  $collectionProcessor = null 
)
Parameters
ResourceBlock$resource
BlockFactory$blockFactory
Data\BlockInterfaceFactory$dataBlockFactory
BlockCollectionFactory$blockCollectionFactory
Data\BlockSearchResultsInterfaceFactory$searchResultsFactory
DataObjectHelper$dataObjectHelper
DataObjectProcessor$dataObjectProcessor
StoreManagerInterface$storeManager
CollectionProcessorInterface$collectionProcessor

Definition at line 83 of file BlockRepository.php.

93  {
94  $this->resource = $resource;
95  $this->blockFactory = $blockFactory;
96  $this->blockCollectionFactory = $blockCollectionFactory;
97  $this->searchResultsFactory = $searchResultsFactory;
98  $this->dataObjectHelper = $dataObjectHelper;
99  $this->dataBlockFactory = $dataBlockFactory;
100  $this->dataObjectProcessor = $dataObjectProcessor;
101  $this->storeManager = $storeManager;
102  $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
103  }

Member Function Documentation

◆ delete()

delete ( Data\BlockInterface  $block)

Delete Block

Parameters
\Magento\Cms\Api\Data\BlockInterface$block
Returns
bool
Exceptions
CouldNotDeleteException

Implements BlockRepositoryInterface.

Definition at line 173 of file BlockRepository.php.

174  {
175  try {
176  $this->resource->delete($block);
177  } catch (\Exception $exception) {
178  throw new CouldNotDeleteException(__($exception->getMessage()));
179  }
180  return true;
181  }
__()
Definition: __.php:13
$block
Definition: block.php:8

◆ deleteById()

deleteById (   $blockId)

Delete Block by given Block Identity

Parameters
string$blockId
Returns
bool
Exceptions
CouldNotDeleteException
NoSuchEntityException

Implements BlockRepositoryInterface.

Definition at line 191 of file BlockRepository.php.

192  {
193  return $this->delete($this->getById($blockId));
194  }

◆ getById()

getById (   $blockId)

Load Block data by given Block Identity

Parameters
string$blockId
Returns
Block
Exceptions

Implements BlockRepositoryInterface.

Definition at line 133 of file BlockRepository.php.

134  {
135  $block = $this->blockFactory->create();
136  $this->resource->load($block, $blockId);
137  if (!$block->getId()) {
138  throw new NoSuchEntityException(__('The CMS block with the "%1" ID doesn\'t exist.', $blockId));
139  }
140  return $block;
141  }
__()
Definition: __.php:13
$block
Definition: block.php:8

◆ save()

save ( Data\BlockInterface  $block)

Save Block data

Parameters
\Magento\Cms\Api\Data\BlockInterface$block
Returns
Block
Exceptions
CouldNotSaveException

Implements BlockRepositoryInterface.

Definition at line 112 of file BlockRepository.php.

113  {
114  if (empty($block->getStoreId())) {
115  $block->setStoreId($this->storeManager->getStore()->getId());
116  }
117 
118  try {
119  $this->resource->save($block);
120  } catch (\Exception $exception) {
121  throw new CouldNotSaveException(__($exception->getMessage()));
122  }
123  return $block;
124  }
__()
Definition: __.php:13
$block
Definition: block.php:8

Field Documentation

◆ $blockCollectionFactory

$blockCollectionFactory
protected

Definition at line 40 of file BlockRepository.php.

◆ $blockFactory

$blockFactory
protected

Definition at line 35 of file BlockRepository.php.

◆ $dataBlockFactory

$dataBlockFactory
protected

Definition at line 60 of file BlockRepository.php.

◆ $dataObjectHelper

$dataObjectHelper
protected

Definition at line 50 of file BlockRepository.php.

◆ $dataObjectProcessor

$dataObjectProcessor
protected

Definition at line 55 of file BlockRepository.php.

◆ $resource

$resource
protected

Definition at line 30 of file BlockRepository.php.

◆ $searchResultsFactory

$searchResultsFactory
protected

Definition at line 45 of file BlockRepository.php.


The documentation for this class was generated from the following file: