Skip to content

Commit

Permalink
Add product installer connection (See #24)
Browse files Browse the repository at this point in the history
* Support importing via the product installer 2922775

* - Structure modified cebef5b
- Product Installer added to `setLoadAfter`

* Consider archive connections 8aca2f6

* Add setUserGroupArchiveConnections fdcfd03

* Add translations 899ada2

---------

Co-authored-by: Daniele Sciannimanica <[email protected]>
  • Loading branch information
zoglo and doishub authored Mar 5, 2024
2 parents 6c5a816 + 899ada2 commit 45fda5e
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 1 deletion.
6 changes: 6 additions & 0 deletions contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down Expand Up @@ -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'];
6 changes: 5 additions & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
])
];
}
}
42 changes: 42 additions & 0 deletions src/EventListener/Import/AddRecommendationValidatorListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/*
* This file is part of Oveleon Recommendation Bundle.
*
* @package contao-recommendation-bundle
* @license AGPL-3.0
* @author Daniele Sciannimanica <https://github.com/doishub>
* @copyright Oveleon <https://www.oveleon.de/>
*/

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();
}
}
23 changes: 23 additions & 0 deletions src/Import/Validator/RecommendationArchiveValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Oveleon\ContaoRecommendationBundle\Import\Validator;

use Oveleon\ContaoRecommendationBundle\Model\RecommendationArchiveModel;

/**
* Validator class for validating the recommendation records during and after import.
*
* @author Daniele Sciannimanica <https://github.com/doishub>
*/
class RecommendationArchiveValidator
{
static public function getTrigger(): string
{
return RecommendationArchiveModel::getTable();
}

static public function getModel(): string
{
return RecommendationArchiveModel::class;
}
}
24 changes: 24 additions & 0 deletions src/Import/Validator/RecommendationValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Oveleon\ContaoRecommendationBundle\Import\Validator;

use Oveleon\ContaoRecommendationBundle\Model\RecommendationModel;
use Oveleon\ProductInstaller\Import\Validator\ValidatorInterface;

/**
* Validator class for validating the recommendation item records during and after import.
*
* @author Daniele Sciannimanica <https://github.com/doishub>
*/
class RecommendationValidator implements ValidatorInterface
{
static public function getTrigger(): string
{
return RecommendationModel::getTable();
}

static public function getModel(): string
{
return RecommendationModel::class;
}
}
23 changes: 23 additions & 0 deletions translations/setup.de.yaml
Original file line number Diff line number Diff line change
@@ -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.<br/><br/><b>Folgende Seite wurde nicht importiert und benötigt eine Alternative:</b>'
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.'
23 changes: 23 additions & 0 deletions translations/setup.en.yaml
Original file line number Diff line number Diff line change
@@ -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.<br/><br/><b>The following page was not imported and needs an alternative:</b>'
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.'

0 comments on commit 45fda5e

Please sign in to comment.