Skip to content
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
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11687,12 +11687,6 @@ parameters:
count: 1
path: src/lib/Service/ContentTypeService.php

-
message: '#^Access to an undefined property Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject\:\:\$fieldDefinitions\.$#'
identifier: property.notFound
count: 1
path: src/lib/Service/MetaFieldType/MetaFieldDefinitionService.php

-
message: '#^Access to an undefined property Ibexa\\Contracts\\Core\\Repository\\Values\\User\\Policy\:\:\$originalId\.$#'
identifier: property.notFound
Expand Down
26 changes: 23 additions & 3 deletions src/lib/Service/MetaFieldType/MetaFieldDefinitionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
use Ibexa\AdminUi\Config\AdminUiForms\ContentTypeFieldTypesResolverInterface;
use Ibexa\Bundle\AdminUi\DependencyInjection\Configuration\Parser\AdminUiForms;
use Ibexa\Contracts\Core\Repository\ContentTypeService;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\FieldTypeService;
use Ibexa\Contracts\Core\Repository\LanguageService;
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeCreateStruct;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeDraft;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
use Ibexa\Contracts\Core\Repository\Values\ValueObject;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\Core\Base\Exceptions\NotFound\FieldTypeNotFoundException;
use Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList;
use Ibexa\Core\MVC\Symfony\Locale\LocaleConverterInterface;
use JMS\TranslationBundle\Annotation\Ignore;
Expand All @@ -34,6 +37,8 @@

private ContentTypeService $contentTypeService;

private FieldTypeService $fieldTypeService;

private FieldsGroupsList $fieldsGroupsList;

private LanguageService $languageService;
Expand All @@ -42,24 +47,29 @@

private TranslatorInterface $translator;

public function __construct(
ConfigResolverInterface $configResolver,
ContentTypeFieldTypesResolverInterface $contentTypeFieldTypesResolver,
ContentTypeService $contentTypeService,
FieldTypeService $fieldTypeService,
FieldsGroupsList $fieldsGroupsList,
LanguageService $languageService,
LocaleConverterInterface $localeConverter,
TranslatorInterface $translator
) {

Check warning on line 59 in src/lib/Service/MetaFieldType/MetaFieldDefinitionService.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function has 8 parameters, which is greater than the 7 authorized.

See more on https://sonarcloud.io/project/issues?id=ibexa_admin-ui&issues=AaBnLRlAhHT77rhMGmq-&open=AaBnLRlAhHT77rhMGmq-&pullRequest=2060
$this->configResolver = $configResolver;
$this->contentTypeFieldTypesResolver = $contentTypeFieldTypesResolver;
$this->contentTypeService = $contentTypeService;
$this->fieldTypeService = $fieldTypeService;
$this->fieldsGroupsList = $fieldsGroupsList;
$this->languageService = $languageService;
$this->localeConverter = $localeConverter;
$this->translator = $translator;
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeCreateStruct|\Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeDraft $contentType
*/
public function addMetaFieldDefinitions(ValueObject $contentType, ?Language $language = null): void
{
$metaFieldTypes = $this->contentTypeFieldTypesResolver->getMetaFieldTypes();
Expand All @@ -70,8 +80,15 @@

foreach ($metaFieldTypes as $metaFieldTypeIdentifier => $metaFieldTypeSettings) {
$fieldGroup = $this->getDefaultMetaDataFieldTypeGroup() ?? $this->fieldsGroupsList->getDefaultGroup();
try {
$isSingular = $this->fieldTypeService->getFieldType($metaFieldTypeIdentifier)->isSingular();
} catch (NotFoundException|FieldTypeNotFoundException $e) {
continue;
}

$fieldTypeGroup = $isSingular === true ? null : $fieldGroup;
Comment thread
konradoboza marked this conversation as resolved.

if ($this->metaFieldDefinitionExists($metaFieldTypeIdentifier, $fieldGroup, $contentType)) {
if ($this->metaFieldDefinitionExists($metaFieldTypeIdentifier, $fieldTypeGroup, $contentType)) {
continue;
}

Expand Down Expand Up @@ -120,15 +137,18 @@
return $fieldDefinitionCreateStruct;
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeCreateStruct|\Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeDraft $contentType
*/
public function metaFieldDefinitionExists(
string $fieldTypeIdentifier,
string $fieldTypeGroup,
?string $fieldTypeGroup,
ValueObject $contentType
): bool {
foreach ($contentType->fieldDefinitions as $fieldDefinition) {
if (
$fieldDefinition->fieldTypeIdentifier === $fieldTypeIdentifier
&& $fieldDefinition->fieldGroup === $fieldTypeGroup
&& ($fieldTypeGroup === null || $fieldDefinition->fieldGroup === $fieldTypeGroup)
) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
interface MetaFieldDefinitionServiceInterface
{
/**
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeCreateStruct|\Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeDraft $contentType
*/
public function addMetaFieldDefinitions(
ValueObject $contentType,
?Language $language = null
Expand All @@ -29,9 +32,12 @@ public function createMetaFieldDefinitionCreateStruct(
int $position
): FieldDefinitionCreateStruct;

/**
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeCreateStruct|\Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeDraft $contentType
*/
public function metaFieldDefinitionExists(
string $fieldTypeIdentifier,
string $fieldTypeGroup,
?string $fieldTypeGroup,
ValueObject $contentType
): bool;

Expand Down
Loading
Loading