Skip to content

Commit

Permalink
Fix two issues with the file picker provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jul 21, 2017
1 parent 3ddf78f commit 7655f00
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Picker/FilePickerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ public function getDcaAttributes(PickerConfig $config)
*/
public function convertDcaValue(PickerConfig $config, $value)
{
if ('file' === $config->getContext()) {
return $value;
}

/** @var FilesModel $filesAdapter */
$filesAdapter = $this->framework->getAdapter(FilesModel::class);

$filesModel = $filesAdapter->findByPath(rawurldecode($value));

if ($filesModel instanceof FilesModel) {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/public/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ var Backend =
Backend.openModalSelector({
'id': 'tl_listing',
'title': win.document.getElement('div.mce-title').get('text'),
'url': document.location.pathname.replace('/contao', '/_contao') + '/picker?context=' + (type == 'file' ? 'link' : 'file') + '&value=' + url + '&popup=1',
'url': document.location.pathname.replace('/contao', '/_contao') + '/picker?context=' + (type == 'file' ? 'link' : 'file') + '&extras[fieldType]=radio&extras[filesOnly]=true&value=' + url + '&popup=1',
'callback': function(table, value) {
win.document.getElementById(field_name).value = value.join(',');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/public/core.min.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions tests/Picker/FilePickerProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,18 @@ public function testGetDcaAttributes()
public function testConvertDcaValue()
{
$this->assertSame(
'{{file::82243f46-a4c3-11e3-8e29-000c29e44aea}}',
'/foobar',
$this->provider->convertDcaValue(new PickerConfig('file'), '/foobar')
);

$this->assertSame(
'{{file::82243f46-a4c3-11e3-8e29-000c29e44aea}}',
$this->provider->convertDcaValue(new PickerConfig('link'), '/foobar')
);

$this->assertSame(
'/foobar',
$this->provider->convertDcaValue(new PickerConfig('file'), '/foobar')
$this->provider->convertDcaValue(new PickerConfig('link'), '/foobar')
);
}
}

0 comments on commit 7655f00

Please sign in to comment.