diff --git a/contao/config/config.php b/contao/config/config.php index 36e49be..f5bfc2b 100644 --- a/contao/config/config.php +++ b/contao/config/config.php @@ -8,6 +8,7 @@ use Oveleon\ContaoRecommendationBundle\ModuleRecommendationReader; use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel; use Oveleon\ContaoRecommendationBundle\Model\RecommendationModel; +use Oveleon\ContaoRecommendationBundle\EventListener\Import\AddRecommendationValidatorListener; // Back end modules ArrayUtil::arrayInsert($GLOBALS['BE_MOD']['content'], 5, [ @@ -39,3 +40,8 @@ // Models $GLOBALS['TL_MODELS']['tl_recommendation'] = RecommendationModel::class; $GLOBALS['TL_MODELS']['tl_recommendation_archive'] = RecommendationArchiveModel::class; + +// Add product installer validators +$GLOBALS['PI_HOOKS']['addValidator'][] = [AddRecommendationValidatorListener::class, 'addValidators']; +$GLOBALS['PI_HOOKS']['setModuleValidatorArchiveConnections'][] = [AddRecommendationValidatorListener::class, 'setModuleArchiveConnections']; +$GLOBALS['PI_HOOKS']['setUserGroupValidatorArchiveConnections'][] = [AddRecommendationValidatorListener::class, 'setUserGroupArchiveConnections']; diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index d32d03c..3eb53b6 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -15,6 +15,7 @@ use Contao\ManagerPlugin\Bundle\Config\BundleConfig; use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; use Oveleon\ContaoRecommendationBundle\ContaoRecommendationBundle; +use Oveleon\ProductInstaller\ProductInstaller; class Plugin implements BundlePluginInterface { @@ -26,7 +27,10 @@ public function getBundles(ParserInterface $parser): array return [ BundleConfig::create(ContaoRecommendationBundle::class) ->setReplace(['recommendation']) - ->setLoadAfter([ContaoCoreBundle::class]) + ->setLoadAfter([ + ContaoCoreBundle::class, + ProductInstaller::class + ]) ]; } } diff --git a/src/EventListener/Import/AddRecommendationValidatorListener.php b/src/EventListener/Import/AddRecommendationValidatorListener.php new file mode 100644 index 0000000..2b5e82f --- /dev/null +++ b/src/EventListener/Import/AddRecommendationValidatorListener.php @@ -0,0 +1,42 @@ + + * @copyright Oveleon + */ + +namespace Oveleon\ContaoRecommendationBundle\EventListener\Import; + +use Oveleon\ContaoRecommendationBundle\Import\Validator\RecommendationArchiveValidator; +use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel; +use Oveleon\ProductInstaller\Import\Validator; +use Oveleon\ProductInstaller\Import\Validator\ModuleValidator; + +class AddRecommendationValidatorListener +{ + public function addValidators(): void + { + // Connects jumpTo pages + Validator::addValidatorCollection([RecommendationArchiveValidator::class], ['setJumpToPageConnection']); + } + + public function setModuleArchiveConnections(array $row): array + { + return match ($row['type']) { + 'recommendationlist', 'recommendationreader' => ['field' => 'recommendation_archives', 'table' => RecommendationArchiveModel::getTable()], + 'recommendationform' => ['field' => 'recommendation_archive', 'table' => RecommendationArchiveModel::getTable()], + default => [], + }; + } + + public function setUserGroupArchiveConnections(array &$connections): void + { + $connections['recommendations'] = RecommendationArchiveModel::getTable(); + } +} diff --git a/src/Import/Validator/RecommendationArchiveValidator.php b/src/Import/Validator/RecommendationArchiveValidator.php new file mode 100644 index 0000000..e8f17f8 --- /dev/null +++ b/src/Import/Validator/RecommendationArchiveValidator.php @@ -0,0 +1,23 @@ + + */ +class RecommendationArchiveValidator +{ + static public function getTrigger(): string + { + return RecommendationArchiveModel::getTable(); + } + + static public function getModel(): string + { + return RecommendationArchiveModel::class; + } +} diff --git a/src/Import/Validator/RecommendationValidator.php b/src/Import/Validator/RecommendationValidator.php new file mode 100644 index 0000000..918b4ba --- /dev/null +++ b/src/Import/Validator/RecommendationValidator.php @@ -0,0 +1,24 @@ + + */ +class RecommendationValidator implements ValidatorInterface +{ + static public function getTrigger(): string + { + return RecommendationModel::getTable(); + } + + static public function getModel(): string + { + return RecommendationModel::class; + } +} diff --git a/translations/setup.de.yaml b/translations/setup.de.yaml new file mode 100644 index 0000000..55194af --- /dev/null +++ b/translations/setup.de.yaml @@ -0,0 +1,23 @@ +setup: + tables: + tl_recommendation_archive: 'Bewertungen-Archive' + tl_recommendation: 'Bewertungen' + prompt: + recommendation_archive: + jumpTo: + label: 'Bewertungen-Archiv → Weiterleitungsseite' + description: 'Ein oder mehrere Bewertungen-Archive verweisen auf eine Weiterleitungsseite, welche nicht aufgelöst werden kann. Ihre Auswahl wird für alle weiteren Bewertungen-Archive, welche auf die selbe Weiterleitungsseite referenzieren, übernommen.' + explanation: 'Beim Importieren eines oder mehrerer Bewertungen-Archive konnte die zugehörige Weiterleitungsseite nicht gefunden werden. Wählen Sie bitte eine Seite aus Ihrer Contao-Instanz, um eine Verknüpfung zwischen diesen Archiven und einer Seite herzustellen.

