Skip to content

Commit

Permalink
New setIcon() method added to message handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed May 6, 2019
1 parent 1d3d67c commit 2250d3c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
27 changes: 26 additions & 1 deletion e107_handlers/message_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class eMessage
*/
static $_customTitle = array();

/**
* Custom font-awesome icon
* @var array
*/
static $_customIcon = array();


static $_close = array('info'=>true,'success'=>true,'warning'=>true,'error'=>true,'debug'=>true);
/**
Expand Down Expand Up @@ -398,6 +404,22 @@ public function setTitle($title, $type)
return $this;
}

/**
* Set a custom icon (useful for front-end)
*
* @param string $fa FontAwesome reference. eg. fa-cog
* @param string $type E_MESSAGE_SUCCESS,E_MESSAGE_ERROR, E_MESSAGE_WARNING, E_MESSAGE_INFO
* @return $this
* @example e107::getMessage()->setIcon('fa-cog', E_MESSAGE_INFO);
*/
public function setIcon($fa, $type)
{
$tp = e107::getParser();
self::$_customIcon[$type] = $tp->toText($fa);

return $this;
}


/**
* Enable the 'x' close functionality of an alert.
Expand Down Expand Up @@ -567,10 +589,13 @@ public static function formatMessage($mstack, $type, $message)
//$message = array_unique($message); // quick fix for duplicates.
$message = "<div class='s-message-item'>".implode("</div>\n<div class='s-message-item'>", $message)."</div>";
}

$icon = !empty(self::$_customIcon[$type]) ? "s-message-empty fa fa-2x ".self::$_customIcon[$type] : "s-message-".$type;


$text = "<div class='s-message alert alert-block fade in {$type} {$bclass}'>";
$text .= (self::$_close[$type] === true) ? "<a class='close' data-dismiss='alert'>×</a>" : "";
$text .= "<i class='s-message-icon s-message-".$type."'></i>
$text .= "<i class='s-message-icon ".$icon."'></i>
<h4 class='s-message-title'>".self::getTitle($type, $mstack)."</h4>
<div class='s-message-body'>
{$message}
Expand Down
1 change: 1 addition & 0 deletions e107_themes/bootstrap3/admin_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ i.s-message-error { background-position: -925px 0; width: 32px; height: 32px; }
i.s-message-warning { background-position: -777px -37px; width: 32px; height: 32px; }
i.s-message-info { background-position: -1480px 0; width: 32px; height: 32px; }
i.s-message-debug { background-position: -1480px 0; width: 32px; height: 32px; }
i.s-message-empty { background:none; }

.s-message .well { background-color: rgba(0,0,0,0.4) }
.s-message-body { padding-left: 42px; }
Expand Down

0 comments on commit 2250d3c

Please sign in to comment.