forked from Snck3rs/contao-leaflet-maps
Refactor frontend integration using dependency injection.
This commit is contained in:
@@ -14,6 +14,7 @@ use Netzmacht\Contao\Leaflet\Alias\DefaultAliasFilter;
|
||||
use Netzmacht\Contao\Leaflet\Boot;
|
||||
use Netzmacht\Contao\Leaflet\ContaoAssets;
|
||||
use Netzmacht\Contao\Leaflet\Dca\ControlCallbacks;
|
||||
use Netzmacht\Contao\Leaflet\Dca\FrontendIntegration;
|
||||
use Netzmacht\Contao\Leaflet\Dca\LayerCallbacks;
|
||||
use Netzmacht\Contao\Leaflet\Dca\MapCallbacks;
|
||||
use Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices;
|
||||
@@ -199,6 +200,19 @@ $container['leaflet.dca.control-callbacks'] = $container->share(
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Callback helper class for frontend integration.
|
||||
*
|
||||
* @return FrontendIntegration
|
||||
*/
|
||||
$container['leaflet.dca.frontend-integration'] = $container->share(
|
||||
function ($container) {
|
||||
return new FrontendIntegration(
|
||||
$container[Services::TRANSLATOR]
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Component factory for content element.
|
||||
*
|
||||
|
||||
@@ -22,9 +22,9 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_map'] = array(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_content']['leaflet_map'],
|
||||
'inputType' => 'select',
|
||||
'exclude' => true,
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getMaps'),
|
||||
'options_callback' => \Netzmacht\Contao\Leaflet\Dca\FrontendIntegration::callback('getMaps'),
|
||||
'wizard' => array(
|
||||
array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getEditMapLink'),
|
||||
\Netzmacht\Contao\Leaflet\Dca\FrontendIntegration::callback('getEditMapLink'),
|
||||
),
|
||||
'eval' => array(
|
||||
'tl_class' => 'w50 wizard',
|
||||
|
||||
@@ -22,9 +22,9 @@ $GLOBALS['TL_DCA']['tl_module']['fields']['leaflet_map'] = array(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_module']['leaflet_map'],
|
||||
'inputType' => 'select',
|
||||
'exclude' => true,
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getMaps'),
|
||||
'options_callback' => \Netzmacht\Contao\Leaflet\Dca\FrontendIntegration::callback('getMaps'),
|
||||
'wizard' => array(
|
||||
array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getEditMapLink'),
|
||||
\Netzmacht\Contao\Leaflet\Dca\FrontendIntegration::callback('getEditMapLink'),
|
||||
),
|
||||
'eval' => array(
|
||||
'tl_class' => 'w50 wizard',
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
use ContaoCommunityAlliance\Translator\TranslatorInterface as Translator;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
|
||||
@@ -21,6 +23,35 @@ use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
*/
|
||||
class FrontendIntegration
|
||||
{
|
||||
/**
|
||||
* Translator.
|
||||
*
|
||||
* @var Translator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* FrontendIntegration constructor.
|
||||
*
|
||||
* @param Translator $translator Translator.
|
||||
*/
|
||||
public function __construct(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.
|
||||
*
|
||||
@@ -39,8 +70,6 @@ class FrontendIntegration
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function getEditMapLink($dataContainer)
|
||||
{
|
||||
@@ -53,23 +82,23 @@ class FrontendIntegration
|
||||
|
||||
return sprintf(
|
||||
'<a href="%s%s&popup=1&rt=%s" %s>%s</a>',
|
||||
'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=',
|
||||
'contao/main.php?do=leaflet_map&table=tl_leaflet_map&act=edit&id=',
|
||||
$dataContainer->value,
|
||||
\RequestToken::get(),
|
||||
sprintf(
|
||||
$pattern,
|
||||
specialchars(sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)),
|
||||
specialchars($this->translator->translate('editalias.1', 'tl_content', [$dataContainer->value])),
|
||||
specialchars(
|
||||
str_replace(
|
||||
"'",
|
||||
"\\'",
|
||||
sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)
|
||||
sprintf($this->translator->translate('editalias.1', 'tl_content', [$dataContainer->value]))
|
||||
)
|
||||
)
|
||||
),
|
||||
\Image::getHtml(
|
||||
'alias.gif',
|
||||
$GLOBALS['TL_LANG']['tl_content']['editalias'][0],
|
||||
$this->translator->translate('editalias.0', 'tl_content', [$dataContainer->value]),
|
||||
'style="vertical-align:top"'
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user