Skip to content

Commit

Permalink
Merge pull request #9 from oveleon/develop
Browse files Browse the repository at this point in the history
Contao 5.1 support
  • Loading branch information
zoglo authored Jun 1, 2023
2 parents e77406b + a82d19b commit f9fe1aa
Show file tree
Hide file tree
Showing 25 changed files with 452 additions and 324 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Composer
/composer.lock
/vendor/

# PhpUnit
/.phpunit.result.cache
/phpunit.xml

# IDE
/.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

---

> Working with **Contao 4.9** and up to **Contao 4.13** (PHP ^7.4 and PHP 8)
> Working with **Contao 4.13** and **Contao 5.1** (PHP ^8.1)
---

Expand Down
40 changes: 30 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@
"name": "Oveleon",
"homepage": "https://oveleon.de/",
"role": "Developer"
},
{
"name": "Sebastian Zoglowek",
"homepage": "https://github.com/zoglo",
"role": "Developer"
},
{
"name": "Fabian Ekert",
"homepage": "https://github.com/eki89",
"role": "Developer"
}
],
"require": {
"php": "^7.4 || ^8.0",
"contao/core-bundle":"^4.9",
"oveleon/contao-recommendation-bundle":"^1.2.1"
"php": "^8.1",
"contao/core-bundle": "^4.13 || ^5.1",
"oveleon/contao-recommendation-bundle": "^1.3"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
"contao/manager-plugin": "^2.3.1",
"contao/test-case": "^5.1",
"phpunit/phpunit": "^9.5",
"symfony/http-client": "^5.4 || ^6.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0"
},
"conflict": {
"contao/core": "*",
Expand All @@ -29,19 +43,25 @@
"Oveleon\\ContaoGoogleRecommendationBundle\\": "src/"
},
"classmap": [
"src/Resources/contao/"
"contao/"
],
"exclude-from-classmap": [
"src/Resources/contao/config/",
"src/Resources/contao/dca/",
"src/Resources/contao/languages/",
"src/Resources/contao/templates/"
"contao/config/",
"contao/dca/",
"contao/languages/",
"contao/templates/"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-main": "1.3.x-dev"
},
"contao-manager-plugin": "Oveleon\\ContaoGoogleRecommendationBundle\\ContaoManager\\Plugin"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"contao/manager-plugin": true
}
}
}
9 changes: 9 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: true

Oveleon\ContaoGoogleRecommendationBundle\:
resource: '../src/'
exclude: '../src/{Model,DependencyInjection,Resources}'
9 changes: 9 additions & 0 deletions contao/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Oveleon\ContaoGoogleRecommendationBundle\GooglePlacesApi;

// Back end modules
$GLOBALS['BE_MOD']['content']['recommendation']['startSync'] = [GooglePlacesApi::class, 'syncWithGoogle'];
$GLOBALS['BE_MOD']['content']['recommendation']['syncAllArchives'] = [GooglePlacesApi::class, 'syncAllArchives'];
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?php

/*
* This file is part of Oveleon Google Recommendation Bundle.
*
* (c) https://www.oveleon.de/
*/

$GLOBALS['TL_DCA']['tl_recommendation']['fields']['googleAuthorUrl'] = array
(
use Contao\CoreBundle\DataContainer\PaletteManipulator;

$GLOBALS['TL_DCA']['tl_recommendation']['fields']['googleAuthorUrl'] = [
'exclude' => true,
'inputType' => 'text',
'eval' => array('maxlength'=>255, 'tl_class'=>'w50'),
'eval' => ['maxlength'=>255, 'tl_class'=>'w50'],
'sql' => "varchar(255) NOT NULL default ''"
);
];

