Skip to content

WIP: Feature/contao55 #42

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
"require": {
"php": "^8.1",
"ext-json": "*",
"contao-components/colorpicker": "^1.5",
"contao/core-bundle": "^4.13 || ^5.0",
"symfony/asset": "^5.4 || ^6.0",
"symfony/config": "^5.4 || ^6.0",
"symfony/console": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Contao/Widgets/MultiColumnWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ protected function generateButtonString($level = 0)
$return .=
\sprintf(
'<a data-operations="%s" href="%s" class="widgetImage op-%s" title="%s"
onclick="return false;">%s</a>',
onclick="return false;" data-turbo-prefetch="false">%s</a>',
$button,
$this->addToUrl(
\sprintf(
Expand Down
2 changes: 2 additions & 0 deletions src/EventListener/Contao/InitializeSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace MenAtWork\MultiColumnWizardBundle\EventListener\Contao;

use Contao\CoreBundle\ContaoCoreBundle;
use Contao\Environment;
use Contao\Input;
use Contao\System;
Expand All @@ -40,6 +41,7 @@ class InitializeSystem

/**
* @param ContaoApiService $contaoApi
* @param Packages $packages
*/
public function __construct(ContaoApiService $contaoApi)
{
Expand Down
51 changes: 48 additions & 3 deletions src/EventListener/Mcw/ColorPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@

namespace MenAtWork\MultiColumnWizardBundle\EventListener\Mcw;

use Contao\CoreBundle\ContaoCoreBundle;
use Contao\CoreBundle\Framework\Adapter;
use Contao\Image;
use Contao\StringUtil;
use MenAtWork\MultiColumnWizardBundle\Event\GetColorPickerStringEvent;
use MenAtWork\MultiColumnWizardBundle\Service\ContaoApiService;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Class ColorPicker
*/
class ColorPicker
{
static private $jsLoaded = false;

/**
* Adapter to the image class.
*
Expand All @@ -55,6 +59,13 @@ class ColorPicker
*/
private $translator;

/**
* Some functions to work with contao.
*
* @var ContaoApiService
*/
private $contaoApi;

/**
* ColorPicker constructor.
*
Expand All @@ -64,11 +75,43 @@ class ColorPicker
*
* @param TranslatorInterface $translator Translator class.
*/
public function __construct($imageAdapter, $stringUtilAdapter, $translator)
public function __construct
(
$imageAdapter,
$stringUtilAdapter,
$translator,
ContaoApiService $contaoApi
)
{
$this->imageAdapter = $imageAdapter;
$this->imageAdapter = $imageAdapter;
$this->stringUtilAdapter = $stringUtilAdapter;
$this->translator = $translator;
$this->translator = $translator;
$this->contaoApi = $contaoApi;
}

/**
* Load the old mooRainbow picker in Contao 5.5
*
* @return void
*/
private function loadJs()
{
// Run only ones.
if(self::$jsLoaded === true ){
return;
}
self::$jsLoaded = true;

if (version_compare($this->contaoApi->getContaoVersion(), '5.5', '>=')) {
$GLOBALS['TL_JAVASCRIPT']['mooRainbow'] = $this->contaoApi->getFileUrl(
'js/mooRainbow.min.js',
'contao-components/colorpicker'
);
$GLOBALS['TL_CSS']['mooRainbow'] = $this->contaoApi->getFileUrl(
'css/mooRainbow.min.css',
'contao-components/colorpicker'
);
}
}

/**
Expand All @@ -80,6 +123,8 @@ public function __construct($imageAdapter, $stringUtilAdapter, $translator)
*/
public function executeEvent(GetColorPickerStringEvent $event)
{
$this->loadJs();

// Get some vars.
$fieldConfiguration = $event->getFieldConfiguration();
$fieldId = $event->getFieldId();
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/listener.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
- '@=service(''contao.framework'').getAdapter(''Contao\\Image'')'
- '@=service(''contao.framework'').getAdapter(''Contao\\StringUtil'')'
- "@translator"
- "@MenAtWork\MultiColumnWizardBundle\Service\ContaoApiService"
tags:
- name: kernel.event_listener
event: men-at-work.multi-column-wizard-bundle.get-color-picker
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
public: true
arguments:
- '@MenAtWork\MultiColumnWizardBundle\Service\ContaoApiService'
- '@assets.packages'

MenAtWork\MultiColumnWizardBundle\EventListener\Contao\LoadDataContainer:
public: true
Expand All @@ -22,3 +23,4 @@ services:
arguments:
- '@request_stack'
- '@contao.routing.scope_matcher'
- '@assets.packages'
2 changes: 1 addition & 1 deletion src/Resources/public/css/multicolumnwizard.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Resources/public/css/multicolumnwizard_src.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
height: auto;
}

.multicolumnwizard .tl_select,
.multicolumnwizard .tl_mselect {
.multicolumnwizard .tl_select:not(.choices),
.multicolumnwizard .tl_mselect:not(.choices) {
width: auto;
}

Expand Down
30 changes: 29 additions & 1 deletion src/Service/ContaoApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,34 @@

use Composer\InstalledVersions;
use Contao\CoreBundle\Routing\ScopeMatcher;
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\RequestStack;

class ContaoApiService
{
/**
* @var RequestStack
*/
private RequestStack $requestStack;

/**
* @var ScopeMatcher
*/
private ScopeMatcher $scopeMatcher;

/**
* @var Packages
*/
private Packages $packages;

public function __construct(
RequestStack $requestStack,
ScopeMatcher $scopeMatcher
ScopeMatcher $scopeMatcher,
Packages $packages
) {
$this->requestStack = $requestStack;
$this->scopeMatcher = $scopeMatcher;
$this->packages = $packages;
}

/**
Expand Down Expand Up @@ -77,4 +92,17 @@ public function getContaoVersion(): ?string
{
return InstalledVersions::getPrettyVersion('contao/core-bundle');
}

/**
* Returns the public path for a file.
*
* @param string $path
* @param string|null $packageName
*
* @return string
*/
public function getFileUrl(string $path, ?string $packageName = null): string
{
return $this->packages->getUrl($path, $packageName);
}
}
Loading