_storeManager = $storeManager; parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); } /** * Initialize collection model * * @return void * @codeCoverageIgnore */ protected function _construct() { $this->_init(\Magento\Eav\Model\Form\Fieldset::class, \Magento\Eav\Model\ResourceModel\Form\Fieldset::class); } /** * Add Form Type filter to collection * * @param Type|int $type * @return $this */ public function addTypeFilter($type) { if ($type instanceof Type) { $type = $type->getId(); } return $this->addFieldToFilter('type_id', $type); } /** * Set order by fieldset sort order * * @return $this * @codeCoverageIgnore */ public function setSortOrder() { $this->setOrder('sort_order', self::SORT_ORDER_ASC); return $this; } /** * Retrieve label store scope * * @return int */ public function getStoreId() { if ($this->_storeId === null) { return $this->_storeManager->getStore()->getId(); } return $this->_storeId; } /** * Set store scope ID * * @param int $storeId * @return $this * @codeCoverageIgnore */ public function setStoreId($storeId) { $this->_storeId = $storeId; return $this; } /** * Initialize select object * * @return $this */ protected function _initSelect() { parent::_initSelect(); $select = $this->getSelect(); $select->join( ['default_label' => $this->getTable('eav_form_fieldset_label')], 'main_table.fieldset_id = default_label.fieldset_id AND default_label.store_id = 0', [] ); if ($this->getStoreId() == 0) { $select->columns('label', 'default_label'); } else { $labelExpr = $select->getConnection()->getIfNullSql('store_label.label', 'default_label.label'); $joinCondition = $this->getConnection()->quoteInto( 'main_table.fieldset_id = store_label.fieldset_id AND store_label.store_id = ?', (int)$this->getStoreId() ); $select->joinLeft( ['store_label' => $this->getTable('eav_form_fieldset_label')], $joinCondition, ['label' => $labelExpr] ); } return $this; } }