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 4 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
Expand Up @@ -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),

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, highest, true, 6.4.x-dev)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.
$element instanceof Document => GridData\Document::getData($element),

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Document.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Document.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Document.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Document.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, highest, true, 6.4.x-dev)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Document.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Document.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Document.
$element instanceof Asset => GridData\Asset::getData($element),

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Asset.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Asset.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Asset.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Asset.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, highest, true, 6.4.x-dev)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Asset.

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

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Asset.

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

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\Asset.
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
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 @@
$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']);

Check failure on line 221 in models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 221 in models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 221 in models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 221 in models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 221 in models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, highest, true, 6.4.x-dev)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 221 in models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 221 in models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.
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 @@
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']);

Check failure on line 181 in models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 181 in models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 181 in models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 181 in models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 181 in models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, highest, true, 6.4.x-dev)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 181 in models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.

Check failure on line 181 in models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php

View workflow job for this annotation

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

Call to static method getData() on an unknown class Pimcore\Bundle\AdminBundle\Service\GridData\DataObject.
}
}
}
Expand Down