diff --git a/src/CoreBundle/ContaoManager/Plugin.php b/src/CoreBundle/ContaoManager/Plugin.php index 0d882b31c..1a4d47b95 100644 --- a/src/CoreBundle/ContaoManager/Plugin.php +++ b/src/CoreBundle/ContaoManager/Plugin.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/core. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2024 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,8 @@ * @package MetaModels/core * @author Christian Schiffler * @author Sven Baumann - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2024 The MetaModels team. * @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -30,6 +31,7 @@ use MetaModels\CoreBundle\MetaModelsCoreBundle; use Symfony\Component\Config\Loader\LoaderResolverInterface; use Symfony\Component\HttpKernel\KernelInterface; +use Symfony\Component\Routing\RouteCollection; /** * Plugin for the Contao Manager. @@ -39,7 +41,7 @@ class Plugin implements BundlePluginInterface, RoutingPluginInterface /** * {@inheritdoc} */ - public function getBundles(ParserInterface $parser) + public function getBundles(ParserInterface $parser): array { return [ BundleConfig::create(MetaModelsCoreBundle::class) @@ -57,7 +59,7 @@ public function getBundles(ParserInterface $parser) /** * {@inheritdoc} */ - public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel) + public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel): ?RouteCollection { if (false === ($resolved = $resolver->resolve(__DIR__ . '/../Resources/config/routing.yml'))) { return null; diff --git a/src/CoreBundle/DependencyInjection/MetaModelsCoreExtension.php b/src/CoreBundle/DependencyInjection/MetaModelsCoreExtension.php index 1aa37c4f7..7c07d7400 100644 --- a/src/CoreBundle/DependencyInjection/MetaModelsCoreExtension.php +++ b/src/CoreBundle/DependencyInjection/MetaModelsCoreExtension.php @@ -26,6 +26,7 @@ use MetaModels\CoreBundle\Migration\TableCollationMigration; use MetaModels\Filter\FilterUrlBuilder; use Symfony\Component\Cache\Adapter\ArrayAdapter; +use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -116,10 +117,11 @@ public function load(array $configs, ContainerBuilder $container): void /** * {@inheritdoc} */ - public function getConfiguration(array $config, ContainerBuilder $container) + public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface { $projectDir = $container->getParameter('kernel.project_dir'); assert(\is_string($projectDir)); + return new Configuration((bool) $container->getParameter('kernel.debug'), $projectDir); } @@ -139,6 +141,7 @@ private function buildCacheService(ContainerBuilder $container, array $config): $cache->setClass(ArrayAdapter::class); $cache->setArguments([]); $container->setParameter('metamodels.cache_dir', null); + return; } diff --git a/src/CoreBundle/EventListener/BackendNavigationListener.php b/src/CoreBundle/EventListener/BackendNavigationListener.php index 3f16ccd5f..c944d57cc 100644 --- a/src/CoreBundle/EventListener/BackendNavigationListener.php +++ b/src/CoreBundle/EventListener/BackendNavigationListener.php @@ -81,13 +81,6 @@ class BackendNavigationListener */ private RouterInterface $router; - /** - * The session. - * - * @var Session - */ - private Session $session; - /** * Create a new instance. * @@ -96,7 +89,6 @@ class BackendNavigationListener * @param ViewCombination $viewCombination The view combination. * @param TokenStorageInterface $tokenStorage The token storage. * @param RouterInterface $router The router. - * @param Session $session The session. */ public function __construct( TranslatorInterface $translator, @@ -104,14 +96,12 @@ public function __construct( ViewCombination $viewCombination, TokenStorageInterface $tokenStorage, RouterInterface $router, - Session $session, ) { $this->requestStack = $requestStack; $this->translator = $translator; $this->viewCombination = $viewCombination; $this->tokenStorage = $tokenStorage; $this->router = $router; - $this->session = $session; } /** @@ -287,7 +277,7 @@ private function buildConfigNode(FactoryInterface $factory, Request $request): I private function updateCollapsedState(ItemInterface $metaModelsNode): void { $nodeName = $metaModelsNode->getName(); - $sessionBag = $this->session->getBag('contao_backend'); + $sessionBag = $this->requestStack->getSession()->getBag('contao_backend'); $status = ($sessionBag instanceof AttributeBagInterface) ? $sessionBag->get('backend_modules') : []; $isCollapsed = ($status[$nodeName] ?? 1) < 1; $path = $this->router->generate('contao_backend'); diff --git a/src/CoreBundle/Resources/config/listeners.yml b/src/CoreBundle/Resources/config/listeners.yml index 9367eaab6..ac733a748 100644 --- a/src/CoreBundle/Resources/config/listeners.yml +++ b/src/CoreBundle/Resources/config/listeners.yml @@ -81,7 +81,6 @@ services: - '@metamodels.view_combination' - '@security.token_storage' - '@router' - - '@session' tags: - { name: kernel.event_listener } diff --git a/src/CoreBundle/Resources/config/services.yml b/src/CoreBundle/Resources/config/services.yml index 9e2d80dfa..e66fdbccb 100644 --- a/src/CoreBundle/Resources/config/services.yml +++ b/src/CoreBundle/Resources/config/services.yml @@ -14,7 +14,7 @@ services: class: MetaModels\CoreBundle\Assets\IconBuilder arguments: - "@=service('contao.framework').getAdapter('Contao\\\\FilesModel')" - - "@contao.image.image_factory" + - "@contao.image.factory" - "%kernel.project_dir%" - "%metamodels.assets_dir%" - "%metamodels.assets_web%" @@ -87,6 +87,10 @@ services: - 'Contao\Input' metamodels.contao_session: + deprecated: + package: metamodels/core + version: 2.3 + message: 'The service "%service_id%" is deprecated and to be removed in MetaModels 3 - Use the symfony session instead.' class: Contao\Session factory: ['@MetaModels\CoreBundle\Contao\Compat\ContaoFactory', 'createInstance'] arguments: @@ -186,7 +190,10 @@ services: - "@metamodels.view_combination.input_screen_information_builder" MetaModels\MetaModelsServiceContainer: - deprecated: 'The service "%service_id%" is deprecated and to be removed in MetaModels 3 - inject needed services directly.' + deprecated: + package: metamodels/core + version: 2.3 + message: 'The service "%service_id%" is deprecated and to be removed in MetaModels 3 - inject needed services directly.' configurator: ['@MetaModels\CoreBundle\LegacyCompat\ServiceContainerInitializer', 'configure'] public: true @@ -293,11 +300,11 @@ services: MetaModels\Helper\ToolboxFile: public: false arguments: - - "@contao.image.image_factory" + - "@contao.image.factory" - "%kernel.project_dir%" - "@contao.assets.files_context" - "@contao.image.picture_factory" - - "@session" + - "@request_stack" MetaModels\CoreBundle\Translator\MetaModelTranslatorConfigurator: arguments: diff --git a/src/CoreBundle/Translator/LoaderInterface.php b/src/CoreBundle/Translator/LoaderInterface.php index 1cbe3e1a4..effc5d4f5 100644 --- a/src/CoreBundle/Translator/LoaderInterface.php +++ b/src/CoreBundle/Translator/LoaderInterface.php @@ -29,8 +29,8 @@ interface LoaderInterface /** * Loads a locale. * - * @param mixed $resource A resource - * @param string $locale A locale + * @param IMetaModel $metaModel A MetaModel + * @param string $locale A locale * * @return MessageCatalogue * diff --git a/src/CoreBundle/Translator/MetaModelTranslationLoader.php b/src/CoreBundle/Translator/MetaModelTranslationLoader.php index 488f775b8..66dcb4343 100644 --- a/src/CoreBundle/Translator/MetaModelTranslationLoader.php +++ b/src/CoreBundle/Translator/MetaModelTranslationLoader.php @@ -252,6 +252,9 @@ private function setTranslationLabelAndDescription( array $parameters, ): void { $headlineKey = 'backend-module.' . $inputScreen['meta']['id'] . '.headline'; + if (!$catalog->has($prefix . '.description', $domain)) { + $catalog->set($prefix . '.description', '', $domain); + } if ('' !== $value = $this->extractLangString($inputScreen['description'], $locale, $mainLanguage) ?? '') { $value = strtr($value, $parameters); $catalog->set($prefix . '.description', $value, $domain); diff --git a/src/CoreBundle/Translator/Translator.php b/src/CoreBundle/Translator/Translator.php index 33592e5ec..b901026e3 100644 --- a/src/CoreBundle/Translator/Translator.php +++ b/src/CoreBundle/Translator/Translator.php @@ -68,4 +68,9 @@ public function getCatalogue($locale = null): MessageCatalogueInterface { return $this->translator->getCatalogue($locale); } + + public function getCatalogues(): array + { + return $this->translator->getCatalogues(); + } } diff --git a/src/Events/DatabaseBackedListener.php b/src/Events/DatabaseBackedListener.php index 2435dc76d..175ffd8ad 100644 --- a/src/Events/DatabaseBackedListener.php +++ b/src/Events/DatabaseBackedListener.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/core. * - * (c) 2012-2023 The MetaModels team. + * (c) 2012-2024 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,7 +16,7 @@ * @author David Molineus * @author Cliff Parnitzky * @author Ingolf Steinhardt - * @copyright 2012-2023 The MetaModels team. + * @copyright 2012-2024 The MetaModels team. * @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -250,7 +250,7 @@ public function createMetaModel(CreateMetaModelEvent $event) { if ($event->getMetaModel() !== null) { /** @psalm-suppress DeprecatedMethod */ - if (($metaModel = $event->getMetaModel()) instanceof ITranslatedMetaModel && $metaModel->isTranslated()) { + if (!($metaModel = $event->getMetaModel()) instanceof ITranslatedMetaModel && $metaModel->isTranslated()) { // @codingStandardsIgnoreStart @\trigger_error( 'Translated "\MetaModel\IMetamodel" instances are deprecated since MetaModels 2.2 ' . diff --git a/src/Helper/ToolboxFile.php b/src/Helper/ToolboxFile.php index 1e5e4c0f2..f9d2a7296 100644 --- a/src/Helper/ToolboxFile.php +++ b/src/Helper/ToolboxFile.php @@ -48,6 +48,7 @@ use InvalidArgumentException; use Symfony\Component\Asset\Context\ContextInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface; use Symfony\Component\HttpFoundation\Session\Session; @@ -99,11 +100,11 @@ class ToolboxFile private PictureFactoryInterface $pictureFactory; /** - * Symfony session object + * Symfony requestStack object * - * @var Session + * @var RequestStack */ - private Session $session; + private RequestStack $requestStack; /** * Allowed file extensions. @@ -210,7 +211,7 @@ class ToolboxFile * @param string|null $rootDir The root path of the installation. * @param ContextInterface|null $filesContext The assets file context. * @param PictureFactoryInterface|null $pictureFactory The picture factory. - * @param Session|null $session The session. + * @param RequestStack|null $requestStack The requestStack. * * @SuppressWarnings(PHPMD.CamelCaseVariableName) * @SuppressWarnings(PHPMD.CyclomaticComplexity) @@ -221,7 +222,7 @@ public function __construct( string $rootDir = null, ContextInterface $filesContext = null, PictureFactoryInterface $pictureFactory = null, - Session $session = null + RequestStack $requestStack = null ) { switch (true) { case ($imageFactory instanceof ImageFactoryInterface) && (null !== $rootDir): @@ -290,17 +291,17 @@ public function __construct( } $this->pictureFactory = $pictureFactory; - if (null === $session) { + if (null === $requestStack) { // @codingStandardsIgnoreStart @trigger_error( 'Not passing a "Session" is deprecated.', E_USER_DEPRECATED ); // @codingStandardsIgnoreEnd - $session = System::getContainer()->get('session'); - assert($session instanceof Session); + $requestStack = System::getContainer()->get('request_stack'); + assert($requestStack instanceof RequestStack); } - $this->session = $session; + $this->requestStack = $requestStack; } /** @@ -573,8 +574,8 @@ protected function getDownloadLink($strFile) ->setQueryParameter('file', \urlencode($strFile)) ->getUrl(); } - - $bag = $this->session->getBag('attributes'); + // Throws exception when running in CLI mode due to missing session. + $bag = $this->requestStack->getSession()->getBag('attributes'); assert($bag instanceof AttributeBagInterface); $links = $bag->has('metaModels_downloads') ? $bag->get('metaModels_downloads') : []; @@ -850,7 +851,8 @@ private function checkDownloads() if (($file = Input::get('file'))) { if ($this->withDownloadKeys) { - $bag = $this->session->getBag('attributes'); + // Throws exception when running in CLI mode due to missing session. + $bag = $this->requestStack->getSession()->getBag('attributes'); assert($bag instanceof AttributeBagInterface); $links = $bag->has('metaModels_downloads') ? $bag->get('metaModels_downloads') : [];