@@ -51,6 +51,13 @@ class WidgetGroup
5151 */
5252 protected $ count = 0 ;
5353
54+ /**
55+ * A callback that defines extra markup that wraps every widget in the group.
56+ *
57+ * @var callable
58+ */
59+ protected $ wrapCallback ;
60+
5461 /**
5562 * @param $name
5663 * @param ApplicationWrapperContract $app
@@ -72,12 +79,12 @@ public function display()
7279 ksort ($ this ->widgets );
7380
7481 $ output = '' ;
75- $ count = 0 ;
82+ $ index = 0 ;
7683 foreach ($ this ->widgets as $ position => $ widgets ) {
7784 foreach ($ widgets as $ widget ) {
78- $ count++ ;
79- $ output .= $ this -> displayWidget ( $ widget ) ;
80- if ($ this ->count !== $ count ) {
85+ $ output .= $ this -> performWrap ( $ this -> displayWidget ( $ widget ), $ index , $ this -> count ) ;
86+ $ index ++ ;
87+ if ($ this ->count !== $ index ) {
8188 $ output .= $ this ->separator ;
8289 }
8390 }
@@ -119,7 +126,7 @@ public function addAsyncWidget()
119126 /**
120127 * Getter for position.
121128 *
122- * @return array
129+ * @return int
123130 */
124131 public function getPosition ()
125132 {
@@ -140,6 +147,20 @@ public function setSeparator($separator)
140147 return $ this ;
141148 }
142149
150+ /**
151+ * Setter for $this->wrapCallback.
152+ *
153+ * @param callable $callable
154+ *
155+ * @return $this
156+ */
157+ public function wrap (callable $ callable )
158+ {
159+ $ this ->wrapCallback = $ callable ;
160+
161+ return $ this ;
162+ }
163+
143164 /**
144165 * Check if there are any widgets in the group.
145166 *
@@ -219,4 +240,24 @@ protected function resetPosition()
219240 {
220241 $ this ->position = 100 ;
221242 }
243+
244+ /**
245+ * Wraps widget content in a special markup defined by $this->wrap().
246+ *
247+ * @param string $content
248+ * @param int $index
249+ * @param int $total
250+ *
251+ * @return string
252+ */
253+ protected function performWrap ($ content , $ index , $ total )
254+ {
255+ if (is_null ($ this ->wrapCallback )) {
256+ return $ content ;
257+ }
258+
259+ $ callback = $ this ->wrapCallback ;
260+
261+ return $ callback ($ content , $ index , $ total );
262+ }
222263}
0 commit comments