Skip to content

Commit

Permalink
EZP-31597: Handled missing Content Types when generating Schema (#82)
Browse files Browse the repository at this point in the history
* Handled missing Content Types when generating Schema

* Changed type-hint to rely on API Exception and aligned code style

Co-authored-by: Andrew Longosz <[email protected]>
  • Loading branch information
SerheyDolgushev and alongosz authored Apr 24, 2020
1 parent 85c9ac4 commit 99e0cb8
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Mapper\FieldDefinition;

use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
use EzSystems\EzPlatformGraphQL\Schema\Domain\Content\NameHelper;

Expand Down Expand Up @@ -39,11 +40,16 @@ public function mapToFieldValueType(FieldDefinition $fieldDefinition): ?string
}
$settings = $fieldDefinition->getFieldSettings();

$type = 'DomainContent';
if (count($settings['selectionContentTypes']) === 1) {
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($settings['selectionContentTypes'][0]);
$type = $this->nameHelper->domainContentName($contentType);
} else {
$type = 'DomainContent';
try {
$contentType = $this->contentTypeService->loadContentTypeByIdentifier(
$settings['selectionContentTypes'][0]
);
$type = $this->nameHelper->domainContentName($contentType);
} catch (NotFoundException $e) {
// Nothing to do
}
}

if ($this->isMultiple($fieldDefinition)) {
Expand Down

0 comments on commit 99e0cb8

Please sign in to comment.