/** * Outputs message depending on flag * * @return string */ public function render() { // get messages $allMessages = ['danger' => array_unique(array_merge($this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages())), 'success' => array_unique(array_merge($this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages())), 'warning' => array_unique(array_merge($this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages())), 'info' => array_unique(array_merge($this->flashMessenger->getInfoMessages(), $this->flashMessenger->getCurrentInfoMessages())), 'default' => array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()))]; // clear messages $this->flashMessenger->clearMessagesFromContainer(); $this->flashMessenger->clearCurrentMessagesFromContainer(); // initialize output $output = ''; // loop through messages foreach ($allMessages as $groupKey => $groupMessages) { foreach ($groupMessages as $message) { $addClass = $groupKey == 'default' ? '' : 'alert-' . $groupKey; // setup view model $viewModel = new ViewModel(); $viewModel->setVariable('alertClass', $addClass); $viewModel->setVariable('alertMessage', $message); $viewModel->setTemplate('zf2rapid-library/widget/bootstrap-alert'); // add rendered output $output .= $this->getView()->render($viewModel); } } // return output return $output . "\n"; }
public function __invoke() { $messages = array(); if ($this->flashMessenger->hasMessages()) { $messages['common'] = $this->flashMessenger->getMessages(); } if ($this->flashMessenger->hasSuccessMessages()) { $messages['success'] = $this->flashMessenger->getSuccessMessages(); } if ($this->flashMessenger->hasInfoMessages()) { $messages['info'] = $this->flashMessenger->getInfoMessages(); } if ($this->flashMessenger->hasErrorMessages()) { $messages['danger'] = $this->flashMessenger->getErrorMessages(); } if ($this->flashMessenger->hasWarningMessages()) { $messages['warning'] = $this->flashMessenger->getWarningMessages(); } return $messages; }
/** * Outputs message depending on flag * * @return string */ public function __invoke() { // get messages $messages = array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages())); $warning_messages = array_unique(array_merge($this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages())); $error_messages = array_unique(array_merge($this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages())); $success_messages = array_unique(array_merge($this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages())); $this->flashMessenger->getSuccessMessages(); // initialize output $output = ''; // loop through messages foreach ($messages as $message) { // create output $output .= '<div class="alert" role="alert">'; $output .= $message; $output .= '</div>'; } foreach ($error_messages as $error_message) { // create output $output .= '<div class="alert alert-danger" role="alert">'; $output .= $error_message; $output .= '</div>'; } foreach ($warning_messages as $warning_message) { // create output $output .= '<div class="alert alert-warning" role="alert">'; $output .= $warning_message; $output .= '</div>'; } foreach ($success_messages as $success_message) { // create output $output .= '<div class="alert alert-success" role="alert">'; $output .= $success_message; $output .= '</div>'; } // clear messages $this->flashMessenger->clearMessages(); $this->flashMessenger->clearCurrentMessages(); // return output return $output . "\n"; }
public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $eventManager->attach(MvcEvent::EVENT_RENDER, function ($e) { $flashMessenger = new FlashMessenger(); $messages = array_merge($flashMessenger->getSuccessMessages(), $flashMessenger->getInfoMessages(), $flashMessenger->getErrorMessages(), $flashMessenger->getMessages()); if ($flashMessenger->hasMessages()) { $e->getViewModel()->setVariable('flashMessages', $messages); } }); $eventManager->attach('route', array($this, 'onPreRoute'), 100); $moduleRouteListener->attach($eventManager); }
/** * @param bool $admin * @param bool $current * @return string */ public function __invoke($admin = false, $current = false) { $prefix = $this->getHTMLPrefix($admin); $html = ''; $flashMessenger = new FlashMessenger(); foreach ($current ? $flashMessenger->getCurrentErrorMessages() : $flashMessenger->getErrorMessages() as $message) { $html .= $admin ? $this->renderAdminMessage($message, 'alert-error') : $this->renderAppMessage($message); } foreach ($current ? $flashMessenger->getCurrentSuccessMessages() : $flashMessenger->getSuccessMessages() as $message) { $html .= $admin ? $this->renderAdminMessage($message, 'alert-success') : $this->renderAppMessage($message); } foreach ($current ? $flashMessenger->getCurrentMessages() : $flashMessenger->getMessages() as $message) { $html .= $admin ? $this->renderAdminMessage($message, 'alert-info') : $this->renderAppMessage($message); } $postfix = $this->getHTMLPostfix($admin); return !empty($html) ? $prefix . $html . $postfix : ''; }