Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Aug 3, 2023
2 parents 411c90f + 88e3ab8 commit d00f8cd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bundle/Resources/config/services/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ services:
arguments:
- "@ibexa.api.repository"
- "@netgen.ibexa_site_api.load_service"
- "@netgen_layouts.error.handler"

netgen_layouts.ibexa_site_api.parameters.value_object_provider.content:
class: Netgen\Layouts\Ibexa\SiteApi\Parameters\ValueObjectProvider\ContentProvider
decorates: netgen_layouts.ibexa.parameters.value_object_provider.content
arguments:
- "@ibexa.api.repository"
- "@netgen.ibexa_site_api.load_service"
- "@netgen_layouts.error.handler"
12 changes: 9 additions & 3 deletions lib/Parameters/ValueObjectProvider/ContentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
use Ibexa\Contracts\Core\Repository\Repository;
use Netgen\IbexaSiteApi\API\LoadService;
use Netgen\IbexaSiteApi\API\Values\Content;
use Netgen\Layouts\Error\ErrorHandlerInterface;
use Netgen\Layouts\Parameters\ValueObjectProviderInterface;

final class ContentProvider implements ValueObjectProviderInterface
{
public function __construct(private Repository $repository, private LoadService $loadService)
{
public function __construct(
private Repository $repository,
private LoadService $loadService,
private ErrorHandlerInterface $errorHandler,
) {
}

public function getValueObject(mixed $value): ?Content
Expand All @@ -24,7 +28,9 @@ public function getValueObject(mixed $value): ?Content
);

return $content->contentInfo->mainLocationId !== null ? $content : null;
} catch (NotFoundException) {
} catch (NotFoundException $e) {
$this->errorHandler->handleError($e);

return null;
}
}
Expand Down
12 changes: 9 additions & 3 deletions lib/Parameters/ValueObjectProvider/LocationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
use Ibexa\Contracts\Core\Repository\Repository;
use Netgen\IbexaSiteApi\API\LoadService;
use Netgen\IbexaSiteApi\API\Values\Location;
use Netgen\Layouts\Error\ErrorHandlerInterface;
use Netgen\Layouts\Parameters\ValueObjectProviderInterface;

final class LocationProvider implements ValueObjectProviderInterface
{
public function __construct(private Repository $repository, private LoadService $loadService)
{
public function __construct(
private Repository $repository,
private LoadService $loadService,
private ErrorHandlerInterface $errorHandler,
) {
}

public function getValueObject(mixed $value): ?Location
Expand All @@ -22,7 +26,9 @@ public function getValueObject(mixed $value): ?Location
return $this->repository->sudo(
fn (): Location => $this->loadService->loadLocation((int) $value),
);
} catch (NotFoundException) {
} catch (NotFoundException $e) {
$this->errorHandler->handleError($e);

return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Core\Base\Exceptions\NotFoundException;
use Netgen\IbexaSiteApi\API\LoadService;
use Netgen\Layouts\Error\ErrorHandlerInterface;
use Netgen\Layouts\Ibexa\SiteApi\Parameters\ValueObjectProvider\ContentProvider;
use Netgen\Layouts\Ibexa\SiteApi\Tests\Stubs\Content;
use Netgen\Layouts\Ibexa\SiteApi\Tests\Stubs\ContentInfo;
Expand Down Expand Up @@ -39,6 +40,7 @@ protected function setUp(): void
$this->valueObjectProvider = new ContentProvider(
$this->repositoryMock,
$this->loadServiceMock,
$this->createMock(ErrorHandlerInterface::class),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Core\Base\Exceptions\NotFoundException;
use Netgen\IbexaSiteApi\API\LoadService;
use Netgen\Layouts\Error\ErrorHandlerInterface;
use Netgen\Layouts\Ibexa\SiteApi\Parameters\ValueObjectProvider\LocationProvider;
use Netgen\Layouts\Ibexa\SiteApi\Tests\Stubs\Location;
use Netgen\Layouts\Parameters\ValueObjectProviderInterface;
Expand Down Expand Up @@ -38,6 +39,7 @@ protected function setUp(): void
$this->valueObjectProvider = new LocationProvider(
$this->repositoryMock,
$this->loadServiceMock,
$this->createMock(ErrorHandlerInterface::class),
);
}

Expand Down

0 comments on commit d00f8cd

Please sign in to comment.