Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-4675: Improved autogenerate field definition name #1117

Open
wants to merge 1 commit into
base: 4.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ parameters:
count: 1
path: src/bundle/Controller/ContentViewController.php

-
message: "#^Parameter \\#1 \\$fieldTypeIdentifier of method Ibexa\\\\Bundle\\\\AdminUi\\\\Controller\\\\FieldDefinitionController\\:\\:getFieldTypeLabel\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/bundle/Controller/FieldDefinitionController.php

-
message: "#^Parameter \\#2 \\$fieldDefinition of method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\ContentTypeService\\:\\:updateFieldDefinition\\(\\) expects Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinition, Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinition\\|null given\\.$#"
count: 1
Expand Down
37 changes: 30 additions & 7 deletions src/bundle/Controller/FieldDefinitionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@
use Ibexa\Rest\Message;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Values;
use JMS\TranslationBundle\Annotation\Ignore;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

final class FieldDefinitionController extends RestController
{
/** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
private $contentTypeService;
private ContentTypeService $contentTypeService;

/** @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface */
private $urlGenerator;
private UrlGeneratorInterface $urlGenerator;

public function __construct(ContentTypeService $contentTypeService, UrlGeneratorInterface $urlGenerator)
{
private TranslatorInterface $translator;

public function __construct(
ContentTypeService $contentTypeService,
UrlGeneratorInterface $urlGenerator,
TranslatorInterface $translator
) {
$this->contentTypeService = $contentTypeService;
$this->urlGenerator = $urlGenerator;
$this->translator = $translator;
}

public function addFieldDefinitionAction(
Expand All @@ -59,7 +65,9 @@ public function addFieldDefinitionAction(

$fieldDefinitionCreateStruct->fieldGroup = $input->fieldGroupIdentifier;
$fieldDefinitionCreateStruct->names = [
$language->languageCode => 'New field type',
$language->languageCode => strtr('New %name%', [
'%name%' => $this->getFieldTypeLabel($input->fieldTypeIdentifier),
]),
];

$fieldDefinitionCreateStruct->position = $input->position ?? $this->getNextFieldPosition($contentTypeDraft);
Expand Down Expand Up @@ -167,4 +175,19 @@ private function getNextFieldPosition(ContentType $contentType): int

return 0;
}

/**
* Generate a human-readable name for field type identifier.
*/
private function getFieldTypeLabel(string $fieldTypeIdentifier): string
{
$name = $this->translator->trans(
/** @Ignore */
$fieldTypeIdentifier . '.name',
[],
'ibexa_fieldtypes'
);

return mb_strtolower($name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@
const targetContainerGroup = targetContainer.closest('.ibexa-collapse--field-definitions-group');
const targetContainerList = targetContainerGroup.closest('.ibexa-content-type-edit__field-definitions-group-list');
const fieldTemplate = targetContainerList.dataset.template;
const fieldRendered = fieldTemplate.replace('{{ type }}', currentDraggedItem.dataset.itemIdentifier);
const fieldRendered = fieldTemplate
.replace('{{ name }}', currentDraggedItem.dataset.itemName.toLowerCase())
.replace('{{ type }}', currentDraggedItem.dataset.itemIdentifier);
let draggedItemPosition = [...dragContainerItems].findIndex((item, index, array) => {
return item.classList.contains('ibexa-field-definitions-placeholder') && index < array.length - 1;
});
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Resources/translations/ibexa_content_type.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@
<note>key: content_type.view.edit.content_field_definitions</note>
</trans-unit>
<trans-unit id="74aead78c735bbbce032dc9b00f9ca7a3632f166" resname="content_type.view.edit.default_header">
<source>New field type</source>
<target state="new">New field type</target>
<source>New {{ name }} ({{ type }})</source>
<target state="new">New {{ name }} ({{ type }})</target>
<note>key: content_type.view.edit.default_header</note>
</trans-unit>
<trans-unit id="a32a5e3d2d67da43b4c5f0f5574c90520868b36a" resname="content_type.view.edit.global_properties">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{% for item in field_type_toolbar %}
<li
class="ibexa-available-field-type {{ is_draggable is defined and is_draggable == false ? 'ibexa-available-field-type--immovable' }}"
data-item-name="{{ item.name }}"
data-item-identifier="{{ item.identifier }}"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'is_draggable': true,
'class': 'ibexa-collapse--field-definition ibexa-collapse--field-definition-highlight ibexa-collapse--field-definition-loading',
'body_id': 'loading-collapse',
'header_label': 'content_type.view.edit.default_header'|trans|desc('New field type') ~ ' ({{ type }})',
'header_label': 'content_type.view.edit.default_header'|trans|desc('New {{ name }} ({{ type }})'),
'data_attr': {
'data-field-definition-identifier': 'loading-collapse',
},
Expand Down
Loading