-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Collection.php
103 lines (91 loc) · 2.35 KB
/
Collection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Model\ResourceModel\Page;
use Magento\Cms\Api\Data\PageInterface;
use \Magento\Cms\Model\ResourceModel\AbstractCollection;
/**
* CMS page collection
*/
class Collection extends AbstractCollection
{
/**
* @var string
*/
protected $_idFieldName = 'page_id';
/**
* Load data for preview flag
*
* @var bool
*/
protected $_previewFlag;
/**
* @var string
*/
protected $_eventPrefix = 'cms_page_collection';
/**
* @var string
*/
protected $_eventObject = 'page_collection';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init(\Magento\Cms\Model\Page::class, \Magento\Cms\Model\ResourceModel\Page::class);
$this->_map['fields']['page_id'] = 'main_table.page_id';
$this->_map['fields']['store'] = 'store_table.store_id';
}
/**
* Set first store flag
*
* @param bool $flag
* @return $this
*/
public function setFirstStoreFlag($flag = false)
{
$this->_previewFlag = $flag;
return $this;
}
/**
* Add filter by store
*
* @param int|array|\Magento\Store\Model\Store $store
* @param bool $withAdmin
* @return $this
*/
public function addStoreFilter($store, $withAdmin = true)
{
if (!$this->getFlag('store_filter_added')) {
$this->performAddStoreFilter($store, $withAdmin);
$this->setFlag('store_filter_added', true);
}
return $this;
}
/**
* Perform operations after collection load
*
* @return $this
*/
protected function _afterLoad()
{
$entityMetadata = $this->metadataPool->getMetadata(PageInterface::class);
$this->performAfterLoad('cms_page_store', $entityMetadata->getLinkField());
$this->_previewFlag = false;
return parent::_afterLoad();
}
/**
* Perform operations before rendering filters
*
* @return void
*/
protected function _renderFiltersBefore()
{
$entityMetadata = $this->metadataPool->getMetadata(PageInterface::class);
$this->joinStoreRelationTable('cms_page_store', $entityMetadata->getLinkField());
}
}