44 * See COPYING.txt for license details.
55 */
66
7- /**
8- * Attribute add/edit form options tab
9- *
10- * @author Magento Core Team <[email protected] > 11- */
127namespace Magento \Eav \Block \Adminhtml \Attribute \Edit \Options ;
138
149use Magento \Store \Model \ResourceModel \Store \Collection ;
10+ use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
1511
1612/**
13+ * Attribute add/edit form options tab
14+ *
1715 * @api
1816 * @since 100.0.2
1917 */
@@ -61,6 +59,7 @@ public function __construct(
6159
6260 /**
6361 * Is true only for system attributes which use source model
62+ *
6463 * Option labels and position for such attributes are kept in source model and thus cannot be overridden
6564 *
6665 * @return bool
@@ -96,12 +95,16 @@ public function getStoresSortedBySortOrder()
9695 {
9796 $ stores = $ this ->getStores ();
9897 if (is_array ($ stores )) {
99- usort ($ stores , function ($ storeA , $ storeB ) {
100- if ($ storeA ->getSortOrder () == $ storeB ->getSortOrder ()) {
101- return $ storeA ->getId () < $ storeB ->getId () ? -1 : 1 ;
98+ usort (
99+ $ stores ,
100+ function ($ storeA , $ storeB ) {
101+ if ($ storeA ->getSortOrder () == $ storeB ->getSortOrder ()) {
102+ return $ storeA ->getId () < $ storeB ->getId () ? -1 : 1 ;
103+ }
104+
105+ return ($ storeA ->getSortOrder () < $ storeB ->getSortOrder ()) ? -1 : 1 ;
102106 }
103- return ($ storeA ->getSortOrder () < $ storeB ->getSortOrder ()) ? -1 : 1 ;
104- });
107+ );
105108 }
106109 return $ stores ;
107110 }
@@ -130,12 +133,14 @@ public function getOptionValues()
130133 }
131134
132135 /**
133- * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
136+ * Preparing values of attribute options
137+ *
138+ * @param AbstractAttribute $attribute
134139 * @param array|\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $optionCollection
135140 * @return array
136141 */
137142 protected function _prepareOptionValues (
138- \ Magento \ Eav \ Model \ Entity \ Attribute \ AbstractAttribute $ attribute ,
143+ AbstractAttribute $ attribute ,
139144 $ optionCollection
140145 ) {
141146 $ type = $ attribute ->getFrontendInput ();
@@ -149,6 +154,41 @@ protected function _prepareOptionValues(
149154
150155 $ values = [];
151156 $ isSystemAttribute = is_array ($ optionCollection );
157+ if ($ isSystemAttribute ) {
158+ $ values = $ this ->getPreparedValues ($ optionCollection , $ isSystemAttribute , $ inputType , $ defaultValues );
159+ } else {
160+ $ optionCollection ->setPageSize (200 );
161+ $ pageCount = $ optionCollection ->getLastPageNumber ();
162+ $ currentPage = 1 ;
163+ while ($ currentPage <= $ pageCount ) {
164+ $ optionCollection ->clear ();
165+ $ optionCollection ->setCurPage ($ currentPage );
166+ $ values = array_merge (
167+ $ values ,
168+ $ this ->getPreparedValues ($ optionCollection , $ isSystemAttribute , $ inputType , $ defaultValues )
169+ );
170+ $ currentPage ++;
171+ }
172+ }
173+
174+ return $ values ;
175+ }
176+
177+ /**
178+ * Return prepared values of system or user defined attribute options
179+ *
180+ * @param array|\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $optionCollection
181+ * @param bool $isSystemAttribute
182+ * @param string $inputType
183+ * @param array $defaultValues
184+ */
185+ private function getPreparedValues (
186+ $ optionCollection ,
187+ bool $ isSystemAttribute ,
188+ string $ inputType ,
189+ array $ defaultValues
190+ ) {
191+ $ values = [];
152192 foreach ($ optionCollection as $ option ) {
153193 $ bunch = $ isSystemAttribute ? $ this ->_prepareSystemAttributeOptionValues (
154194 $ option ,
@@ -169,12 +209,13 @@ protected function _prepareOptionValues(
169209
170210 /**
171211 * Retrieve option values collection
212+ *
172213 * It is represented by an array in case of system attribute
173214 *
174- * @param \Magento\Eav\Model\Entity\Attribute\ AbstractAttribute $attribute
215+ * @param AbstractAttribute $attribute
175216 * @return array|\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection
176217 */
177- protected function _getOptionValuesCollection (\ Magento \ Eav \ Model \ Entity \ Attribute \ AbstractAttribute $ attribute )
218+ protected function _getOptionValuesCollection (AbstractAttribute $ attribute )
178219 {
179220 if ($ this ->canManageOptionDefaultOnly ()) {
180221 $ options = $ this ->_universalFactory ->create (
@@ -226,7 +267,7 @@ protected function _prepareSystemAttributeOptionValues($option, $inputType, $def
226267 foreach ($ this ->getStores () as $ store ) {
227268 $ storeId = $ store ->getId ();
228269 $ value ['store ' . $ storeId ] = $ storeId ==
229- \Magento \Store \Model \Store::DEFAULT_STORE_ID ? $ valuePrefix . $ this ->escapeHtml ($ option ['label ' ]) : '' ;
270+ \Magento \Store \Model \Store::DEFAULT_STORE_ID ? $ valuePrefix . $ this ->escapeHtml ($ option ['label ' ]) : '' ;
230271 }
231272
232273 return [$ value ];
0 commit comments