Skip to content

Commit

Permalink
Propagate Drupal messages to Drupal Console (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
LOBsTerr authored and jmolivas committed Feb 12, 2018
1 parent d9b655d commit 6abeb9e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Application.php
Expand Up @@ -185,6 +185,9 @@ public function doRun(InputInterface $input, OutputInterface $output)
$output
);

// Propogate Drupal messages.
$this->getDrupalMessages($messageManager);

if ($this->showMessages($input)) {
$messages = $messageManager->getMessages();

Expand Down Expand Up @@ -862,4 +865,40 @@ public function find($name)
{
return $this->get($name);
}

/**
* Gets Drupal system messages.
*/
protected function getDrupalMessages($messageManager) {
if (function_exists('drupal_get_messages')) {
$drupalMessages = drupal_get_messages();
foreach ($drupalMessages as $type => $messages) {
foreach ($messages as $message) {
$method = $this->getMessageMethod($type);
$messageManager->{$method}((string)$message);
}
}
}
}

/**
* Gets method name for MessageManager.
*
* @param string $type
* Type of the message.
*
* @return string
* Name of the method
*/
protected function getMessageMethod($type) {
$methodName = 'info';
switch ($type) {
case 'error':
case 'warning':
$methodName = $type;
break;
}

return $methodName;
}
}

0 comments on commit 6abeb9e

Please sign in to comment.