Skip to content

Commit

Permalink
IBX-2667: Added Content Type Meta anchor menu (#558)
Browse files Browse the repository at this point in the history
* Added configuration for ContentType

* Added ContentTypeFieldTypesResolver

* Hidden configured field types in Field types list

* Added enabled property to FieldDefinitionData

* Added enabled form field for configured field types in FieldDefinitionType

* Added tabsFieldDefinitionsData property and form field

* Added field definitions to ContentType for configured field types

* Set tabsFieldDefinitionData in ContentTypeDraftMapper

* Added updating / removing field defeginitions when procesing tabsFieldDefinitionData

* Render enabled field on first position in field definitions

* Fixed tests

* Fixed ContentTypeDraftMapperTest

* Fixed condition to set which field should be enabled

* Dropped useless parameter admin_ui_forms.content_type_edit.form_templates

* Added ContentTypeEditAnchorMenuBuilder

* Added ContentTypeEditMetaFieldsComponent

* Fixed consts names

* Renamed tabs to meta

* Dropped scope when resolving admin_ui_forms.content_type_edit parameters

* Used LanguageService to get default language code and load Language object

* Code cleanup

* Added ContentTypeFieldTypesResolver::getMetaFieldTypeIdentifiers

* Removed unused property contentTypeFieldTypesResolver

* Fixed ContentTypeEditAnchorMenuBuilder

* Fixed MetaField label

* Fixed menu

* Removed temp configuration from admin_ui_forms

* Update src/lib/Component/ContentType/ContentTypeEditMetaFieldsComponent.php

Co-authored-by: Adam Wójs <adam@wojs.pl>

* Update src/bundle/Resources/views/themes/admin/ui/menu/content_type_anchor_menu.html.twig

Co-authored-by: Adam Wójs <adam@wojs.pl>

* Update src/lib/Form/Data/FieldDefinitionData.php

Co-authored-by: Dawid Parafiński <dawid.parafinski@ez.no>

* Added MetaFieldDefinitionService

* Update src/lib/Component/ContentType/ContentTypeEditMetaFieldsComponent.php

Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>

* Added missing docblock in ContentTypeFieldTypesResolver

* Fixed defalut value for default_meta_field_type_group parameter

* Update src/lib/Form/Data/FieldDefinitionData.php

Co-authored-by: Paweł Niedzielski <pawel.tadeusz.niedzielski@gmail.com>

* Added block_prefix for metaFieldDefinitionsData in ContentTypeUpdateType

* frontend content type form

* left sidebar

* fix styling

* added translations

* fix js and seo menu name

* Fixed block prefixes

* fixed blocks names

* fixed edit

* meta fields

* added color variable

* fix form submit

* fixed sidebar width

* Update src/bundle/DependencyInjection/Configuration/Parser/AdminUiForms.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Update src/bundle/DependencyInjection/Configuration/Parser/AdminUiForms.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Update src/bundle/DependencyInjection/Configuration/Parser/AdminUiForms.php

Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>

* Fixed field_types parameter name

* Fixed condition to check if Meta Field Type should be enabled

* Fixed ContentTypeFieldTypesResolverTest

* Fixed meta fields order

* Fixed ContentTypeFieldTypesResolver

* Update src/bundle/DependencyInjection/Configuration/Parser/AdminUiForms.php

Co-authored-by: Dawid Parafiński <dawid.parafinski@ez.no>

* Fixed CS

* Fixed CS

* Fixed CS

* Marked MetaFieldDefinitionService as internal

* Fixed rendering meta field definitions

Co-authored-by: Adam Wójs <adam@wojs.pl>
Co-authored-by: Dawid Parafiński <dawid.parafinski@ez.no>
Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>
Co-authored-by: Paweł Niedzielski <pawel.tadeusz.niedzielski@gmail.com>
Co-authored-by: Michał Grabowski <michal.grabowski@ibexa.co>
Co-authored-by: Andrew Longosz <alongosz@users.noreply.github.com>
  • Loading branch information
7 people authored Oct 3, 2022
1 parent f5a351f commit 0136b6e
Show file tree
Hide file tree
Showing 40 changed files with 1,488 additions and 242 deletions.
20 changes: 16 additions & 4 deletions src/bundle/Controller/ContentTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Ibexa\AdminUi\Form\Factory\FormFactory;
use Ibexa\AdminUi\Form\SubmitHandler;
use Ibexa\AdminUi\Form\Type\ContentType\ContentTypeUpdateType;
use Ibexa\AdminUi\Service\MetaFieldType\MetaFieldDefinitionServiceInterface;
use Ibexa\AdminUi\Tab\ContentType\TranslationsTab;
use Ibexa\AdminUi\UI\Module\FieldTypeToolbar\FieldTypeToolbarFactory;
use Ibexa\AdminUi\View\ContentTypeCreateView;
Expand Down Expand Up @@ -85,6 +86,8 @@ class ContentTypeController extends Controller
/** @var \Ibexa\AdminUi\UI\Module\FieldTypeToolbar\FieldTypeToolbarFactory */
private $fieldTypeToolbarFactory;

private MetaFieldDefinitionServiceInterface $metaFieldDefinitionService;

public function __construct(
TranslatableNotificationHandlerInterface $notificationHandler,
TranslatorInterface $translator,
Expand All @@ -97,7 +100,8 @@ public function __construct(
ContentTypeFormFactory $contentTypeFormFactory,
ContentTypeDraftMapper $contentTypeDraftMapper,
ConfigResolverInterface $configResolver,
FieldTypeToolbarFactory $fieldTypeToolbarFactory
FieldTypeToolbarFactory $fieldTypeToolbarFactory,
MetaFieldDefinitionServiceInterface $metaFieldDefinitionService
) {
$this->notificationHandler = $notificationHandler;
$this->translator = $translator;
Expand All @@ -111,6 +115,7 @@ public function __construct(
$this->contentTypeDraftMapper = $contentTypeDraftMapper;
$this->configResolver = $configResolver;
$this->fieldTypeToolbarFactory = $fieldTypeToolbarFactory;
$this->metaFieldDefinitionService = $metaFieldDefinitionService;
}

/**
Expand Down Expand Up @@ -183,13 +188,17 @@ public function listAction(ContentTypeGroup $group, string $routeName, int $page
public function addAction(ContentTypeGroup $group)
{
$this->denyAccessUnlessGranted(new Attribute('class', 'create'));
$languages = $this->configResolver->getParameter('languages');
$mainLanguageCode = reset($languages);
$mainLanguageCode = $this->languageService->getDefaultLanguageCode();

$createStruct = $this->contentTypeService->newContentTypeCreateStruct('__new__' . md5((string)microtime(true)));
$createStruct->mainLanguageCode = $mainLanguageCode;
$createStruct->names = [$mainLanguageCode => 'New Content Type'];

$this->metaFieldDefinitionService->addMetaFieldDefinitions(
$createStruct,
$this->languageService->loadLanguage($mainLanguageCode)
);

try {
$contentTypeDraft = $this->contentTypeService->createContentType($createStruct, [$group]);
} catch (NotFoundException $e) {
Expand Down Expand Up @@ -375,8 +384,10 @@ public function editAction(Request $request, ContentTypeGroup $group, ContentTyp
null,
['contentType' => $contentType]
);
$form->handleRequest($request);

$this->metaFieldDefinitionService->addMetaFieldDefinitions($contentTypeDraft);

$form->handleRequest($request);
if ($form->isSubmitted()) {
$result = $this->submitHandler->handle($form, function (ContentTypeEditData $data) use ($contentTypeDraft) {
$contentTypeGroup = $data->getContentTypeGroup();
Expand Down Expand Up @@ -719,6 +730,7 @@ public function createUpdateForm(
Language $language = null,
?Language $baseLanguage = null
): FormInterface {
$this->metaFieldDefinitionService->addMetaFieldDefinitions($contentTypeDraft, $language);
$contentTypeData = $this->contentTypeDraftMapper->mapToFormData(
$contentTypeDraft,
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class AdminUiForms extends AbstractParser
{
public const FORM_TEMPLATES_PARAM = 'admin_ui_forms.content_edit_form_templates';
public const FIELD_TYPES_PARAM = 'admin_ui_forms.content_edit.fieldtypes';
public const CONTENT_TYPE_FIELD_TYPES_PARAM = 'admin_ui_forms.content_type_edit.field_types';
public const CONTENT_TYPE_DEFAULT_META_FIELD_TYPE_GROUP_PARAM =
'admin_ui_forms.content_type_edit.default_meta_field_type_group';

private const GROUP_NAME_PATTERN = '/^[a-zA-Z0-9_][a-zA-Z0-9_\-:]*$/D';

/**
* Adds semantic configuration definition.
Expand Down Expand Up @@ -84,6 +89,48 @@ public function addSemanticConfig(NodeBuilder $nodeBuilder)
->end()
->end()
->end()
->arrayNode('content_type_edit')
->info('Content Type Edit form configuration')
->children()
->scalarNode('default_meta_field_type_group')
->info('Group name used to add meta field types')
->beforeNormalization()
->ifTrue(
static function (string $groupName): bool {
return
empty($groupName)
|| !preg_match(self::GROUP_NAME_PATTERN, $groupName);
}
)
->thenInvalid('The group name "%s" contains illegal characters. Group names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").')
->end()
->end()
->arrayNode('field_types')
->info('Configuration for specific Field Types')
->useAttributeAsKey('identifier')
->arrayPrototype()
->beforeNormalization()
->ifTrue(
static function (array $config): bool {
$isMeta = $config['meta'] ?? false;

return $isMeta && !isset($config['position']);
}
)
->thenInvalid('The "position" option is required for all Meta Field Types')
->end()
->children()
->scalarNode('identifier')->end()
->booleanNode('meta')
->info('Make this field_type a part of Meta group')
->defaultFalse()
->end()
->integerNode('position')->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end();
}
Expand All @@ -104,20 +151,43 @@ public function mapConfig(
}

if (!empty($scopeSettings['admin_ui_forms']['content_edit']['fieldtypes'])) {
$scopeSettings['admin_ui_forms.content_edit.fieldtypes'] = $scopeSettings['admin_ui_forms']['content_edit']['fieldtypes'];
$scopeSettings['admin_ui_forms.content_edit.fieldtypes'] =
$scopeSettings['admin_ui_forms']['content_edit']['fieldtypes'];
unset($scopeSettings['admin_ui_forms']['content_edit']['fieldtypes']);
}

if (!empty($scopeSettings['admin_ui_forms']['content_type_edit']['field_types'])) {
$scopeSettings['admin_ui_forms.content_type_edit.field_types'] =
$scopeSettings['admin_ui_forms']['content_type_edit']['field_types'];
unset($scopeSettings['admin_ui_forms']['content_type_edit']['field_types']);
}

if (!empty($scopeSettings['admin_ui_forms']['content_type_edit']['default_meta_field_type_group'])) {
$scopeSettings['admin_ui_forms.content_type_edit.default_meta_field_type_group'] =
$scopeSettings['admin_ui_forms']['content_type_edit']['default_meta_field_type_group'];
unset($scopeSettings['admin_ui_forms']['content_type_edit']['default_meta_field_type_group']);
}

$contextualizer->setContextualParameter(
static::FORM_TEMPLATES_PARAM,
self::FORM_TEMPLATES_PARAM,
$currentScope,
$scopeSettings['admin_ui_forms.content_edit_form_templates'] ?? []
);
$contextualizer->setContextualParameter(
static::FIELD_TYPES_PARAM,
self::FIELD_TYPES_PARAM,
$currentScope,
$scopeSettings['admin_ui_forms.content_edit.fieldtypes'] ?? []
);
$contextualizer->setContextualParameter(
self::CONTENT_TYPE_FIELD_TYPES_PARAM,
$currentScope,
$scopeSettings['admin_ui_forms.content_type_edit.field_types'] ?? []
);
$contextualizer->setContextualParameter(
self::CONTENT_TYPE_DEFAULT_META_FIELD_TYPE_GROUP_PARAM,
$currentScope,
$scopeSettings['admin_ui_forms.content_type_edit.default_meta_field_type_group'] ?? null
);
}

/**
Expand All @@ -127,6 +197,8 @@ public function postMap(array $config, ContextualizerInterface $contextualizer)
{
$contextualizer->mapConfigArray('admin_ui_forms.content_edit_form_templates', $config);
$contextualizer->mapConfigArray('admin_ui_forms.content_edit.fieldtypes', $config);
$contextualizer->mapConfigArray('admin_ui_forms.content_type_edit.field_types', $config);
$contextualizer->mapSetting('admin_ui_forms.content_type_edit.default_meta_field_type_group', $config);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
imports:
- { resource: services/service_aliases.yaml }
- { resource: services/config.yaml }
- { resource: services/controllers.yaml }
- { resource: services/tabs.yaml }
- { resource: services/menu.yaml }
Expand All @@ -12,6 +13,7 @@ imports:
- { resource: services/modules/field_type_toolbar.yaml }
- { resource: services/form_processors.yaml }
- { resource: services/validators.yaml }
- { resource: services/services.yaml }
- { resource: services/siteaccess.yaml }
- { resource: services/universal_discovery_widget.yaml }
- { resource: services/utils.yaml }
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Resources/config/services/components.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
imports:
- { resource: services/components/content/edit.yaml }
- { resource: services/components/content_type/edit.yaml }

services:
_defaults:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
_defaults:
public: false
autowire: true
autoconfigure: true

Ibexa\AdminUi\Component\ContentType\ContentTypeEditMetaFieldsComponent:
tags:
- { name: ibexa.admin_ui.component, group: 'content-type-edit-sections' }
10 changes: 10 additions & 0 deletions src/bundle/Resources/config/services/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
_defaults:
autoconfigure: true
autowire: true
public: false

Ibexa\AdminUi\Config\AdminUiForms\ContentTypeFieldTypesResolver: ~

Ibexa\AdminUi\Config\AdminUiForms\ContentTypeFieldTypesResolverInterface:
'@Ibexa\AdminUi\Config\AdminUiForms\ContentTypeFieldTypesResolver'
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/services/menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ services:
tags:
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content_type_edit.sidebar_right }

Ibexa\AdminUi\Menu\ContentTypeEditAnchorMenuBuilder:
public: true
tags:
- { name: knp_menu.menu_builder, method: build, alias: ibexa.admin_ui.menu.content_type_edit.anchor_menu }

Ibexa\AdminUi\Menu\URLEditRightSidebarBuilder:
public: true
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ services:

Ibexa\AdminUi\UI\Module\FieldTypeToolbar\FieldTypeToolbarFactory:
arguments:
- '@Ibexa\AdminUi\Config\AdminUiForms\ContentTypeFieldTypesResolverInterface'
- '@Ibexa\Core\FieldType\FieldTypeRegistry'
- '@translator'
10 changes: 10 additions & 0 deletions src/bundle/Resources/config/services/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Ibexa\AdminUi\Service\MetaFieldType\MetaFieldDefinitionService: ~

Ibexa\AdminUi\Service\MetaFieldType\MetaFieldDefinitionServiceInterface:
'@Ibexa\AdminUi\Service\MetaFieldType\MetaFieldDefinitionService'
6 changes: 3 additions & 3 deletions src/bundle/Resources/public/scss/_anchor-navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
}

&__section-groups {
min-width: calculateRem(350px);
max-width: calculateRem(400px);
width: 25vw;
min-width: calculateRem(280px);
max-width: calculateRem(420px);
width: calc(25vw - #{calculateRem(50px)});
height: calculateRem(48px);

&--list {
Expand Down
19 changes: 18 additions & 1 deletion src/bundle/Resources/public/scss/_content-type-edit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,27 @@
padding: 0;
}

.ibexa-edit-content__container--meta {
margin-top: calculateRem(-40px);

.ibexa-content-type-edit {
&__section-column-header {
border-top: 1px solid $ibexa-color-light;
padding-top: calculateRem(16px);
margin-top: calculateRem(40px);
}

&__section,
&__section-column {
margin-bottom: 0;
}
}
}

&__section {
display: flex;
flex-wrap: wrap;
margin: 0 0 calculateRem(50px) 0;
margin: 0 0 calculateRem(32px) 0;

&--one-column-layout {
.ibexa-content-type-edit__section-column {
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/public/scss/_main-container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
}

&.ibexa-main-container {
&--with-anchor-menu-items {
.ibexa-main-container {
&__side-column {
min-width: calculateRem(330px);
max-width: calculateRem(470px);
width: 25vw;
}
}
}

&--no-border {
padding: 0;

Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/content_type.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@
<target state="new">Description</target>
<note>key: field_definition.description</note>
</trans-unit>
<trans-unit id="83622f13aaf2bf484e7c92ced0b65d2e392a157d" resname="field_definition.enabled">
<source>Enabled</source>
<target state="new">Enabled</target>
<note>key: field_definition.enabled</note>
</trans-unit>
<trans-unit id="60b0ee9222a502c38adf1be704d4984564190e8e" resname="field_definition.ezauthor.default_author">
<source>Default value</source>
<target state="new">Default value</target>
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/translations/menu.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@
<target state="new">Create</target>
<note>key: content_type_create__sidebar_right__save</note>
</trans-unit>
<trans-unit id="ca09d2e9bfc8aa93d6b4c4f3c7d38f37976d7038" resname="content_type_edit__anchor_menu__field_definitions">
<source>Field definitions</source>
<target state="new">Field definitions</target>
<note>key: content_type_edit__anchor_menu__field_definitions</note>
</trans-unit>
<trans-unit id="e39ae19f3f6be47b23321398f5d499bf78f9fc7c" resname="content_type_edit__anchor_menu__global_properties">
<source>Global properties</source>
<target state="new">Global properties</target>
<note>key: content_type_edit__anchor_menu__global_properties</note>
</trans-unit>
<trans-unit id="17d86a1011976758251b804acfbe8092d2860946" resname="content_type_edit__sidebar_right__cancel">
<source>Discard changes</source>
<target state="new">Discard changes</target>
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/translations/messages.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@
<target state="new">Search...</target>
<note>key: content_type.view.edit.search</note>
</trans-unit>
<trans-unit id="6cf3d774e8b9e13d11f9f7525f1a6eaa6a892320" resname="content_type.view.edit.seo">
<source>SEO</source>
<target state="new">SEO</target>
<note>key: content_type.view.edit.seo</note>
</trans-unit>
<trans-unit id="803a61fc8cf4e7bdfcf27432bb35e379a4971134" resname="content_type.view.list.action.add">
<source>Add new</source>
<target state="new">Add new</target>
Expand Down Expand Up @@ -538,6 +543,11 @@
<target state="new">I understand the consequences of this action.</target>
<note>key: location_trash_form.confirm_label</note>
</trans-unit>
<trans-unit id="8c2261eecf1e143eaf524c34f4f89608929c5c81" resname="meta.enabled">
<source>Enable %type% for this content type</source>
<target state="new">Enable %type% for this content type</target>
<note>key: meta.enabled</note>
</trans-unit>
<trans-unit id="7fe072f41348fb097b6bb018eec4f1b1bc9cffc3" resname="modal.cancel">
<source>Cancel</source>
<target state="new">Cancel</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends '@ibexadesign/ui/component/anchor_navigation/section_group.html.twig' %}

{% set data_id = 'ibexa-edit-content-type-sections-meta' %}

{% block sections %}{% endblock %}
Loading

0 comments on commit 0136b6e

Please sign in to comment.