-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #643 from creative-commoners/pulls/4.3/bootstrap-a…
…lerts NEW Use Bootstrap alerts throughout the CMS
- Loading branch information
Showing
12 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Forms; | ||
|
||
use SilverStripe\Core\Extension; | ||
|
||
/** | ||
* Will convert a SilverStripe message type into a Bootstrap alert type | ||
*/ | ||
class FormMessageBootstrapExtension extends Extension | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
protected $bootstrapAlertsMap = [ | ||
'good' => 'alert-success', | ||
'bad' => 'alert-danger', | ||
'required' => 'alert-danger', | ||
'warning' => 'alert-warning', | ||
]; | ||
|
||
/** | ||
* Maps a SilverStripe message type to a Bootstrap alert type | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function getAlertType() | ||
{ | ||
$type = $this->owner->getMessageType(); | ||
|
||
if (isset($this->bootstrapAlertsMap[$type])) { | ||
return $this->bootstrapAlertsMap[$type]; | ||
} | ||
|
||
// Fallback to original | ||
return $type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p id="$Name" class="field $Type"> | ||
$Field | ||
<label class="right" for="$id">$Title</label> | ||
<% if $Message %><span class="alert $AlertType">$Message</span><% end_if %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
themes/cms-forms/templates/SilverStripe/Forms/Includes/Form.ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<% if $IncludeFormTag %> | ||
<form $AttributesHTML> | ||
<% end_if %> | ||
<% if $Message %> | ||
<p id="{$FormName}_error" class="alert $AlertType">$Message</p> | ||
<% else %> | ||
<p id="{$FormName}_error" class="alert $AlertType" style="display: none"></p> | ||
<% end_if %> | ||
|
||
<fieldset> | ||
<% if $Legend %><legend>$Legend</legend><% end_if %> | ||
<% loop $Fields %> | ||
$FieldHolder | ||
<% end_loop %> | ||
<div class="clear"><!-- --></div> | ||
</fieldset> | ||
|
||
<% if $Actions %> | ||
<div class="btn-toolbar"> | ||
<% loop $Actions %> | ||
$Field | ||
<% end_loop %> | ||
</div> | ||
<% end_if %> | ||
<% if $IncludeFormTag %> | ||
</form> | ||
<% end_if %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters