@@ -57,7 +57,11 @@ public function processBlock($block)
5757 */
5858 protected function _removeAction ($ params )
5959 {
60- $ params ->getBlock ()->removeColumn ($ params ->getColumn ()->getName ());
60+ if (method_exists ($ params ->getBlock (), 'removeColumn ' )){
61+ $ params ->getBlock ()->removeColumn ($ params ->getColumn ()->getName ());
62+ } else {
63+ $ this ->removeGridColumn ($ params ->getBlock (), $ params ->getColumn ()->getName ());
64+ }
6165 }
6266
6367 /**
@@ -145,4 +149,75 @@ protected function _callProtectedMethod($object, $methodName)
145149 $ method ->setAccessible (true );
146150 return $ method ->invoke ($ object );
147151 }
152+
153+ /**
154+ * gets reflected property
155+ *
156+ * @param Mage_Adminhtml_Block_Widget_Grid $grid
157+ * @param string $propertyName
158+ * @return ReflectionProperty
159+ */
160+ private function getReflectedProperty (Mage_Adminhtml_Block_Widget_Grid $ grid , $ propertyName )
161+ {
162+ $ reflection = new ReflectionClass ($ grid );
163+ $ property = $ reflection ->getProperty ($ propertyName );
164+ $ property ->setAccessible (true );
165+ return $ property ;
166+ }
167+
168+ /**
169+ * gets a value of protected property on a grid object
170+ *
171+ * @param Mage_Adminhtml_Block_Widget_Grid $grid
172+ * @param string $propertyName
173+ * @return array
174+ */
175+ private function getGridProtectedPropertyValue (Mage_Adminhtml_Block_Widget_Grid $ grid , $ propertyName )
176+ {
177+ $ property = $ this ->getReflectedProperty ($ grid , $ propertyName );
178+ return $ property ->getValue ($ grid );
179+ }
180+
181+ /**
182+ * sets a value of protected property on a grid object
183+ *
184+ * @param Mage_Adminhtml_Block_Widget_Grid $grid
185+ * @param string $propertyName
186+ * @param mixed $propertyValue
187+ * @return Mage_Adminhtml_Block_Widget_Grid
188+ */
189+ private function setGridProtectedPropertyValue (
190+ Mage_Adminhtml_Block_Widget_Grid $ grid ,
191+ $ propertyName ,
192+ $ propertyValue
193+ )
194+ {
195+ $ property = $ this ->getReflectedProperty ($ grid , $ propertyName );
196+ $ property ->setValue ($ grid , $ propertyValue );
197+ }
198+
199+ /**
200+ * removes a column from grid if grid doesn't have any method to do it (i.e. Magento 1.5)
201+ *
202+ * @param Mage_Adminhtml_Block_Widget_Grid $grid
203+ * @param string $columnName
204+ */
205+ protected function removeGridColumn (Mage_Adminhtml_Block_Widget_Grid $ grid , $ columnName )
206+ {
207+ $ columnsPropertyName = '_columns ' ;
208+ $ lastColumnIdPropertyName = '_lastColumnId ' ;
209+
210+ $ columns = $ this ->getGridProtectedPropertyValue ($ grid , $ columnsPropertyName );
211+ $ lastColumnId = $ this ->getGridProtectedPropertyValue ($ grid , $ lastColumnIdPropertyName );
212+
213+ if (isset ($ columns [$ columnName ])) {
214+ unset($ columns [$ columnName ]);
215+ if ($ lastColumnId == $ columnName ){
216+ $ lastColumnId = key ($ columns );
217+ }
218+ }
219+
220+ $ this ->setGridProtectedPropertyValue ($ grid , $ columnsPropertyName , $ columns );
221+ $ this ->setGridProtectedPropertyValue ($ grid , $ lastColumnIdPropertyName , $ lastColumnId );
222+ }
148223}
0 commit comments