1111use Ibexa \ContentForms \Data \Content \ContentUpdateData ;
1212use Ibexa \ContentForms \Data \Mapper \ContentUpdateMapper ;
1313use Ibexa \ContentForms \Form \Type \Content \ContentEditType ;
14+ use Ibexa \Contracts \ContentForms \Event \AutosaveEnabled ;
1415use Ibexa \Contracts \Core \Repository \ContentService ;
1516use Ibexa \Contracts \Core \Repository \ContentTypeService ;
1617use Ibexa \Contracts \Core \Repository \Exceptions \NotFoundException ;
2425use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
2526use Symfony \Component \Form \FormFactoryInterface ;
2627use Symfony \Component \Form \FormInterface ;
28+ use Symfony \Contracts \EventDispatcher \EventDispatcherInterface ;
2729
2830class ContentEditViewFilter implements EventSubscriberInterface
2931{
30- /** @var \Ibexa\Contracts\Core\Repository\ContentService */
31- private $ contentService ;
32+ private ContentService $ contentService ;
3233
33- /** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
34- private $ contentTypeService ;
34+ private ContentTypeService $ contentTypeService ;
3535
36- /** @var \Symfony\Component\Form\FormFactoryInterface */
37- private $ formFactory ;
36+ private FormFactoryInterface $ formFactory ;
3837
39- /** @var \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface */
40- private $ languagePreferenceProvider ;
38+ private UserLanguagePreferenceProviderInterface $ languagePreferenceProvider ;
4139
4240 private LocationService $ locationService ;
4341
44- /**
45- * @param \Ibexa\Contracts\Core\Repository\ContentService $contentService
46- * @param \Ibexa\Contracts\Core\Repository\ContentTypeService $contentTypeService
47- * @param \Symfony\Component\Form\FormFactoryInterface $formFactory
48- * @param \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface $languagePreferenceProvider
49- */
42+ private EventDispatcherInterface $ eventDispatcher ;
43+
5044 public function __construct (
5145 ContentService $ contentService ,
5246 LocationService $ locationService ,
5347 ContentTypeService $ contentTypeService ,
5448 FormFactoryInterface $ formFactory ,
55- UserLanguagePreferenceProviderInterface $ languagePreferenceProvider
49+ UserLanguagePreferenceProviderInterface $ languagePreferenceProvider ,
50+ EventDispatcherInterface $ eventDispatcher
5651 ) {
5752 $ this ->contentService = $ contentService ;
5853 $ this ->contentTypeService = $ contentTypeService ;
5954 $ this ->formFactory = $ formFactory ;
6055 $ this ->languagePreferenceProvider = $ languagePreferenceProvider ;
6156 $ this ->locationService = $ locationService ;
57+ $ this ->eventDispatcher = $ eventDispatcher ;
6258 }
6359
6460 public static function getSubscribedEvents ()
@@ -111,11 +107,14 @@ public function handleContentEditForm(FilterViewBuilderParametersEvent $event)
111107 $ contentType ,
112108 $ currentFields
113109 );
110+
111+ $ autosaveEnabled = $ this ->eventDispatcher ->dispatch (new AutosaveEnabled ($ contentDraft ->getVersionInfo ()))->isAutosaveEnabled ();
114112 $ form = $ this ->resolveContentEditForm (
115113 $ contentUpdate ,
116114 $ languageCode ,
117115 $ contentDraft ,
118- $ location ?? null
116+ $ location ?? null ,
117+ $ autosaveEnabled
119118 );
120119
121120 $ event ->getParameters ()->add ([
@@ -153,7 +152,8 @@ private function resolveContentEditForm(
153152 ContentUpdateData $ contentUpdate ,
154153 string $ languageCode ,
155154 Content $ content ,
156- ?Location $ location = null
155+ ?Location $ location = null ,
156+ bool $ autosaveEnabled = true
157157 ): FormInterface {
158158 return $ this ->formFactory ->create (
159159 ContentEditType::class,
@@ -165,6 +165,7 @@ private function resolveContentEditForm(
165165 'content ' => $ content ,
166166 'contentUpdateStruct ' => $ contentUpdate ,
167167 'drafts_enabled ' => true ,
168+ 'autosave_enabled ' => $ autosaveEnabled ,
168169 ]
169170 );
170171 }
0 commit comments