// Extend the default palette
Contao\CoreBundle\DataContainer\PaletteManipulator::create()
->addLegend('google_legend', 'expert_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_BEFORE)
->addField(array('googleAuthorUrl'), 'google_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND)
PaletteManipulator::create()
->addLegend('google_legend', 'expert_legend', PaletteManipulator::POSITION_BEFORE)
->addField(array('googleAuthorUrl'), 'google_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', 'tl_recommendation')
;
73 changes: 73 additions & 0 deletions contao/dca/tl_recommendation_archive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
* This file is part of Oveleon Google Recommendation Bundle.
*
* (c) https://www.oveleon.de/
*/

use Contao\CoreBundle\DataContainer\PaletteManipulator;
use Contao\System;
use Oveleon\ContaoGoogleRecommendationBundle\EventListener\DataContainer\RecommendationArchiveListener;

// Load language files
System::loadLanguageFile('tl_recommendation_languages');

// Add global operations
$GLOBALS['TL_DCA']['tl_recommendation_archive']['list']['global_operations']['syncAllArchives'] = [
'href' => 'key=syncAllArchives',
'icon' => 'sync.svg',
'attributes' => 'onclick="if(!confirm(\'' . ($GLOBALS['TL_LANG']['tl_recommendation_archive']['syncAllConfirm'] ?? null) . '\'))return false;Backend.getScrollOffset()"',
];

// Add operations
$GLOBALS['TL_DCA']['tl_recommendation_archive']['list']['operations']['startSync'] = [
'href' => 'key=startSync',
'icon' => 'sync.svg',
'attributes' => 'onclick="if(!confirm(\'' . ($GLOBALS['TL_LANG']['tl_recommendation_archive']['syncConfirm'] ?? null) . '\'))return false;Backend.getScrollOffset()"',
'button_callback' => [RecommendationArchiveListener::class, 'addSyncButton'],
];

// Add subpalettes
$GLOBALS['TL_DCA']['tl_recommendation_archive']['fields']['syncWithGoogle'] = [
'exclude' => true,
'inputType' => 'checkbox',
'eval' => ['submitOnChange'=>true],
'sql' => "char(1) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_recommendation_archive']['fields']['googleApiToken'] = [
'exclude' => true,
'inputType' => 'text',
'eval' => ['doNotCopy'=>true, 'mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'w50'],
'sql' => "varchar(255) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_recommendation_archive']['fields']['googlePlaceId'] = [
'exclude' => true,
'inputType' => 'text',
'eval' => ['doNotCopy'=>true, 'mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'w50'],
'sql' => "varchar(255) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_recommendation_archive']['fields']['syncLanguage'] = [
'exclude' => true,
'inputType' => 'select',
'options_callback' => static function ()
{
return array_keys($GLOBALS['TL_LANG']['tl_recommendation_languages']);
},
'reference' => &$GLOBALS['TL_LANG']['tl_recommendation_languages'],
'eval' => ['doNotCopy'=>true, 'includeBlankOption'=>true, 'chosen'=>true,'tl_class'=>'w50'],
'sql' => "varchar(5) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_recommendation_archive']['palettes']['__selector__'][] = 'syncWithGoogle';
$GLOBALS['TL_DCA']['tl_recommendation_archive']['subpalettes']['syncWithGoogle'] = 'googleApiToken,googlePlaceId,syncLanguage';

// Extend the default palette
PaletteManipulator::create()
->addLegend('google_legend', 'protected_legend')
->addField(['syncWithGoogle'], 'google_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', 'tl_recommendation_archive')
;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/tl_recommendation.php" source-language="en" target-language="de">
<file datatype="php" original="contao/languages/en/tl_recommendation.php" source-language="en" target-language="de">
<body>
<trans-unit id="tl_recommendation.googleAuthorUrl.0">
<source>Google author url</source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/tl_recommendation_archive.php" source-language="en" target-language="de">
<file datatype="php" original="contao/languages/en/tl_recommendation_archive.php" source-language="en" target-language="de">
<body>
<trans-unit id="tl_recommendation_archive.syncAllArchives">
<source>Sync all archives</source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/tl_recommendation_languages_languages.php" source-language="en" target-language="de">
<file datatype="php" original="contao/languages/en/tl_recommendation_languages_languages.php" source-language="en" target-language="de">
<body>
<trans-unit id="tl_recommendation_languages.af">
<source>Afrikaans</source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/tl_recommendation.php" source-language="en">
<file datatype="php" original="contao/languages/en/tl_recommendation.php" source-language="en">
<body>
<trans-unit id="tl_recommendation.googleAuthorUrl.0">
<source>Google author url</source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/tl_recommendation_archive.php" source-language="en">
<file datatype="php" original="contao/languages/en/tl_recommendation_archive.php" source-language="en">
<body>
<trans-unit id="tl_recommendation_archive.syncAllArchives">
<source>Sync all archives</source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="src/Resources/contao/languages/en/tl_recommendation_languages_languages.php" source-language="en">
<file datatype="php" original="contao/languages/en/tl_recommendation_languages_languages.php" source-language="en">
<body>
<trans-unit id="tl_recommendation_languages.af">
<source>Afrikaans</source>
Expand Down
21 changes: 21 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
<env name="SYMFONY_PATCH_TYPE_DECLARATIONS" value="deprecations=0"/>
</php>
<testsuites>
<testsuite name="contao-google-recommendation-bundle">
<directory>./tests</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
File renamed without changes
11 changes: 5 additions & 6 deletions src/ContaoGoogleRecommendationBundle.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of Oveleon Recommendation Bundle.
* This file is part of Oveleon Google Recommendation Bundle.
*
* (c) https://www.oveleon.de/
*/
Expand All @@ -10,11 +10,10 @@

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Configures the Contao google recommendation bundle.
*
* @author Fabian Ekert <[email protected]>
*/
class ContaoGoogleRecommendationBundle extends Bundle
{
public function getPath(): string
{
return \dirname(__DIR__);
}
}
5 changes: 0 additions & 5 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
use Oveleon\ContaoGoogleRecommendationBundle\ContaoGoogleRecommendationBundle;
use Oveleon\ContaoRecommendationBundle\ContaoRecommendationBundle;

/**
* Plugin for the Contao Manager.
*
* @author Fabian Ekert <[email protected]>
*/
class Plugin implements BundlePluginInterface
{
/**
Expand Down
29 changes: 29 additions & 0 deletions src/Cron/GetGoogleReviewsCron.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

/*
* This file is part of Oveleon Google Recommendation Bundle.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoGoogleRecommendationBundle\Cron;

use Contao\CoreBundle\DependencyInjection\Attribute\AsCronJob;
use Contao\CoreBundle\Framework\ContaoFramework;
use Oveleon\ContaoGoogleRecommendationBundle\GooglePlacesApi;
use Psr\Log\LoggerInterface;

#[AsCronJob('daily')]
class GetGoogleReviewsCron
{
public function __construct(private ContaoFramework $framework, private LoggerInterface|null $logger)
{
}

public function __invoke(): void
{
(new GooglePlacesApi)->getGoogleReviews();
}
}
26 changes: 26 additions & 0 deletions src/DependencyInjection/ContaoGoogleRecommendationExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of Oveleon Google Recommendation Bundle.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoGoogleRecommendationBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class ContaoGoogleRecommendationExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader->load('services.yaml');
}
}
Loading

0 comments on commit f9fe1aa

Please sign in to comment.