- Documentation >
- Administration >
- Back Office >
- Tab switcher in Content edit page
Tab switcher in Content edit page
Tabs switcher allows separating the default Field Types in the content type from the Field Types that enhance the content with new functionalities.
The best example of such Field Types are SEO or Taxonomy, as these are not typical Field Types but a Field Types that handle functionalities for the whole Content object.
The following example shows how to add a Meta tab with automatically assigned Taxonomy Field Type.
Before you start adding the Meta tab, make sure the content type you want to edit has Taxonomy Entry Assignment Field Type.
Next, provide the semantic configuration under the ibexa.system.<scope>.admin_ui_forms
configuration key:
| ibexa:
system:
admin_group:
admin_ui_forms:
content_edit:
fieldtypes:
ibexa_taxonomy_entry_assignment:
meta: true
|
ibexa_taxonomy_entry_assignment
- identifier for the Field Type
meta
- when set to true
, puts the declared Field Type in the Meta tab
The default configuration makes the ibexa_taxonomy_entry_assignment
Field always visible in the Meta tab in the Content form.
With this new feature, you can indicate what Field types, previously set in the Back Office content type, are shown in the Meta tab section in the Content form.
You can automatically move all Field types from Metadata group to the Meta tab in the Content form.
To do it, use the following configuration:
| ibexa:
system:
admin_group:
admin_ui_forms:
content_edit:
meta_field_groups_list:
- metadata
|
To disable the feature:
| ibexa:
system:
admin_group:
admin_ui_forms:
content_edit:
meta_field_groups_list: []
|
The meta_field_groups_list
configuration can be easily overriden.
Add custom tab
First, create an event listener in the src/EventListener/TextAnchorMenuTabListener.php
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 | <?php declare(strict_types=1);
namespace App\EventListener;
use Ibexa\AdminUi\Menu\ContentEditAnchorMenuBuilder;
use Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TextAnchorMenuTabListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [ConfigureMenuEvent::CONTENT_EDIT_ANCHOR_MENU => 'onAnchorMenuConfigure'];
}
public function onAnchorMenuConfigure(ConfigureMenuEvent $event): void
{
// access anchor menu root item
$menu = $event->getMenu();
// if you need to access "Content" tab, use ITEM__CONTENT constant:
$contentTab = $menu[ContentEditAnchorMenuBuilder::ITEM__CONTENT];
// if you need to access "Meta" tab, use ITEM__META constant:
$metaTab = $menu[ContentEditAnchorMenuBuilder::ITEM__META];
// Adding new tab called "New tab"
$menu->addChild('New tab', ['attributes' => ['data-target-id' => 'ibexa-edit-content-sections-new-tab']]);
// Add second level item "2nd level item" to previously created "New tab" tab
$menu['New tab']->addChild('2nd level item', ['attributes' => ['data-target-id' => 'ibexa-edit-content-sections-new-tab-item_2']]);
}
}
|
A new custom tab is defined in the line 28, the line 31 defines items for the second level.
For new tabs it is also required to render its section in the Content editing form. To do it, register the UI Component:
| services:
app.custom_content_edit_tab:
parent: Ibexa\AdminUi\Component\TwigComponent
arguments:
$template: '@@ibexadesign/content_type/edit/custom_tab.html.twig'
tags:
- { name: ibexa.admin_ui.component, group: 'content-edit-sections' }
|
Finally, create the templates/themes/admin/content_type/edit/custom_tab.html.twig
file:
1
2
3
4
5
6
7
8
9
10
11
12 | {% extends '@ibexadesign/ui/component/anchor_navigation/section_group.html.twig' %}
{% set data_id = 'ibexa-edit-content-sections-new-tab' %}
{% block sections %}
{% embed '@ibexadesign/ui/component/anchor_navigation/section.html.twig' %}
{% set data_id = 'ibexa-edit-content-sections-new-tab-item_2' %}
{% block content %}
Contents of custom secondary section
{% endblock %}
{% endembed %}
{% endblock %}
|