The admin modules are based on the SonataAdminBundle. This bundle provides you with a quick and easy way to generate entity lists, filter form, editing/create forms, preview pages, batch actions and much more. To get started with you first admin module, vist getting started with SonataAdminBundle.
We have used this bundle, restyled it a little, and added some small (very small) features to it which you can then use when creating your admin user interface.
Here are a couple of the new features on top of what Sonata already offers.
We have extended the SonataAdmin Admin class and given it one ore two little things which we often need.
- The languages of the CMS are available, this is handing when you need to create choice fields which need to list the avaliable languages of the CMS
- You can get the default language based on the available CMS languages (as per CMS config) and the users language.
- You can use the Annotations to configure your admin bundles if you prefer.
- In order for the Datatables to work, we set the default limit of entries to 1000000, if you do not extend the BaseAdmin class, you will need to set this yourself, or risk not all your entries being displayed in the list view.
We have added extra field options for added tooltips, popovers, append, and prepend buttons and help blocks.
You have 4 choices, which you can be used similtaneously:
- help_label - this will appear right below the label
- help_block - this appears below the form widget
- help - this is the standard help config from sonata and is displayed the same as the help_block, below the form label, and field
- help_label_tooltip - this will add a tooltip to the help_label, with an icon
- help_label_popover - this will add a popover to the help_label, with an icon, like the tooltip, but you need to click on the icon to see the help text
- help_block_tooltip - this will add a tooltip to the help_block, with an icon
- help_block_popover - this will add a popover to the help_block, with an icon, like the tooltip, but you need to click on the icon to see the help text
- widget_addon_prepend - this will add a prepend an icon or text to the form widget, you need to set block_prefix to input_group for this to work.
- widget_addon_append - this will add a append an icon or text to the form widget, you need to set block_prefix to input_group for this to work.
- widget_btn_prepend - this will add a prepend a button to the form widget, you need to set block_prefix to input_group for this to work.
- widget_btn_append - this will add a append a button to the form widget, you need to set block_prefix to input_group for this to work.
$formMapper
->add(
'text_block',
[
'required' => true,
'help' => 'text_block.help.text',
'help_block' => 'text_block.help.text_block',
'help_label' => 'text_block.help.text_block',
'help_label_tooltip' => [
'title' => 'text_block.tooltip.text_label',
'icon' => 'info-circle',
],
'help_label_popover' => [
'title' => 'text_block.tooltip.text_block',
'icon' => 'question-circle',
],
'help_block_tooltip' => [
'title' => 'text_block.tooltip.text_block',
'icon' => 'info-circle',
],
'help_block_popover' => [
'title' => 'text_block.tooltip.text_block',
'icon' => 'question-circle',
],
'widget_addon_prepend' => [
'icon' => 'user fs-2',
],
'widget_addon_append' => [
'text' => '@',
],
'widget_btn_prepend' => [
'icon' => 'user fs-2',
],
'widget_btn_append' => [
'text' => '@',
],
'widget_btn_prepend' => [
'icon' => 'user fs-2',
'class' => 'btn-light-primary copy-to-clipboard btn-outline',
],
'widget_btn_append' => [
'icon' => null,
'label' => 'click me',
'class' => 'btn-light-primary copy-to-clipboard btn-outline',
],
'block_prefix' => 'input_group',
],
);
By default, the first filter in the list weill appear first, and the rest will be hidden, but can be shown by clicking on the "More filter options" link. However, you can change this behaviour by setting the show_filter option to true, on any of the filters you want to show by default. If a filter is active, it will always be shown.
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$datagridMapper
->add('name')
->add('enabled', null, ['show_filter' => true])
->add('context');
}
In the above case, the name and enabeled fields would be shown by default, and the context field is hidden but can be shown by clicking on the "+ more filter options" link.