diff --git a/_config/forms.yml b/_config/forms.yml index feeb96fc9..76cb59ac4 100644 --- a/_config/forms.yml +++ b/_config/forms.yml @@ -4,3 +4,11 @@ Name: adminforms SilverStripe\Forms\GridField\GridFieldPrintButton: extensions: - SilverStripe\Admin\Forms\GridFieldPrintButtonExtension + +SilverStripe\Forms\Form: + extensions: + - SilverStripe\Forms\FormMessageBootstrapExtension + +SilverStripe\Forms\FormField: + extensions: + - SilverStripe\Forms\FormMessageBootstrapExtension diff --git a/code/Forms/FormMessageBootstrapAdapter.php b/code/Forms/FormMessageBootstrapAdapter.php new file mode 100644 index 000000000..41f2c54bc --- /dev/null +++ b/code/Forms/FormMessageBootstrapAdapter.php @@ -0,0 +1,38 @@ + '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; + } +} diff --git a/templates/SilverStripe/Admin/Includes/CMSProfileController_EditForm.ss b/templates/SilverStripe/Admin/Includes/CMSProfileController_EditForm.ss index 5ebaa71c5..927dd9aa5 100644 --- a/templates/SilverStripe/Admin/Includes/CMSProfileController_EditForm.ss +++ b/templates/SilverStripe/Admin/Includes/CMSProfileController_EditForm.ss @@ -2,9 +2,9 @@
$Message
<% else %> - + <% end_if %>$RightTitle
<% end_if %> diff --git a/themes/cms-forms/templates/SilverStripe/Forms/FieldGroup_holder.ss b/themes/cms-forms/templates/SilverStripe/Forms/FieldGroup_holder.ss index 08cdbb184..d7a0fbcca 100644 --- a/themes/cms-forms/templates/SilverStripe/Forms/FieldGroup_holder.ss +++ b/themes/cms-forms/templates/SilverStripe/Forms/FieldGroup_holder.ss @@ -9,8 +9,7 @@ <% if $extraClass %> $extraClass<% end_if %>" > $Field - <%-- TODO: change $MessageType to match Bootstraps alert types, e.g. alert-info, alert-danger etc --%> - <% if $Message %>$Message
<% end_if %> + <% if $Message %>$Message
<% end_if %> <% if $Description %>$Description
<% end_if %> <% if $RightTitle %>$RightTitle
<% end_if %> diff --git a/themes/cms-forms/templates/SilverStripe/Forms/FormField_holder.ss b/themes/cms-forms/templates/SilverStripe/Forms/FormField_holder.ss index bfb06da1e..73b908d87 100644 --- a/themes/cms-forms/templates/SilverStripe/Forms/FormField_holder.ss +++ b/themes/cms-forms/templates/SilverStripe/Forms/FormField_holder.ss @@ -4,8 +4,7 @@ <% end_if %>$Message
<% end_if %> + <% if $Message %>$Message
<% end_if %> <% if $Description %>$Description
<% end_if %>$RightTitle
<% end_if %> diff --git a/themes/cms-forms/templates/SilverStripe/Forms/Includes/Form.ss b/themes/cms-forms/templates/SilverStripe/Forms/Includes/Form.ss new file mode 100644 index 000000000..24a0dcfb2 --- /dev/null +++ b/themes/cms-forms/templates/SilverStripe/Forms/Includes/Form.ss @@ -0,0 +1,27 @@ +<% if $IncludeFormTag %> + +<% end_if %> diff --git a/themes/cms-forms/templates/SilverStripe/Forms/OptionsetField_holder.ss b/themes/cms-forms/templates/SilverStripe/Forms/OptionsetField_holder.ss index bfb06da1e..73b908d87 100644 --- a/themes/cms-forms/templates/SilverStripe/Forms/OptionsetField_holder.ss +++ b/themes/cms-forms/templates/SilverStripe/Forms/OptionsetField_holder.ss @@ -4,8 +4,7 @@ <% end_if %>$Message
<% end_if %> + <% if $Message %>$Message
<% end_if %> <% if $Description %>$Description
<% end_if %>$RightTitle
<% end_if %>