From 9e1c8499f259a38c276611f0e779bc17ee668385 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 7 Jan 2015 11:13:15 +0100 Subject: [PATCH] Improve backend content element handling. --- module/dca/tl_content.php | 5 +++- src/Netzmacht/Contao/Leaflet/Dca/Content.php | 30 +++++++++++++++++++ .../Contao/Leaflet/LeafletMapElement.php | 26 ++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/module/dca/tl_content.php b/module/dca/tl_content.php index 05e24a3..fe6f1d5 100644 --- a/module/dca/tl_content.php +++ b/module/dca/tl_content.php @@ -14,8 +14,11 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_map'] = array( 'inputType' => 'select', 'exclude' => true, 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Content', 'getMaps'), + 'wizard' => array( + array('Netzmacht\Contao\Leaflet\Dca\Content', 'getEditMapLink'), + ), 'eval' => array( - 'tl_class' => 'w50', + 'tl_class' => 'w50 wizard', 'chosen' => true, ), 'sql' => "int(10) unsigned NOT NULL default '0'" diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Content.php b/src/Netzmacht/Contao/Leaflet/Dca/Content.php index 3c78c4c..f33e35c 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/Content.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/Content.php @@ -37,4 +37,34 @@ class Content return $options; } + + public function getEditMapLink($dataContainer) + { + if ($dataContainer->value < 1) { + return ''; + } + + return sprintf( + '%s', + 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=', + $dataContainer->value, + \RequestToken::get(), + sprintf( + 'title="%s" style="padding-left: 3px" ' + . 'onclick="Backend.openModalIframe({\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"', + specialchars(sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)), + specialchars( + str_replace( + "'", + "\\'", + sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value) + ) + ) + ), + \Image::getHtml( + 'alias.gif', + $GLOBALS['TL_LANG']['tl_content']['editalias'][0], 'style="vertical-align:top"' + ) + ); + } } diff --git a/src/Netzmacht/Contao/Leaflet/LeafletMapElement.php b/src/Netzmacht/Contao/Leaflet/LeafletMapElement.php index b15f878..deaa61c 100644 --- a/src/Netzmacht/Contao/Leaflet/LeafletMapElement.php +++ b/src/Netzmacht/Contao/Leaflet/LeafletMapElement.php @@ -11,6 +11,9 @@ namespace Netzmacht\Contao\Leaflet; +use Netzmacht\Contao\Leaflet\Mapper\MapMapper; +use Netzmacht\Contao\Leaflet\Model\MapModel; + /** * @property int leaflet_map */ @@ -41,6 +44,29 @@ class LeafletMapElement extends \ContentElement $this->mapService = $GLOBALS['container']['leaflet.map.service']; } + public function generate() + { + if (TL_MODE === 'BE') { + $model = MapModel::findByPK($this->leaflet_map); + + $template = new \BackendTemplate('be_wildcard'); + + if ($model) { + $href = 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=' . $model->id; + + $template->wildcard = '### LEAFLET MAP ' . $model->title . ' ###'; + $template->title = $this->headline; + $template->id = $model->id; + $template->link = $model->title; + $template->href = $href; + } + + return $template->parse(); + } + + return parent::generate(); + } + /** * Compile the content element. *