Skip to content

Commit

Permalink
Rewrite the DCA picker (see #950).
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp authored and leofeyer committed Jul 24, 2017
1 parent 2a85914 commit d9a7c8f
Show file tree
Hide file tree
Showing 54 changed files with 3,118 additions and 2,061 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Contao core bundle change log

### DEV

* Rewrite the DCA picker (see #950).

### 4.4.1 (2017-07-12)

* Prevent arbitrary PHP file inclusions in the back end (see CVE-2017-10993).
Expand Down
4 changes: 2 additions & 2 deletions src/ContaoCoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Contao\CoreBundle\DependencyInjection\Compiler\AddResourcesPathsPass;
use Contao\CoreBundle\DependencyInjection\Compiler\AddSessionBagsPass;
use Contao\CoreBundle\DependencyInjection\Compiler\DoctrineMigrationsPass;
use Contao\CoreBundle\DependencyInjection\Compiler\PickerMenuProviderPass;
use Contao\CoreBundle\DependencyInjection\Compiler\PickerProviderPass;
use Contao\CoreBundle\DependencyInjection\ContaoCoreExtension;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -63,6 +63,6 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new AddResourcesPathsPass());
$container->addCompilerPass(new AddImagineClassPass());
$container->addCompilerPass(new DoctrineMigrationsPass());
$container->addCompilerPass(new PickerMenuProviderPass());
$container->addCompilerPass(new PickerProviderPass());
}
}
26 changes: 23 additions & 3 deletions src/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
use Contao\BackendPopup;
use Contao\BackendPreview;
use Contao\BackendSwitch;
use Contao\CoreBundle\Picker\PickerConfig;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

/**
* Handles the Contao backend routes.
Expand Down Expand Up @@ -214,18 +216,36 @@ public function alertsAction()
}

/**
* Handles the picker redirect.
* Redirects the user to the Contao back end and includes the picker query parameter. It will determine
* the current provider URL based on the value (usually read dynamically via JavaScript).
*
* @param Request $request
*
* @throws BadRequestHttpException
*
* @return RedirectResponse
*
* @Route("/_contao/picker", name="contao_backend_picker")
*/
public function pickerAction(Request $request)
{
$pickerBuilder = $this->container->get('contao.menu.picker_menu_builder');
$extras = [];

if ($request->query->has('extras')) {
$extras = $request->query->get('extras');

if (!is_array($extras)) {
throw new BadRequestHttpException('Invalid picker extras');
}
}

$config = new PickerConfig($request->query->get('context'), $extras, $request->query->get('value'));
$picker = $this->container->get('contao.picker.builder')->create($config);

if (null === $picker) {
throw new BadRequestHttpException('Unsupported picker context');
}

return new RedirectResponse($pickerBuilder->getPickerUrl($request));
return new RedirectResponse($picker->getCurrentUrl());
}
}
29 changes: 0 additions & 29 deletions src/DataContainer/DcaFilterInterface.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Registers the picker menu providers.
* Registers the picker providers.
*
* @author Leo Feyer <https://github.com/leofeyer>
* @author Andreas Schempp <https://github.com/aschempp>
*/
class PickerMenuProviderPass implements CompilerPassInterface
class PickerProviderPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

Expand All @@ -28,12 +29,12 @@ class PickerMenuProviderPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('contao.menu.picker_menu_builder')) {
if (!$container->has('contao.picker.builder')) {
return;
}

$definition = $container->findDefinition('contao.menu.picker_menu_builder');
$references = $this->findAndSortTaggedServices('contao.picker_menu_provider', $container);
$definition = $container->findDefinition('contao.picker.builder');
$references = $this->findAndSortTaggedServices('contao.picker_provider', $container);

foreach ($references as $reference) {
$definition->addMethodCall('addProvider', [$reference]);
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/ContaoCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Contao\CoreBundle\DependencyInjection;

use Contao\CoreBundle\Menu\PickerMenuProviderInterface;
use Contao\CoreBundle\Picker\PickerProviderInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand Down Expand Up @@ -90,8 +90,8 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
$this->overwriteImageTargetDir($mergedConfig, $container);

$container
->registerForAutoconfiguration(PickerMenuProviderInterface::class)
->addTag('contao.picker_menu_provider')
->registerForAutoconfiguration(PickerProviderInterface::class)
->addTag('contao.picker_provider')
;
}

Expand Down
169 changes: 0 additions & 169 deletions src/Menu/AbstractMenuProvider.php

This file was deleted.

Loading

0 comments on commit d9a7c8f

Please sign in to comment.