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

-
message: '#^Property Ibexa\\ContentForms\\Data\\Content\\ContentUpdateData\:\:\$contentDraft \(Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Content\) in isset\(\) is not nullable\.$#'
identifier: isset.property
count: 1
path: src/lib/FieldType/Mapper/AuthorFormMapper.php

-
message: '#^Method Ibexa\\ContentForms\\FieldType\\Mapper\\BinaryFileFormMapper\:\:mapFieldValueForm\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down
44 changes: 44 additions & 0 deletions src/contracts/Event/AutosaveEnabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\ContentForms\Event;

use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
use Symfony\Contracts\EventDispatcher\Event;

final class AutosaveEnabled extends Event
{
private VersionInfo $versionInfo;

private bool $autosaveEnabled = true;

public function __construct(VersionInfo $versionInfo)
{
$this->versionInfo = $versionInfo;
}

public function getVersionInfo(): VersionInfo
{
return $this->versionInfo;
}

public function isAutosaveEnabled(): bool
{
return $this->autosaveEnabled;
}

public function enableAutosave(): void
{
$this->autosaveEnabled = true;
}

public function disableAutosave(): void
{
$this->autosaveEnabled = false;
}
}
35 changes: 18 additions & 17 deletions src/lib/Content/View/Filter/ContentEditViewFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Ibexa\ContentForms\Data\Content\ContentUpdateData;
use Ibexa\ContentForms\Data\Mapper\ContentUpdateMapper;
use Ibexa\ContentForms\Form\Type\Content\ContentEditType;
use Ibexa\Contracts\ContentForms\Event\AutosaveEnabled;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\ContentTypeService;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
Expand All @@ -24,41 +25,36 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

class ContentEditViewFilter implements EventSubscriberInterface
{
/** @var \Ibexa\Contracts\Core\Repository\ContentService */
private $contentService;
private ContentService $contentService;

/** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
private $contentTypeService;
private ContentTypeService $contentTypeService;

/** @var \Symfony\Component\Form\FormFactoryInterface */
private $formFactory;
private FormFactoryInterface $formFactory;

/** @var \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface */
private $languagePreferenceProvider;
private UserLanguagePreferenceProviderInterface $languagePreferenceProvider;

private LocationService $locationService;

/**
* @param \Ibexa\Contracts\Core\Repository\ContentService $contentService
* @param \Ibexa\Contracts\Core\Repository\ContentTypeService $contentTypeService
* @param \Symfony\Component\Form\FormFactoryInterface $formFactory
* @param \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface $languagePreferenceProvider
*/
private EventDispatcherInterface $eventDispatcher;

public function __construct(
ContentService $contentService,
LocationService $locationService,
ContentTypeService $contentTypeService,
FormFactoryInterface $formFactory,
UserLanguagePreferenceProviderInterface $languagePreferenceProvider
UserLanguagePreferenceProviderInterface $languagePreferenceProvider,
EventDispatcherInterface $eventDispatcher
) {
$this->contentService = $contentService;
$this->contentTypeService = $contentTypeService;
$this->formFactory = $formFactory;
$this->languagePreferenceProvider = $languagePreferenceProvider;
$this->locationService = $locationService;
$this->eventDispatcher = $eventDispatcher;
}

public static function getSubscribedEvents()
Expand Down Expand Up @@ -111,11 +107,14 @@ public function handleContentEditForm(FilterViewBuilderParametersEvent $event)
$contentType,
$currentFields
);

$autosaveEnabled = $this->eventDispatcher->dispatch(new AutosaveEnabled($contentDraft->getVersionInfo()))->isAutosaveEnabled();
$form = $this->resolveContentEditForm(
$contentUpdate,
$languageCode,
$contentDraft,
$location ?? null
$location ?? null,
$autosaveEnabled
);

$event->getParameters()->add([
Expand Down Expand Up @@ -153,7 +152,8 @@ private function resolveContentEditForm(
ContentUpdateData $contentUpdate,
string $languageCode,
Content $content,
?Location $location = null
?Location $location = null,
bool $autosaveEnabled = true
): FormInterface {
return $this->formFactory->create(
ContentEditType::class,
Expand All @@ -165,6 +165,7 @@ private function resolveContentEditForm(
'content' => $content,
'contentUpdateStruct' => $contentUpdate,
'drafts_enabled' => true,
'autosave_enabled' => $autosaveEnabled,
]
);
}
Expand Down
Loading