Skip to content

Commit

Permalink
Initialize tinyMCE file browser types in DataContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jul 12, 2017
1 parent c62f37c commit 1f24de0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
21 changes: 19 additions & 2 deletions src/Resources/contao/classes/DataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ abstract class DataContainer extends \Backend
protected $blnUploadable = false;

/**
* @var \Closure
* DCA Picker instance
* @var PickerInterface
*/
protected $objPicker;

/**
* Callback to convert DCA value to picker value
* @var callable
*/
protected $objPickerCallback;

Expand Down Expand Up @@ -557,17 +564,26 @@ protected function row($strPalette=null)
{
list ($file, $type) = explode('|', $arrData['eval']['rte'], 2);

$fileBrowserTypes = [];
$pickerBuilder = \System::getContainer()->get('contao.picker.builder');
foreach (['file' => 'image', 'link' => 'file'] as $context => $type) {
if ($pickerBuilder->supportsContext($context)) {
$fileBrowserTypes[] = $type;
}
}

/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_' . $file);
$objTemplate->selector = 'ctrl_' . $this->strInputName;
$objTemplate->type = $type;
$objTemplate->fileBrowserTypes = $fileBrowserTypes;

// Deprecated since Contao 4.0, to be removed in Contao 5.0
$objTemplate->language = \Backend::getTinyMceLanguage();

$updateMode = $objTemplate->parse();

unset($file, $type);
unset($file, $type, $pickerBuilder);
}

// Handle multi-select fields in "override all" mode
Expand Down Expand Up @@ -907,6 +923,7 @@ public function initPicker(PickerInterface $picker)

$attributes = $provider->getDcaAttributes($picker->getConfig());

$this->objPicker = $picker;
$this->strPickerFieldType = $attributes['fieldType'];
$this->objPickerCallback = function ($value) use ($picker, $provider) {
return $provider->convertDcaValue($picker->getConfig(), $value);
Expand Down
14 changes: 3 additions & 11 deletions src/Resources/contao/templates/backend/be_tinyFlash.html5
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
namespace Contao;

if ($GLOBALS['TL_CONFIG']['useRTE']):
$builder = \System::getContainer()->get('contao.picker.builder');
$pickerTypes = [];

if ($builder->supportsContext('file')) {
$pickerTypes[] = 'image';
}

if ($builder->supportsContext('link')) {
$pickerTypes[] = 'file';
}

?>
<script>window.tinymce || document.write('<script src="<?= TL_ASSETS_URL ?>assets/tinymce4/js/tinymce.gzip.js">\x3C/script>')</script>
Expand All @@ -35,7 +25,9 @@ setTimeout(function() {
}
editor.on('focus', function(){ Backend.getScrollOffset(); });
},
file_browser_callback_types: <?= json_encode($pickerTypes) ?>,
<?php if (is_array($this->fileBrowserTypes)): ?>
file_browser_callback_types: <?= json_encode($this->fileBrowserTypes) ?>,
<?php endif; ?>
file_browser_callback: function(field_name, url, type, win) {
Backend.openModalBrowser(field_name, url, type, win);
},
Expand Down
14 changes: 3 additions & 11 deletions src/Resources/contao/templates/backend/be_tinyMCE.html5
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
namespace Contao;

if ($GLOBALS['TL_CONFIG']['useRTE']):
$builder = \System::getContainer()->get('contao.picker.builder');
$pickerTypes = [];

if ($builder->supportsContext('file')) {
$pickerTypes[] = 'image';
}

if ($builder->supportsContext('link')) {
$pickerTypes[] = 'file';
}

?>
<script>window.tinymce || document.write('<script src="<?= TL_ASSETS_URL ?>assets/tinymce4/js/tinymce.gzip.js">\x3C/script>')</script>
Expand All @@ -34,7 +24,9 @@ setTimeout(function() {
}
editor.on('focus', function(){ Backend.getScrollOffset(); });
},
file_browser_callback_types: <?= json_encode($pickerTypes) ?>,
<?php if (is_array($this->fileBrowserTypes)): ?>
file_browser_callback_types: <?= json_encode($this->fileBrowserTypes) ?>,
<?php endif; ?>
file_browser_callback: function(field_name, url, type, win) {
Backend.openModalBrowser(field_name, url, type, win);
},
Expand Down
14 changes: 3 additions & 11 deletions src/Resources/contao/templates/backend/be_tinyNews.html5
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
namespace Contao;

if ($GLOBALS['TL_CONFIG']['useRTE']):
$builder = \System::getContainer()->get('contao.picker.builder');
$pickerTypes = [];

if ($builder->supportsContext('file')) {
$pickerTypes[] = 'image';
}

if ($builder->supportsContext('link')) {
$pickerTypes[] = 'file';
}

?>
<script>window.tinymce || document.write('<script src="<?= TL_ASSETS_URL ?>assets/tinymce4/js/tinymce.gzip.js">\x3C/script>')</script>
Expand All @@ -34,7 +24,9 @@ setTimeout(function() {
}
editor.on('focus', function(){ Backend.getScrollOffset(); });
},
file_browser_callback_types: <?= json_encode($pickerTypes) ?>,
<?php if (is_array($this->fileBrowserTypes)): ?>
file_browser_callback_types: <?= json_encode($this->fileBrowserTypes) ?>,
<?php endif; ?>
file_browser_callback: function(field_name, url, type, win) {
Backend.openModalBrowser(field_name, url, type, win);
},
Expand Down

0 comments on commit 1f24de0

Please sign in to comment.