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

Pimcore 11 Support #65

Merged
merged 6 commits into from May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -26,6 +26,6 @@
}
},
"require": {
"pimcore/pimcore": "^10.2"
"pimcore/pimcore": "^11.0"
}
}
4 changes: 2 additions & 2 deletions src/NewsBundle/Controller/Admin/SettingsController.php
Expand Up @@ -3,14 +3,14 @@
namespace NewsBundle\Controller\Admin;

use NewsBundle\Manager\EntryTypeManager;
use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController;
use Pimcore\Model\DataObject;
use Pimcore\Model\Version;
use Pimcore\Translation\Translator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class SettingsController extends AdminController
class SettingsController extends AdminAbstractController
{
protected EntryTypeManager $entryTypeManager;

Expand Down
2 changes: 1 addition & 1 deletion src/NewsBundle/Controller/EntryController.php
Expand Up @@ -15,7 +15,7 @@ public function detailAction(Request $request): Response
$newsFragment = $request->attributes->get('entry');
$locale = $request->attributes->get('_locale');

$entry = DataObject\NewsEntry::getByLocalizedfields('detailUrl', $newsFragment, $locale, ['limit' => 1]);
$entry = DataObject\NewsEntry::getByLocalizedfields('detailUrl', $newsFragment, $locale, 1);

if (!$entry instanceof DataObject\NewsEntry) {
throw new NotFoundHttpException(sprintf('Entry %s not found', $newsFragment));
Expand Down
7 changes: 6 additions & 1 deletion src/NewsBundle/CoreExtension/EntryTypeSelect.php
Expand Up @@ -6,5 +6,10 @@

class EntryTypeSelect extends Select
{
public $fieldtype = 'entryTypeSelect';
public string $fieldtype = 'entryTypeSelect';

public function getFieldType(): string
{
return $this->fieldtype;
}
}
6 changes: 3 additions & 3 deletions src/NewsBundle/Document/Areabrick/News/News.php
Expand Up @@ -396,7 +396,7 @@ private function getDefaultFieldValues(): array
$adminSettings['paginate'] = ['items_per_page' => ['value' => $listConfig['paginate']['items_per_page']]];
$itemsPerPageElement = $this->getDocumentField('numeric', 'itemsPerPage');
if ($itemsPerPageElement->isEmpty()) {
$itemsPerPageElement->setDataFromResource($adminSettings['paginate']['items_per_page']['value']);
$itemsPerPageElement->setDataFromResource((string) $adminSettings['paginate']['items_per_page']['value']);
} else {
$adminSettings['paginate']['items_per_page']['value'] = (int) $itemsPerPageElement->getData();
}
Expand All @@ -405,7 +405,7 @@ private function getDefaultFieldValues(): array
$adminSettings['max_items'] = ['value' => $listConfig['max_items']];
$limitElement = $this->getDocumentField('numeric', 'limit');
if ($limitElement->isEmpty() || $itemsPerPageElement->getData() < 0) {
$limitElement->setDataFromResource($adminSettings['max_items']['value']);
$limitElement->setDataFromResource((string) $adminSettings['max_items']['value']);
} else {
$adminSettings['max_items']['value'] = (int) $limitElement->getData();
}
Expand All @@ -414,7 +414,7 @@ private function getDefaultFieldValues(): array
$adminSettings['offset'] = ['value' => 0];
$offsetElement = $this->getDocumentField('numeric', 'offset');
if ($offsetElement->isEmpty()) {
$offsetElement->setDataFromResource($adminSettings['offset']['value']);
$offsetElement->setDataFromResource((string) $adminSettings['offset']['value']);
} else {
$adminSettings['offset']['value'] = (int) $offsetElement->getData();
}
Expand Down
4 changes: 2 additions & 2 deletions src/NewsBundle/EventListener/EntryTypeListener.php
Expand Up @@ -4,8 +4,8 @@

use NewsBundle\Configuration\Configuration;
use NewsBundle\Manager\EntryTypeManager;
use Pimcore\Bundle\AdminBundle\Event\AdminEvents;
use Pimcore\Tool\Admin as AdminTool;
use Pimcore\Event\AdminEvents;
use Pimcore\Model\DataObject\ClassDefinition\CustomLayout;
use Pimcore\Model\DataObject\NewsEntry;
use Pimcore\Model\DataObject\Service;
Expand Down Expand Up @@ -132,4 +132,4 @@ public function setEntryTypeLayout(GenericEvent $e): void

$e->setArgument('data', $data);
}
}
}
4 changes: 2 additions & 2 deletions src/NewsBundle/EventListener/NewsSeoListener.php
Expand Up @@ -42,7 +42,7 @@ public function handleObjectSeoAdd(DataObjectEvent $event): void
}

