DataProvider.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Search\Model\Synonym;
  7. use Magento\Search\Model\ResourceModel\SynonymGroup\CollectionFactory;
  8. use Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool;
  9. /**
  10. * Class DataProvider
  11. */
  12. class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
  13. {
  14. /**
  15. * @var \Magento\Search\Model\ResourceModel\SynonymGroup\Collection
  16. */
  17. protected $collection;
  18. /**
  19. * @var FilterPool
  20. */
  21. protected $filterPool;
  22. /**
  23. * @var array
  24. */
  25. protected $loadedData;
  26. /**
  27. * Constructor
  28. *
  29. * @param string $name
  30. * @param string $primaryFieldName
  31. * @param string $requestFieldName
  32. * @param CollectionFactory $blockCollectionFactory
  33. * @param FilterPool $filterPool
  34. * @param array $meta
  35. * @param array $data
  36. */
  37. public function __construct(
  38. $name,
  39. $primaryFieldName,
  40. $requestFieldName,
  41. CollectionFactory $blockCollectionFactory,
  42. FilterPool $filterPool,
  43. array $meta = [],
  44. array $data = []
  45. ) {
  46. parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
  47. $this->collection = $blockCollectionFactory->create();
  48. $this->filterPool = $filterPool;
  49. }
  50. /**
  51. * Get data
  52. *
  53. * @return array
  54. */
  55. public function getData()
  56. {
  57. if (isset($this->loadedData)) {
  58. return $this->loadedData;
  59. }
  60. $items = $this->collection->getItems();
  61. /** @var \Magento\Search\Model\SynonymGroup $synGroup */
  62. foreach ($items as $synGroup) {
  63. // Set the virtual 'scope_id' column to appropriate value.
  64. // This is necessary to display the correct selection set
  65. // in 'scope' field on the GUI.
  66. $synGroup->setScope();
  67. $this->loadedData[$synGroup->getId()] = $synGroup->getData();
  68. }
  69. return $this->loadedData;
  70. }
  71. }