/**
  * Gets messages and removes them from storage
  *
  * @param string $type
  * @return array
  **/
 public function getMessages($type = self::MSG_ERROR)
 {
     $this->getFlashMessenger()->setNamespace($type);
     $messages = $this->_flashMessenger->getMessages();
     $currentMessages = $this->_flashMessenger->getCurrentMessages();
     $this->_flashMessenger->clearMessages();
     $this->_flashMessenger->clearCurrentMessages();
     $messages = array_merge($messages, $currentMessages);
     return $messages;
 }
Exemplo n.º 2
0
 /**
  * Generate flash message <div>'s with appropriate classes based on message type.
  *
  * @return string $html
  */
 public function __invoke()
 {
     $html = '';
     $namespaces = ['error', 'info', 'success'];
     foreach ($namespaces as $ns) {
         $this->fm->setNamespace($ns);
         $messages = array_merge($this->fm->getMessages(), $this->fm->getCurrentMessages());
         foreach (array_unique($messages, SORT_REGULAR) as $msg) {
             $html .= '<div class="' . $this->getClassForNamespace($ns) . '">';
             // Advanced form:
             if (is_array($msg)) {
                 // Use a different translate helper depending on whether
                 // or not we're in HTML mode.
                 if (!isset($msg['translate']) || $msg['translate']) {
                     $helper = isset($msg['html']) && $msg['html'] ? 'translate' : 'transEsc';
                 } else {
                     $helper = isset($msg['html']) && $msg['html'] ? false : 'escapeHtml';
                 }
                 $helper = $helper ? $this->getView()->plugin($helper) : false;
                 $tokens = isset($msg['tokens']) ? $msg['tokens'] : [];
                 $default = isset($msg['default']) ? $msg['default'] : null;
                 $html .= $helper ? $helper($msg['msg'], $tokens, $default) : $msg['msg'];
             } else {
                 // Basic default string:
                 $transEsc = $this->getView()->plugin('transEsc');
                 $html .= $transEsc($msg);
             }
             $html .= '</div>';
         }
         $this->fm->clearMessages();
         $this->fm->clearCurrentMessages();
     }
     return $html;
 }
 /**
  * Outputs message depending on flag
  *
  * @return string
  */
 public function __invoke()
 {
     // get messages
     $messages = array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()));
     // initialize output
     $output = '';
     // loop through messages
     foreach ($messages as $message) {
         // create output
         $output .= '<div class="alert alert-success">';
         $output .= '<button class="close" data-dismiss="alert" type="button">×</button>';
         $output .= '<h2>' . $message . '</h2>';
         $output .= '</div>';
     }
     // clear messages
     $this->flashMessenger->clearMessages();
     $this->flashMessenger->clearCurrentMessages();
     // return output
     return $output . "\n";
 }
Exemplo n.º 4
0
 /**
  * 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";
 }
Exemplo n.º 5
0
 /**
  * Outputs message depending on flag
  *
  * @return string 
  */
 public function __invoke()
 {
     // get messages
     $messages = array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()));
     // initialize output
     $output = '';
     // loop through messages
     foreach ($messages as $message) {
         // split into parts to identify $class and $textDomain
         $parts = explode('_', $message);
         $class = $parts[2];
         $textDomain = $parts[0];
         // create output
         $output .= '<div class="alert alert-' . $class . '">';
         $output .= '<button class="close" data-dismiss="alert" type="button">×</button>';
         $output .= $this->getView()->translate($message, $textDomain);
         $output .= '</div>';
     }
     // clear messages
     $this->flashMessenger->clearMessages();
     $this->flashMessenger->clearCurrentMessages();
     // return output
     return $output . "\n";
 }