Folgende Seite wurde nicht importiert und benötigt eine Alternative:' + module: + recommendation_archives: + label: 'Modul → Bewertungsarchive' + description: 'Dem Modul konnten ein oder mehrere Archive nicht zugeordnet werden. Ihre Auswahl wird für das derzeitige Modul übernommen.' + explanation: 'Beim Importieren eines oder mehrerer Module konnten zugehörige Archive nicht gefunden werden. Wählen Sie bitte ein Archiv aus Ihrer Contao-Instanz aus, um eine Verknüpfung zwischen diesem Modul und einem Archiv herzustellen.' + recommendation_archive: + label: 'Modul → Bewertungsarchiv' + description: 'Dem Modul konnte kein Archiv nicht zugeordnet werden. Ihre Auswahl wird für das derzeitige Modul übernommen.' + explanation: 'Beim Importieren eines Moduls konnte kein zugehöriges Archiv gefunden werden. Wählen Sie bitte ein Archiv aus Ihrer Contao-Instanz aus, um eine Verknüpfung zwischen diesem Modul und einem Archiv herzustellen.' + user_group: + recommendations: + label: 'Benutzergruppe "%userGroupName%" → Bewertungsarchive' + description: 'Ein oder mehrere Archive konnten nicht zugewiesen werden, bitte weisen Sie diese manuell zu.' diff --git a/translations/setup.en.yaml b/translations/setup.en.yaml new file mode 100644 index 0000000..b89681a --- /dev/null +++ b/translations/setup.en.yaml @@ -0,0 +1,23 @@ +setup: + tables: + tl_recommendation_archive: 'Recommendation archives' + tl_recommendation: 'Recommendations' + prompt: + recommendation_archive: + jumpTo: + label: 'Recommendation-Archive → Redirect page' + description: 'One or more recommendation archives refer to a forwarding page that cannot be resolved. Your selection is applied to all other rating archives that reference the same redirection page.' + explanation: 'When importing one or more recommendation archives, the corresponding redirect page could not be found. Please select a page from your Contao instance to create a link between these archives and a page.

The following page was not imported and needs an alternative:' + module: + recommendation_archives: + label: 'Module → Recommendation archives' + description: 'One or more archives could not be assigned to the module. Your selection will be applied to the current module.' + explanation: 'During the import of one or more modules, the corresponding archives could not be found. Please select an archive from your Contao instance to create a link between this module and an archive.' + recommendation_archive: + label: 'Module → Recommendation archive' + description: 'No archive could not be assigned to the module. Your selection will be applied to the current module.' + explanation: 'During the import of a module, no associated archive could be found. Please select an archive from your Contao instance to create a link between this module and an archive.' + user_group: + recommendations: + label: 'User group "%userGroupName%" → Recommendation archives' + description: 'One or more archives could not be assigned, please assign them manually.'