Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement]: Move grid data related functions to admin-ui-classic-bundle #16745

Open
wants to merge 21 commits into
base: 11.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.3, highest, false)

Ignored error pattern #^Access to constant CONTEXT_SEARCH on an unknown class Pimcore\\Bundle\\AdminBundle\\Event\\ElementAdminStyleEvent\.$# in path /home/runner/work/pimcore/pimcore/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php was not matched in reported errors.

Check failure on line 1 in bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.3, highest, false)

Ignored error pattern #^Access to constant RESOLVE_ELEMENT_ADMIN_STYLE on an unknown class Pimcore\\Bundle\\AdminBundle\\Event\\AdminEvents\.$# in path /home/runner/work/pimcore/pimcore/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php was not matched in reported errors.

Check failure on line 1 in bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.3, highest, false)

Ignored error pattern #^Call to method getAdminStyle\(\) on an unknown class Pimcore\\Bundle\\AdminBundle\\Event\\ElementAdminStyleEvent\.$# in path /home/runner/work/pimcore/pimcore/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php was not matched in reported errors.

Check failure on line 1 in bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.3, highest, false)

Ignored error pattern #^Call to method getFilterCondition\(\) on an unknown class Pimcore\\Bundle\\AdminBundle\\Helper\\GridHelperService\.$# in path /home/runner/work/pimcore/pimcore/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php was not matched in reported errors.

Check failure on line 1 in bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.3, highest, false)

Ignored error pattern #^Instantiated class Pimcore\\Bundle\\AdminBundle\\Event\\ElementAdminStyleEvent not found\.$# in path /home/runner/work/pimcore/pimcore/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php was not matched in reported errors.

Check failure on line 1 in bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.3, highest, false)

Ignored error pattern #^Parameter \$gridHelperService of method Pimcore\\Bundle\\SimpleBackendSearchBundle\\Controller\\SearchController\:\:findAction\(\) has invalid type Pimcore\\Bundle\\AdminBundle\\Helper\\GridHelperService\.$# in path /home/runner/work/pimcore/pimcore/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php was not matched in reported errors.
declare(strict_types=1);

/**
Expand All @@ -21,6 +21,7 @@
use Pimcore\Bundle\AdminBundle\Event\ElementAdminStyleEvent;
use Pimcore\Bundle\AdminBundle\Helper\GridHelperService;
use Pimcore\Bundle\AdminBundle\Helper\QueryParams;
use Pimcore\Bundle\AdminBundle\Service\GridData;
use Pimcore\Bundle\SimpleBackendSearchBundle\Event\AdminSearchEvents;
use Pimcore\Bundle\SimpleBackendSearchBundle\Model\Search\Backend\Data;
use Pimcore\Config;
Expand Down Expand Up @@ -330,14 +331,13 @@
foreach ($hits as $hit) {
$element = Element\Service::getElementById($hit->getId()->getType(), $hit->getId()->getId());
if ($element->isAllowed('list')) {
$data = null;
if ($element instanceof DataObject\AbstractObject) {
$data = DataObject\Service::gridObjectData($element, $fields);
} elseif ($element instanceof Document) {
$data = Document\Service::gridDocumentData($element);
} elseif ($element instanceof Asset) {
$data = Asset\Service::gridAssetData($element);
}

$data = match (true) {
$element instanceof DataObject\AbstractObject => GridData\DataObject::getData($element, $fields),
$element instanceof Document => GridData\Document::getData($element),
$element instanceof Asset => GridData\Asset::getData($element),
default => null, // Default case if none of the conditions are met
};

if ($data) {
$elements[] = $data;
Expand Down
Expand Up @@ -17,6 +17,7 @@
namespace Pimcore\Bundle\SimpleBackendSearchBundle\DataProvider\GDPR;

use Pimcore\Bundle\AdminBundle\GDPR\DataProvider;
use Pimcore\Bundle\AdminBundle\Service\GridData;
use Pimcore\Bundle\SimpleBackendSearchBundle\Model\Search\Backend\Data;
use Pimcore\Db;
use Pimcore\Model\Asset;
Expand Down Expand Up @@ -96,7 +97,7 @@ public function searchData(int $id, string $firstname, string $lastname, string
$element = Service::getElementById($hit->getId()->getType(), $hit->getId()->getId());

if ($element instanceof Asset) {
$data = \Pimcore\Model\Asset\Service::gridAssetData($element);
$data = GridData\Asset::getData($element);
$data['permissions'] = $element->getUserPermissions();
$elements[] = $data;
}
Expand Down
Expand Up @@ -18,6 +18,7 @@

use Pimcore\Bundle\AdminBundle\GDPR\DataProvider;
use Pimcore\Bundle\AdminBundle\Helper\QueryParams;
use Pimcore\Bundle\AdminBundle\Service\GridData;
use Pimcore\Bundle\SimpleBackendSearchBundle\Model\Search\Backend\Data;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Concrete;
Expand Down Expand Up @@ -102,7 +103,7 @@ public function searchData(int $id, string $firstname, string $lastname, string
foreach ($hits as $hit) {
$element = Element\Service::getElementById($hit->getId()->getType(), $hit->getId()->getId());
if ($element instanceof Concrete) {
$data = DataObject\Service::gridObjectData($element);
$data = GridData\DataObject::getData($element);
$data['__gdprIsDeletable'] = $this->config['classes'][$element->getClassName()]['allowDelete'] ?? false;
$elements[] = $data;
}
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -132,7 +132,8 @@
"conflict": {
"symfony/symfony": "*",
"sabre/dav": "4.2.2",
"thecodingmachine/safe": "<2.0"
"thecodingmachine/safe": "<2.0",
"pimcore/admin-ui-classic-bundle": "<1.4"
},
"require-dev": {
"codeception/codeception": "^5.0.3",
Expand All @@ -146,7 +147,8 @@
"chrome-php/chrome": "^1.4.0",
"webmozarts/console-parallelization": "^2.1",
"symfony/dotenv": "^6.4",
"symfony/runtime": "^6.4"
"symfony/runtime": "^6.4",
"pimcore/admin-ui-classic-bundle": "dev-move-previewthumbfromcore as 1.4"
},
"suggest": {
"ext-sockets": "*",
Expand Down
99 changes: 0 additions & 99 deletions models/Asset/Service.php
Expand Up @@ -207,105 +207,6 @@ public function copyContents(Asset $target, Asset $source): Asset
return $target;
}

/**
*
*
* @internal
*/
public static function gridAssetData(Asset $asset, array $fields = null, string $requestedLanguage = null, array $params = []): array
{
$data = Element\Service::gridElementData($asset);
$loader = null;

if ($asset instanceof Asset && !empty($fields)) {
$data = [
'id' => $asset->getId(),
'id~system' => $asset->getId(),
'type~system' => $asset->getType(),
'fullpath~system' => $asset->getRealFullPath(),
'filename~system' => $asset->getKey(),
'creationDate~system' => $asset->getCreationDate(),
'modificationDate~system' => $asset->getModificationDate(),
'idPath~system' => Element\Service::getIdPath($asset),
];

$requestedLanguage = str_replace('default', '', $requestedLanguage);

foreach ($fields as $field) {
$fieldDef = explode('~', $field);
if (isset($fieldDef[1]) && $fieldDef[1] === 'system') {
if ($fieldDef[0] === 'preview') {
$data[$field] = self::getPreviewThumbnail($asset, ['treepreview' => true, 'width' => 108, 'height' => 70, 'frame' => true]);
} elseif ($fieldDef[0] === 'size') {
$size = $asset->getFileSize();
$data[$field] = formatBytes($size);
}
} else {
if (isset($fieldDef[1])) {
$language = ($fieldDef[1] === 'none' ? '' : $fieldDef[1]);
$rawMetaData = $asset->getMetadata($fieldDef[0], $language, true, true);
} else {
$rawMetaData = $asset->getMetadata($field, $requestedLanguage, true, true);
}

$metaData = $rawMetaData['data'] ?? null;

if ($rawMetaData) {
$type = $rawMetaData['type'];
if (!$loader) {
$loader = \Pimcore::getContainer()->get('pimcore.implementation_loader.asset.metadata.data');
}

$metaData = $rawMetaData['data'] ?? null;

try {
/** @var Data $instance */
$instance = $loader->build($type);
$metaData = $instance->getDataForListfolderGrid($rawMetaData['data'] ?? null, $rawMetaData);
} catch (UnsupportedException $e) {
}
}

$data[$field] = $metaData;
}
}
}

return $data;
}

