Rework frontend integration callback class to a listener service.

This commit is contained in:
David Molineus
2017-10-06 14:06:20 +02:00
parent f03ed713f3
commit ad5e30fd09
4 changed files with 15 additions and 21 deletions

View File

@@ -10,9 +10,10 @@
* @filesource * @filesource
*/ */
namespace Netzmacht\Contao\Leaflet\Dca; declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
use Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory;
use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder; use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\Leaflet\Model\MapModel; use Netzmacht\Contao\Leaflet\Model\MapModel;
use Symfony\Component\Translation\TranslatorInterface as Translator; use Symfony\Component\Translation\TranslatorInterface as Translator;
@@ -22,7 +23,7 @@ use Symfony\Component\Translation\TranslatorInterface as Translator;
* *
* @package Netzmacht\Contao\Leaflet\Dca * @package Netzmacht\Contao\Leaflet\Dca
*/ */
class FrontendIntegration final class FrontendIntegrationListener
{ {
/** /**
* Translator. * Translator.
@@ -41,24 +42,12 @@ class FrontendIntegration
$this->translator = $translator; $this->translator = $translator;
} }
/**
* Generate the callback definition.
*
* @param string $methodName Callback method name.
*
* @return callable
*/
public static function callback($methodName)
{
return CallbackFactory::service('leaflet.dca.frontend-integration', $methodName);
}
/** /**
* Get all leaflet maps. * Get all leaflet maps.
* *
* @return array * @return array
*/ */
public function getMaps() public function getMaps(): array
{ {
$collection = MapModel::findAll(); $collection = MapModel::findAll();
@@ -72,7 +61,7 @@ class FrontendIntegration
* *
* @return string * @return string
*/ */
public function getEditMapLink($dataContainer) public function getEditMapLink($dataContainer): string
{ {
if ($dataContainer->value < 1) { if ($dataContainer->value < 1) {
return ''; return '';

View File

@@ -10,6 +10,11 @@ services:
arguments: arguments:
- '@translator' - '@translator'
netzmacht.contao_leaflet_maps.listeners.dca.frontend_integration:
class: Netzmacht\Contao\Leaflet\Listener\Dca\FrontendIntegrationListener
arguments:
- '@translator'
netzmacht.contao_leaflet_maps.listeners.dca.map: netzmacht.contao_leaflet_maps.listeners.dca.map:
class: Netzmacht\Contao\Leaflet\Listener\Dca\MapDcaListener class: Netzmacht\Contao\Leaflet\Listener\Dca\MapDcaListener
arguments: arguments:

View File

@@ -23,9 +23,9 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_map'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_content']['leaflet_map'], 'label' => &$GLOBALS['TL_LANG']['tl_content']['leaflet_map'],
'inputType' => 'select', 'inputType' => 'select',
'exclude' => true, 'exclude' => true,
'options_callback' => \Netzmacht\Contao\Leaflet\Dca\FrontendIntegration::callback('getMaps'), 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.frontend_integration', 'getMaps'],
'wizard' => array( 'wizard' => array(
\Netzmacht\Contao\Leaflet\Dca\FrontendIntegration::callback('getEditMapLink'), ['netzmacht.contao_leaflet_maps.listeners.dca.frontend_integration', 'getEditMapLink'],
), ),
'eval' => array( 'eval' => array(
'tl_class' => 'w50 wizard', 'tl_class' => 'w50 wizard',

View File

@@ -23,9 +23,9 @@ $GLOBALS['TL_DCA']['tl_module']['fields']['leaflet_map'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_module']['leaflet_map'], 'label' => &$GLOBALS['TL_LANG']['tl_module']['leaflet_map'],
'inputType' => 'select', 'inputType' => 'select',
'exclude' => true, 'exclude' => true,
'options_callback' => \Netzmacht\Contao\Leaflet\Dca\FrontendIntegration::callback('getMaps'), 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.frontend_integration', 'getMaps'],
'wizard' => array( 'wizard' => array(
\Netzmacht\Contao\Leaflet\Dca\FrontendIntegration::callback('getEditMapLink'), ['netzmacht.contao_leaflet_maps.listeners.dca.frontend_integration', 'getEditMapLink'],
), ),
'eval' => array( 'eval' => array(
'tl_class' => 'w50 wizard', 'tl_class' => 'w50 wizard',