Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Aug 31, 2023
1 parent bdffeae commit 7abdf55
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/contracts/Event/NameSchema/AbstractSchemaEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
abstract class AbstractSchemaEvent extends Event
{
/** @var array<string, array> */
protected array $schemaIdentifiers;
private array $schemaIdentifiers;

/** @var array<string, array<string>> */
protected array $tokenValues = [];
private array $tokenValues = [];

public function __construct(array $schemaIdentifiers)
{
$this->schemaIdentifiers = $schemaIdentifiers;
}

public function getTokenValues(): array
final public function getTokenValues(): array
{
return $this->tokenValues;
}

public function setTokenValues(array $names): void
final public function setTokenValues(array $names): void
{
$this->tokenValues = $names;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

final class ResolveContentNameSchemaEvent extends AbstractNameSchemaEvent implements ContentAwareEventInterface
{
protected Content $content;
private Content $content;

public function __construct(
Content $content,
Expand Down
64 changes: 30 additions & 34 deletions src/lib/Repository/Helper/NameSchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ protected function mergeFieldMap(Content $content, array $fieldMap, array $langu

foreach ($content->fields as $fieldIdentifier => $fieldLanguageMap) {
foreach ($languageCodes as $languageCode) {
$mergedFieldMap[$fieldIdentifier][$languageCode] = isset($fieldMap[$fieldIdentifier][$languageCode])
? $fieldMap[$fieldIdentifier][$languageCode]
: $fieldLanguageMap[$languageCode];
$mergedFieldMap[$fieldIdentifier][$languageCode] = $fieldMap[$fieldIdentifier][$languageCode] ?? $fieldLanguageMap[$languageCode];
}
}

Expand All @@ -152,40 +150,38 @@ protected function getFieldTitles(array $schemaIdentifiers, $contentType, array
$fieldTitles = [];

foreach ($schemaIdentifiers as $fieldDefinitionIdentifier) {
if (isset($fieldMap[$fieldDefinitionIdentifier][$languageCode])) {
if ($contentType instanceof SPIContentType) {
$fieldDefinition = null;
foreach ($contentType->fieldDefinitions as $spiFieldDefinition) {
if ($spiFieldDefinition->identifier === $fieldDefinitionIdentifier) {
$fieldDefinition = $this->contentTypeDomainMapper->buildFieldDefinitionDomainObject(
$spiFieldDefinition,
// This is probably not main language, but as we don't expose it, it's ok for now.
$languageCode
);
break;
}
}

if ($fieldDefinition === null) {
$fieldTitles[$fieldDefinitionIdentifier] = '';
continue;
if (!isset($fieldMap[$fieldDefinitionIdentifier][$languageCode])) {
continue;
}
if ($contentType instanceof SPIContentType) {
$fieldDefinition = null;
foreach ($contentType->fieldDefinitions as $spiFieldDefinition) {
if ($spiFieldDefinition->identifier === $fieldDefinitionIdentifier) {
$fieldDefinition = $this->contentTypeDomainMapper->buildFieldDefinitionDomainObject(
$spiFieldDefinition,
// This is probably not main language, but as we don't expose it, it's ok for now.
$languageCode
);
break;
}
} elseif ($contentType instanceof ContentType) {
$fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier);
} else {
throw new InvalidArgumentType('$contentType', 'API or SPI variant of a Content Type');
}

$fieldTypeService = $this->fieldTypeRegistry->getFieldType(
$fieldDefinition->fieldTypeIdentifier
);

$fieldTitles[$fieldDefinitionIdentifier] = $fieldTypeService->getName(
$fieldMap[$fieldDefinitionIdentifier][$languageCode],
$fieldDefinition,
$languageCode
);
if ($fieldDefinition === null) {
$fieldTitles[$fieldDefinitionIdentifier] = '';
continue;
}
} elseif ($contentType instanceof ContentType) {
$fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier);
} else {
throw new InvalidArgumentType('$contentType', 'API or SPI variant of a Content Type');
}
$fieldTypeService = $this->fieldTypeRegistry->getFieldType(
$fieldDefinition->fieldTypeIdentifier
);
$fieldTitles[$fieldDefinitionIdentifier] = $fieldTypeService->getName(
$fieldMap[$fieldDefinitionIdentifier][$languageCode],
$fieldDefinition,
$languageCode
);
}

return $fieldTitles;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Repository/NameSchema/NameSchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class NameSchemaService implements NameSchemaServiceInterface
*/
protected array $settings;

protected EventDispatcherInterface $eventDispatcher;
private EventDispatcherInterface $eventDispatcher;

protected SchemaIdentifierExtractorInterface $schemaIdentifierExtractor;
private SchemaIdentifierExtractorInterface $schemaIdentifierExtractor;

/**
* @param array{limit?: integer, sequence?: string} $settings
Expand Down

0 comments on commit 7abdf55

Please sign in to comment.