diff --git a/library/Icinga/Web/Form/Decorator/FormNotifications.php b/library/Icinga/Web/Form/Decorator/FormNotifications.php new file mode 100644 index 000000000..ed725e625 --- /dev/null +++ b/library/Icinga/Web/Form/Decorator/FormNotifications.php @@ -0,0 +1,95 @@ +getElement(); + if (! $form instanceof Form) { + return $content; + } + + $view = $form->getView(); + if ($view === null) { + return $content; + } + + $notifications = $this->recurseForm($form); + + if (empty($notifications)) { + return $content; + } + + $html = ''; + case self::PREPEND: + return $html . '' . $content; + } + } + + /** + * Recurse the given form and return the notifications for it and all of its subforms + * + * @param Form $form The form to recurse + * + * @return array + */ + protected function recurseForm(Form $form) + { + $notifications = $form->getNotifications(); + + foreach ($form->getSubForms() as $subForm) { + $notifications = $notifications + $this->recurseForm($subForm); + } + + return $notifications; + } + + /** + * Get the readable type name of the notification + * + * @param $type Type of the message + * + * @return string + */ + public static function getNotificationTypeName($type) + { + switch ($type) { + case Form::NOTIFICATION_ERROR: + return 'error'; + break; + case Form::NOTIFICATION_WARNING: + return 'warning'; + break; + case Form::NOTIFICATION_INFO: + return 'info'; + break; + default: + return 'unknown'; + } + } +}