Skip to content

Commit 363ae44

Browse files
authored
add new document adapter interface (#1498)
1 parent ddf74f1 commit 363ae44

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

doc/10_Extending_Studio/03_Documents/01_Document_types.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ Important interfaces:
226226
- `Pimcore\Bundle\StudioBackendBundle\Document\Data\SetterDataInterface` - The mandatory interface that must be implemented by the adapter.
227227
- `Pimcore\Bundle\StudioBackendBundle\Document\Data\EditableDataNormalizerInterface` - The interface that needs to be implemented if the adapter should be able to normalize editable data.
228228
- `Pimcore\Bundle\StudioBackendBundle\Document\Data\SettingsNormalizerInterface` - The interface that needs to be implemented if the adapter should be able to normalize document settings data.
229+
- `Pimcore\Bundle\StudioBackendBundle\Document\Data\SetInitialDataInterface` - Marker interface that needs to be implemented by the adapter if it there is a need to adapt this initial data on document creation.
229230
- `Pimcore\Bundle\StudioBackendBundle\Document\Data\Model\EditableDataInterface` - Marker interface that needs to be implemented by custom editable data model. This interface is returned by the `normalizeEditableData` method of the `EditableNormalizerInterface`.
230231
- `Pimcore\Bundle\StudioBackendBundle\Document\Data\Model\SettingsDataInterface` - Marker interface that needs to be implemented by custom settings data model. This interface is returned by the `normalizeSettings` method of the `SettingsNormalizerInterface`.
231232

232-
Important data keys:
233+
- Important data keys:
233234
- `editableData` - The key for the detail data of the document (e.g., editable fields of your document).
234235
- `settingsData` - The key for the document settings data (e.g., document settings like title, description, prettyUrl).
235236

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Document\Data;
15+
16+
use Pimcore\Model\Document;
17+
use Pimcore\Model\UserInterface;
18+
19+
interface SetInitialDataInterface
20+
{
21+
public function setInitialData(Document $document, array $data, UserInterface $user): void;
22+
}

src/Document/Service/CreateService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Pimcore\Bundle\StaticResolverBundle\Models\Document\DocTypeResolverInterface;
1818
use Pimcore\Bundle\StaticResolverBundle\Models\Document\DocumentResolverInterface;
1919
use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface;
20+
use Pimcore\Bundle\StudioBackendBundle\Document\Data\SetInitialDataInterface;
2021
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\DocumentAddParameters;
2122
use Pimcore\Bundle\StudioBackendBundle\Document\Util\Trait\DocumentClassTrait;
2223
use Pimcore\Bundle\StudioBackendBundle\Element\Service\ElementSaveServiceInterface;
@@ -47,6 +48,7 @@
4748
public function __construct(
4849
private DocumentResolverInterface $documentResolver,
4950
private DocTypeResolverInterface $docTypeResolver,
51+
private DocumentTypeServiceInterface $documentTypeService,
5052
private ElementSaveServiceInterface $elementSaveService,
5153
private ResolverInterface $classResolver,
5254
private ServiceResolverInterface $serviceResolver,
@@ -72,6 +74,11 @@ public function createDocument(Document $parent, DocumentAddParameters $paramete
7274
$this->addLanguageProperty($document, $baseTranslationDocument, $parameters->getLanguage());
7375
}
7476

77+
$adapter = $this->documentTypeService->tryTypeAdapter($document->getType());
78+
if ($adapter instanceof SetInitialDataInterface) {
79+
$adapter->setInitialData($document, $data, $user);
80+
}
81+
7582
try {
7683
$this->elementSaveService->save($document, $user);
7784
} catch (Exception $e) {

0 commit comments

Comments
 (0)