$reset = false;
$masterRequest = $this->requestStack->getMasterRequest();
$masterRequest = $this->requestStack->getMainRequest();
if ($masterRequest instanceof Request) {
$reset = true;
foreach (['sourceId', 'targetId', 'transactionId'] as $copyTransactionArgument) {
Expand Down Expand Up @@ -87,7 +87,7 @@ private function parseUrl($object): void

$oldObject = null;
if ($object->getId() > 0) {
$oldObject = $objectClass::getById($object->getId(), true);
$oldObject = $objectClass::getById($object->getId(), ['force' => true]);
}

foreach ($languages as $language) {
Expand Down
6 changes: 3 additions & 3 deletions src/NewsBundle/Generator/RelatedEntriesGenerator.php
Expand Up @@ -42,7 +42,7 @@ public function generateRelatedEntries(EntryInterface $news, array $params = [])
}

$newsListing->addConditionParam('name <> ""');
$newsListing->setGroupBy('o_id');
$newsListing->setGroupBy($newsListing->getDao()->getTableName().'.id', false);

$categories = [];
if (count($news->getCategories()) > 0 && !$settings['ignoreCategory']) {
Expand All @@ -57,7 +57,7 @@ public function generateRelatedEntries(EntryInterface $news, array $params = [])
$newsListing->addConditionParam('entryType = ?', $settings['entryType']);
}

$newsListing->addConditionParam('o_id != ?', $news->getId());
$newsListing->addConditionParam($newsListing->getDao()->getTableName().'.id != ?', $news->getId());

//add additional where clauses.
if (count($settings['where'])) {
Expand All @@ -68,4 +68,4 @@ public function generateRelatedEntries(EntryInterface $news, array $params = [])

return $newsListing->load();
}
}
}
2 changes: 1 addition & 1 deletion src/NewsBundle/Manager/EntryTypeManager.php
Expand Up @@ -3,11 +3,11 @@
namespace NewsBundle\Manager;