/**
*
*
* @internal
*/
public static function getPreviewThumbnail(Asset $asset, array $params = [], bool $onlyMethod = false): ?string
{
$thumbnailMethod = '';
$thumbnailUrl = null;

if ($asset instanceof Asset\Image) {
$thumbnailMethod = 'getThumbnail';
} elseif ($asset instanceof Asset\Video && \Pimcore\Video::isAvailable()) {
$thumbnailMethod = 'getImageThumbnail';
} elseif ($asset instanceof Asset\Document && \Pimcore\Document::isAvailable()) {
$thumbnailMethod = 'getImageThumbnail';
}

if ($onlyMethod) {
return $thumbnailMethod;
}

if (!empty($thumbnailMethod)) {
$thumbnailUrl = '/admin/asset/get-' . $asset->getType() . '-thumbnail?id=' . $asset->getId();
if (count($params) > 0) {
$thumbnailUrl .= '&' . http_build_query($params);
}
}

return $thumbnailUrl;
}

/**
* @static
*
Expand Down
Expand Up @@ -20,6 +20,7 @@
use Pimcore\Logger;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Bundle\AdminBundle\Service\GridData;
use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData;
use Pimcore\Model\DataObject\Localizedfield;
use Pimcore\Model\Element;
Expand Down Expand Up @@ -217,7 +218,7 @@ public function getDataForEditmode(mixed $data, DataObject\Concrete $object = nu
$index = $mkey + 1;
$object = $metaObject->getObject();
if ($object instanceof DataObject\Concrete) {
$columnData = DataObject\Service::gridObjectData($object, $gridFields, null, ['purpose' => 'editmode']);
$columnData = GridData\DataObject::getData($object, $gridFields, null, ['purpose' => 'editmode']);
foreach ($this->getColumns() as $c) {
$getter = 'get' . ucfirst($c['key']);

Expand Down
Expand Up @@ -16,6 +16,7 @@

namespace Pimcore\Model\DataObject\ClassDefinition\Data;

use Pimcore\Bundle\AdminBundle\Service\GridData;
use Pimcore\Model;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\ClassDefinition\Data\Relations\AbstractRelations;
Expand Down Expand Up @@ -177,7 +178,7 @@ public function getDataForEditmode(mixed $data, DataObject\Concrete $object = nu
if (is_array($data) && count($data) > 0) {
foreach ($data as $referencedObject) {
if ($referencedObject instanceof DataObject\Concrete) {
$return[] = DataObject\Service::gridObjectData($referencedObject, $gridFields, null, ['purpose' => 'editmode']);
$return[] = GridData\DataObject::getData($referencedObject, $gridFields, null, ['purpose' => 'editmode']);
}
}
}
Expand Down