diff options
| author | Thomas Hackl <hackl@data-quest.de> | 2022-12-12 15:20:27 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2022-12-12 15:20:27 +0000 |
| commit | 936d1c00ea05bb0a5c56f441ff2eece6ccefada6 (patch) | |
| tree | 10c4b9a4a1d02780112f7ddc99f9a88b37a1ad20 /lib/classes/WidgetContainer.php | |
| parent | 54dbf11a35cac0de6fed1c50114c9583d210a40e (diff) | |
Resolve "StEP00348: Responsive Navigation Stud.IP 5.x"
Closes #32
Merge request studip/studip!65
Diffstat (limited to 'lib/classes/WidgetContainer.php')
| -rw-r--r-- | lib/classes/WidgetContainer.php | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/classes/WidgetContainer.php b/lib/classes/WidgetContainer.php index 108477a..c702d06 100644 --- a/lib/classes/WidgetContainer.php +++ b/lib/classes/WidgetContainer.php @@ -160,6 +160,24 @@ abstract class WidgetContainer } /** + * Returns the number of widgets in this container. Optionally constrained + * to widgets of a specific class. + * + * @param string|null $widget_class + * @return int + */ + public function countWidgets(string $widget_class = null): int + { + $widgets = $this->widgets; + if ($widget_class !== null) { + $widgets = array_filter($widgets, function (Widget $widget) use ($widget_class) { + return is_a($widget, $widget_class); + }); + } + return count($widgets); + } + + /** * Returns whether this container has any widget. * * @return bool True if the container has at least one widget, false @@ -167,7 +185,7 @@ abstract class WidgetContainer */ public function hasWidgets() { - return count($this->widgets) > 0; + return $this->countWidgets() > 0; } /** |