use NewsBundle\Configuration\Configuration;
use Pimcore\Bundle\StaticRoutesBundle\Model\Staticroute;
use Pimcore\Http\Request\Resolver\DocumentResolver;
use Pimcore\Http\Request\Resolver\EditmodeResolver;
use Pimcore\Http\Request\Resolver\SiteResolver;
use Pimcore\Model\Site;
use Pimcore\Model\Staticroute;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Tool;
Expand Down
2 changes: 1 addition & 1 deletion src/NewsBundle/Model/Category.php
Expand Up @@ -85,7 +85,7 @@ public function getEntriesPaging(
$list->setOrderKey($sort['name']);
$list->setOrder($sort['direction']);

$paginator = \Pimcore::getContainer()->get(PaginatorInterface::class);
$paginator = \Pimcore::getContainer()->get('knp_paginator');

return $paginator->paginate(
$list,
Expand Down
32 changes: 20 additions & 12 deletions src/NewsBundle/Model/Entry.php
Expand Up @@ -53,9 +53,9 @@ public static function getEntriesPaging(array $params = []): PaginationInterface
$newsListing = DataObject\NewsEntry::getList();
$newsListing->setOrderKey($settings['sort']['field']);
$newsListing->setOrder($settings['sort']['dir']);
$newsListing->setGroupBy('o_id');
$newsListing->setGroupBy('id');

$paginator = \Pimcore::getContainer()->get(PaginatorInterface::class);
$paginator = \Pimcore::getContainer()->get('knp_paginator');

$categories = null;
if (isset($settings['category']) && $settings['category'] instanceof Category) {
Expand Down Expand Up @@ -105,6 +105,14 @@ public static function getEntriesPaging(array $params = []): PaginationInterface
//allow listing modification.
static::modifyListing($newsListing, $settings);

if ($newsListing->getOffset()) {
$notList = clone $newsListing;
$notList->setOffset(0);
$notList->setLimit($newsListing->getOffset());
$notIdList = $notList->loadIdList();
$newsListing->filterById([$notIdList], 'NOT IN(?)');
}

return $paginator->paginate(
$newsListing,
$settings['page'] === 0 ? 1 : $settings['page'],
Expand All @@ -125,16 +133,16 @@ public static function addTimeRange(DataObject\NewsEntry\Listing $newsListing, a

$newsListing->addConditionParam(sprintf('(
CASE WHEN showEntryUntil IS NOT NULL
THEN
THEN
showEntryUntil %1$s UNIX_TIMESTAMP(NOW())
ELSE
(CASE WHEN dateTo IS NOT NULL
THEN
dateTo %1$s UNIX_TIMESTAMP(NOW())
THEN
dateTo %1$s UNIX_TIMESTAMP(NOW())
ELSE
(CASE WHEN date IS NOT NULL
THEN
date %1$s UNIX_TIMESTAMP(NOW())
THEN
date %1$s UNIX_TIMESTAMP(NOW())
ELSE
FALSE
END
Expand Down Expand Up @@ -238,27 +246,27 @@ public function getJsonLDData(): array
return $data;
}

public function getName($language = null)
public function getName(?string $language = null)
{
throw new ImplementedByPimcoreException(__CLASS__, __METHOD__);
}

public function getLead($language = null)
public function getLead(?string $language = null)
{
throw new ImplementedByPimcoreException(__CLASS__, __METHOD__);
}

public function getDescription($language = null)
public function getDescription(?string $language = null)
{
throw new ImplementedByPimcoreException(__CLASS__, __METHOD__);
}

public function getRedirectLink($language = null)
public function getRedirectLink(?string $language = null)
{
throw new ImplementedByPimcoreException(__CLASS__, __METHOD__);
}

public function getDetailUrl($language = null)
public function getDetailUrl(?string $language = null)
{
throw new ImplementedByPimcoreException(__CLASS__, __METHOD__);
}
Expand Down
10 changes: 5 additions & 5 deletions src/NewsBundle/Model/EntryInterface.php
Expand Up @@ -21,19 +21,19 @@ public static function getCategoriesRecursive(?CategoryInterface $category, bool

public function getImage(): ?Asset;

public function getName($language = null);
public function getName(?string $language = null);

public function getLead($language = null);
public function getLead(?string $language = null);

public function getDescription($language = null);
public function getDescription(?string $language = null);

public function getJsonLDData();

public function getEntryType();

public function getRedirectLink($language = null);
public function getRedirectLink(?string $language = null);

public function getDetailUrl($language = null);
public function getDetailUrl(?string $language = null);

public function getCategories();

Expand Down
23 changes: 20 additions & 3 deletions src/NewsBundle/NewsBundle.php
Expand Up @@ -5,10 +5,11 @@
use NewsBundle\DependencyInjection\CompilerPass\PresetPass;
use NewsBundle\Tool\Install;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface;
use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class NewsBundle extends AbstractPimcoreBundle
class NewsBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface
{
use PackageVersionTrait;

Expand All @@ -25,6 +26,11 @@ public function getInstaller(): Install
return $this->container->get(Install::class);
}

protected function getComposerPackageName(): string
{
return self::PACKAGE_NAME;
}

public function getJsPaths(): array
{
return [
Expand All @@ -34,8 +40,19 @@ public function getJsPaths(): array
];
}

protected function getComposerPackageName(): string

public function getCssPaths(): array
{
return self::PACKAGE_NAME;
return [];
}

public function getEditmodeJsPaths(): array
{
return [];
}

public function getEditmodeCssPaths(): array
{
return [];
}
}
2 changes: 1 addition & 1 deletion src/NewsBundle/Resources/config/services/system.yml
Expand Up @@ -9,7 +9,7 @@ services:
arguments:
$bundle: "@=service('kernel').getBundle('NewsBundle')"
calls:
- [setTokenStorageUserResolver, ['@Pimcore\Bundle\AdminBundle\Security\User\TokenStorageUserResolver']]
- [setTokenStorageUserResolver, ['@Pimcore\Security\User\TokenStorageUserResolver']]
- [setSerializer, ['@serializer']]

NewsBundle\Configuration\Configuration: ~
Expand Down