Skip to content

Commit a083966

Browse files
martineiberlukmzig
andauthored
[Document] [Search] Add title, description and filename (#1337)
* Add titel, description and fielname to Dacumant Grid * Apply php-cs-fixer changes * Remove Private * Update src/Document/Schema/PageSnippet/PageSnippet.php Co-authored-by: Lukas Mzigot <30526586+lukmzig@users.noreply.github.com> * Fix Typo --------- Co-authored-by: martineiber <11687066+martineiber@users.noreply.github.com> Co-authored-by: Lukas Mzigot <30526586+lukmzig@users.noreply.github.com>
1 parent d86c0e9 commit a083966

3 files changed

Lines changed: 109 additions & 1 deletion

File tree

src/DataIndex/Hydrator/DocumentHydrator.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator;
1515

1616
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\SearchResult\DocumentSearchResultItem;
17+
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Document\SearchResult\SearchResultItem\Page;
1718
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Document;
19+
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\PageSnippet\PageSnippet;
1820
use Pimcore\Bundle\StudioBackendBundle\Document\Service\HydratorServiceInterface;
1921

2022
/**
@@ -29,6 +31,15 @@ public function __construct(
2931

3032
public function hydrate(DocumentSearchResultItem $item): Document
3133
{
32-
return new Document(...$this->hydratorService->getBaseDocumentData($item));
34+
$documentBaseData = $this->hydratorService->getBaseDocumentData($item);
35+
36+
if ($item instanceof Page) {
37+
$documentBaseData[] = $item->getTitle();
38+
$documentBaseData[] = $item->getDescription();
39+
40+
return new PageSnippet(...$documentBaseData);
41+
}
42+
43+
return new Document(...$documentBaseData);
3344
}
3445
}

src/Document/Schema/Document.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,9 @@ public function getNavigationExclude(): bool
143143
{
144144
return $this->navigationExclude;
145145
}
146+
147+
public function getFilename(): string
148+
{
149+
return $this->getKey();
150+
}
146151
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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\Schema\PageSnippet;
15+
16+
use OpenApi\Attributes\Property;
17+
use OpenApi\Attributes\Schema;
18+
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Document;
19+
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\DocumentPermissions;
20+
use Pimcore\Bundle\StudioBackendBundle\Response\ElementIcon;
21+
22+
#[Schema(
23+
schema: 'PageSnippet',
24+
title: 'PageSnippet',
25+
required: [
26+
'title',
27+
'description',
28+
],
29+
type: 'object'
30+
)]
31+
final class PageSnippet extends Document
32+
{
33+
public function __construct(
34+
string $fullPath,
35+
bool $published,
36+
string $type,
37+
string $key,
38+
int $index,
39+
bool $hasChildren,
40+
bool $hasWorkflowWithPermissions,
41+
DocumentPermissions $permissions,
42+
int $id,
43+
int $parentId,
44+
string $path,
45+
ElementIcon $icon,
46+
int $userOwner,
47+
?int $userModification,
48+
?string $locked,
49+
bool $isLocked,
50+
?int $creationDate,
51+
?int $modificationDate,
52+
bool $isSite = false,
53+
bool $navigationExclude = false,
54+
#[Property(description: 'Title of the Page Snippet', type: 'string', example: 'Title')]
55+
private ?string $title = null,
56+
#[Property(description: 'Description of the Page Snippet', type: 'string', example: 'Description')]
57+
private ?string $description = null,
58+
) {
59+
parent::__construct(
60+
$fullPath,
61+
$published,
62+
$type,
63+
$key,
64+
$index,
65+
$hasChildren,
66+
$hasWorkflowWithPermissions,
67+
$permissions,
68+
$id,
69+
$parentId,
70+
$path,
71+
$icon,
72+
$userOwner,
73+
$userModification,
74+
$locked,
75+
$isLocked,
76+
$creationDate,
77+
$modificationDate,
78+
$isSite = false,
79+
$navigationExclude = false,
80+
);
81+
}
82+
83+
public function getTitle(): ?string
84+
{
85+
return $this->title;
86+
}
87+
88+
public function getDescription(): ?string
89+
{
90+
return $this->description;
91+
}
92+
}

0 commit comments

Comments
 (0)