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 @@
<% if $Message %> -

$Message

+

$Message

<% else %> - + <% end_if %>
diff --git a/templates/SilverStripe/Admin/Includes/LeftAndMain_EditForm.ss b/templates/SilverStripe/Admin/Includes/LeftAndMain_EditForm.ss index 3e238cdb8..9cf8ad429 100644 --- a/templates/SilverStripe/Admin/Includes/LeftAndMain_EditForm.ss +++ b/templates/SilverStripe/Admin/Includes/LeftAndMain_EditForm.ss @@ -29,9 +29,9 @@
<% if $Message %> -

$Message

+

$Message

<% else %> - + <% end_if %>
diff --git a/themes/cms-forms/templates/RightLabelledFieldHolder.ss b/themes/cms-forms/templates/RightLabelledFieldHolder.ss new file mode 100644 index 000000000..06cb8e0a6 --- /dev/null +++ b/themes/cms-forms/templates/RightLabelledFieldHolder.ss @@ -0,0 +1,5 @@ +

+ $Field + + <% if $Message %>$Message<% end_if %> +

diff --git a/themes/cms-forms/templates/SilverStripe/Forms/CheckboxField_holder.ss b/themes/cms-forms/templates/SilverStripe/Forms/CheckboxField_holder.ss index 62a82c52e..887769249 100644 --- a/themes/cms-forms/templates/SilverStripe/Forms/CheckboxField_holder.ss +++ b/themes/cms-forms/templates/SilverStripe/Forms/CheckboxField_holder.ss @@ -4,8 +4,7 @@ $Field $Title - <%-- TODO: change $MessageType to match Bootstraps alert types, e.g. alert-info, alert-danger etc --%> - <% if $Message %><% end_if %> + <% if $Message %><% end_if %> <% if $Description %>

$Description

<% end_if %>
<% if $RightTitle %>

$RightTitle

<% end_if %> diff --git a/themes/cms-forms/templates/SilverStripe/Forms/CompositeField_holder.ss b/themes/cms-forms/templates/SilverStripe/Forms/CompositeField_holder.ss index 499c2fbea..e3c6df17e 100644 --- a/themes/cms-forms/templates/SilverStripe/Forms/CompositeField_holder.ss +++ b/themes/cms-forms/templates/SilverStripe/Forms/CompositeField_holder.ss @@ -8,8 +8,7 @@ <% if $Zebra %> form__fieldgroup-zebra<% end_if %>" > $Field - <%-- TODO: change $MessageType to match Bootstraps alert types, e.g. alert-info, alert-danger etc --%> - <% if $Message %><% end_if %> + <% if $Message %><% end_if %> <% if $Description %>

$Description

<% end_if %> <% if $RightTitle %>

$RightTitle

<% end_if %> diff --git a/themes/cms-forms/templates/SilverStripe/Forms/DatetimeField_holder.ss b/themes/cms-forms/templates/SilverStripe/Forms/DatetimeField_holder.ss index 104dbef44..5d634ce95 100644 --- a/themes/cms-forms/templates/SilverStripe/Forms/DatetimeField_holder.ss +++ b/themes/cms-forms/templates/SilverStripe/Forms/DatetimeField_holder.ss @@ -8,8 +8,7 @@ <% if $extraClass %> $extraClass<% end_if %>" > $Field - <%-- TODO: change $MessageType to match Bootstraps alert types, e.g. alert-info, alert-danger etc --%> - <% if $Message %><% end_if %> + <% if $Message %><% end_if %> <% if $Description %>

$Description

<% end_if %>
<% if $RightTitle %>

$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 %><% end_if %> + <% if $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 %>
$Field - <%-- TODO: change $MessageType to match Bootstraps alert types, e.g. alert-info, alert-danger etc --%> - <% if $Message %><% end_if %> + <% if $Message %><% end_if %> <% if $Description %>

$Description

<% end_if %>
<% if $RightTitle %>

$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 %> + <% if $Message %> +

$Message

+ <% else %> + + <% end_if %> + +
+ <% if $Legend %>$Legend<% end_if %> + <% loop $Fields %> + $FieldHolder + <% end_loop %> +
+
+ + <% if $Actions %> +
+ <% loop $Actions %> + $Field + <% end_loop %> +
+ <% end_if %> +<% 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 %>
$Field - <%-- TODO: change $MessageType to match Bootstraps alert types, e.g. alert-info, alert-danger etc --%> - <% if $Message %><% end_if %> + <% if $Message %><% end_if %> <% if $Description %>

$Description

<% end_if %>
<% if $RightTitle %>

$RightTitle

<% end_if %>