Collection.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Model\ResourceModel\Design\Config;
  7. use Magento\Config\Model\ResourceModel\Config\Data\Collection as ConfigCollection;
  8. use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
  9. use Magento\Framework\Data\Collection\EntityFactoryInterface;
  10. use Magento\Framework\DB\Adapter\AdapterInterface;
  11. use Magento\Framework\Event\ManagerInterface;
  12. use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
  13. use Magento\Theme\Model\Design\Config\ValueProcessor;
  14. use Psr\Log\LoggerInterface;
  15. class Collection extends ConfigCollection
  16. {
  17. /**
  18. * @var \Magento\Theme\Model\Design\Config\ValueProcessor
  19. */
  20. protected $valueProcessor;
  21. /**
  22. * @param EntityFactoryInterface $entityFactory
  23. * @param LoggerInterface $logger
  24. * @param FetchStrategyInterface $fetchStrategy
  25. * @param ManagerInterface $eventManager
  26. * @param ValueProcessor $valueProcessor
  27. * @param AdapterInterface|null $connection
  28. * @param AbstractDb|null $resource
  29. */
  30. public function __construct(
  31. EntityFactoryInterface $entityFactory,
  32. LoggerInterface $logger,
  33. FetchStrategyInterface $fetchStrategy,
  34. ManagerInterface $eventManager,
  35. ValueProcessor $valueProcessor,
  36. AdapterInterface $connection = null,
  37. AbstractDb $resource = null
  38. ) {
  39. $this->valueProcessor = $valueProcessor;
  40. parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
  41. }
  42. /**
  43. * Add paths filter to collection
  44. *
  45. * @param array $paths
  46. * @return $this
  47. */
  48. public function addPathsFilter(array $paths)
  49. {
  50. $this->addFieldToFilter('path', ['in' => $paths]);
  51. return $this;
  52. }
  53. /**
  54. * Add scope ID filter to collection
  55. *
  56. * @param int $scopeId
  57. * @return $this
  58. */
  59. public function addScopeIdFilter($scopeId)
  60. {
  61. $this->addFieldToFilter('scope_id', (int)$scopeId);
  62. return $this;
  63. }
  64. /**
  65. * @inheritDoc
  66. */
  67. protected function _afterLoad()
  68. {
  69. foreach ($this->_items as $item) {
  70. $item->setData(
  71. 'value',
  72. $this->valueProcessor->process(
  73. $item->getData('value'),
  74. $this->getData('scope'),
  75. $this->getData('scope_id'),
  76. $item->getData('path')
  77. )
  78. );
  79. }
  80. parent::_afterLoad();
  81. }
  82. }