From 7655f003543ad54d9fea8958cf6871733a4becb9 Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Fri, 21 Jul 2017 21:09:16 +0200 Subject: [PATCH] Fix two issues with the file picker provider. --- src/Picker/FilePickerProvider.php | 5 ++++- src/Resources/public/core.js | 2 +- src/Resources/public/core.min.js | 4 ++-- tests/Picker/FilePickerProviderTest.php | 9 +++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Picker/FilePickerProvider.php b/src/Picker/FilePickerProvider.php index 3561f60429..b480f7336a 100644 --- a/src/Picker/FilePickerProvider.php +++ b/src/Picker/FilePickerProvider.php @@ -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) { diff --git a/src/Resources/public/core.js b/src/Resources/public/core.js index 782dbca9de..9a7f94c7c9 100644 --- a/src/Resources/public/core.js +++ b/src/Resources/public/core.js @@ -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(','); } diff --git a/src/Resources/public/core.min.js b/src/Resources/public/core.min.js index d5fd4d8534..2d5ffa6ea3 100644 --- a/src/Resources/public/core.min.js +++ b/src/Resources/public/core.min.js @@ -1,2 +1,2 @@ -var AjaxRequest={themePath:Contao.script_url+"system/themes/"+Contao.theme+"/",toggleNavigation:function(e,t,n){e.blur();var a=$(t),o=$(e).getParent("li");return!!a&&(o.hasClass("node-collapsed")?(a.setStyle("display",null),o.removeClass("node-collapsed").addClass("node-expanded"),$(e).store("tip:title",Contao.lang.collapse),new Request.Contao({url:n}).post({action:"toggleNavigation",id:t,state:1,REQUEST_TOKEN:Contao.request_token})):(a.setStyle("display","none"),o.removeClass("node-expanded").addClass("node-collapsed"),$(e).store("tip:title",Contao.lang.expand),new Request.Contao({url:n}).post({action:"toggleNavigation",id:t,state:0,REQUEST_TOKEN:Contao.request_token})),!1)},toggleStructure:function(e,t,n,a){e.blur();var o=$(t),i=$(e).getFirst("img");return o?("none"==o.getStyle("display")?(o.setStyle("display",null),i.src=AjaxRequest.themePath+"icons/folMinus.svg",$(e).store("tip:title",Contao.lang.collapse),new Request.Contao({field:e}).post({action:"toggleStructure",id:t,state:1,REQUEST_TOKEN:Contao.request_token})):(o.setStyle("display","none"),i.src=AjaxRequest.themePath+"icons/folPlus.svg",$(e).store("tip:title",Contao.lang.expand),new Request.Contao({field:e}).post({action:"toggleStructure",id:t,state:0,REQUEST_TOKEN:Contao.request_token})),!1):(new Request.Contao({field:e,evalScripts:!0,onRequest:AjaxRequest.displayBox(Contao.lang.loading+" …"),onSuccess:function(o){var l=new Element("li",{id:t,class:"parent",styles:{display:"inline"}});if(new Element("ul",{class:"level_"+n,html:o}).inject(l,"bottom"),5==a)l.inject($(e).getParent("li"),"after");else{for(var s,c=!1,r=$(e).getParent("li");"element"==typeOf(r)&&(s=r.getNext("li"));)if(r=s,r.hasClass("tl_folder")){c=!0;break}c?l.inject(r,"before"):l.inject(r,"after")}l.getElements("a").each(function(e){e.href=e.href.replace(/&ref=[a-f0-9]+/,"&ref="+Contao.referer_id)}),$(e).store("tip:title",Contao.lang.collapse),i.src=AjaxRequest.themePath+"icons/folMinus.svg",window.fireEvent("structure"),AjaxRequest.hideBox(),window.fireEvent("ajax_change")}}).post({action:"loadStructure",id:t,level:n,state:1,REQUEST_TOKEN:Contao.request_token}),!1)},toggleFileManager:function(e,t,n,a){e.blur();var o=$(t),i=$(e).getFirst("img");return o?("none"==o.getStyle("display")?(o.setStyle("display",null),i.src=AjaxRequest.themePath+"icons/folMinus.svg",$(e).store("tip:title",Contao.lang.collapse),new Request.Contao({field:e}).post({action:"toggleFileManager",id:t,state:1,REQUEST_TOKEN:Contao.request_token})):(o.setStyle("display","none"),i.src=AjaxRequest.themePath+"icons/folPlus.svg",$(e).store("tip:title",Contao.lang.expand),new Request.Contao({field:e}).post({action:"toggleFileManager",id:t,state:0,REQUEST_TOKEN:Contao.request_token})),!1):(new Request.Contao({field:e,evalScripts:!0,onRequest:AjaxRequest.displayBox(Contao.lang.loading+" …"),onSuccess:function(n){var o=new Element("li",{id:t,class:"parent",styles:{display:"inline"}});new Element("ul",{class:"level_"+a,html:n}).inject(o,"bottom"),o.inject($(e).getParent("li"),"after"),o.getElements("a").each(function(e){e.href=e.href.replace(/&ref=[a-f0-9]+/,"&ref="+Contao.referer_id)}),$(e).store("tip:title",Contao.lang.collapse),i.src=AjaxRequest.themePath+"icons/folMinus.svg",AjaxRequest.hideBox(),window.fireEvent("ajax_change")}}).post({action:"loadFileManager",id:t,level:a,folder:n,state:1,REQUEST_TOKEN:Contao.request_token}),!1)},togglePagetree:function(e,t,n,a,o){e.blur(),Backend.getScrollOffset();var i=$(t),l=$(e).getFirst("img");return i?("none"==i.getStyle("display")?(i.setStyle("display",null),l.src=AjaxRequest.themePath+"icons/folMinus.svg",$(e).store("tip:title",Contao.lang.collapse),new Request.Contao({field:e}).post({action:"togglePagetree",id:t,state:1,REQUEST_TOKEN:Contao.request_token})):(i.setStyle("display","none"),l.src=AjaxRequest.themePath+"icons/folPlus.svg",$(e).store("tip:title",Contao.lang.expand),new Request.Contao({field:e}).post({action:"togglePagetree",id:t,state:0,REQUEST_TOKEN:Contao.request_token})),!1):(new Request.Contao({field:e,evalScripts:!0,onRequest:AjaxRequest.displayBox(Contao.lang.loading+" …"),onSuccess:function(n){var a=new Element("li",{id:t,class:"parent",styles:{display:"inline"}});new Element("ul",{class:"level_"+o,html:n}).inject(a,"bottom"),a.inject($(e).getParent("li"),"after"),a.getElements("a").each(function(e){e.href=e.href.replace(/&ref=[a-f0-9]+/,"&ref="+Contao.referer_id)}),$(e).store("tip:title",Contao.lang.collapse),l.src=AjaxRequest.themePath+"icons/folMinus.svg",AjaxRequest.hideBox(),window.fireEvent("ajax_change")}}).post({action:"loadPagetree",id:t,level:o,field:n,name:a,state:1,REQUEST_TOKEN:Contao.request_token}),!1)},toggleFiletree:function(e,t,n,a,o,i){e.blur(),Backend.getScrollOffset();var l=$(t),s=$(e).getFirst("img");return l?("none"==l.getStyle("display")?(l.setStyle("display",null),s.src=AjaxRequest.themePath+"icons/folMinus.svg",$(e).store("tip:title",Contao.lang.collapse),new Request.Contao({field:e}).post({action:"toggleFiletree",id:t,state:1,REQUEST_TOKEN:Contao.request_token})):(l.setStyle("display","none"),s.src=AjaxRequest.themePath+"icons/folPlus.svg",$(e).store("tip:title",Contao.lang.expand),new Request.Contao({field:e}).post({action:"toggleFiletree",id:t,state:0,REQUEST_TOKEN:Contao.request_token})),!1):(new Request.Contao({field:e,evalScripts:!0,onRequest:AjaxRequest.displayBox(Contao.lang.loading+" …"),onSuccess:function(n){var a=new Element("li",{id:t,class:"parent",styles:{display:"inline"}});new Element("ul",{class:"level_"+i,html:n}).inject(a,"bottom"),a.inject($(e).getParent("li"),"after"),a.getElements("a").each(function(e){e.href=e.href.replace(/&ref=[a-f0-9]+/,"&ref="+Contao.referer_id)}),$(e).store("tip:title",Contao.lang.collapse),s.src=AjaxRequest.themePath+"icons/folMinus.svg",AjaxRequest.hideBox(),window.fireEvent("ajax_change")}}).post({action:"loadFiletree",id:t,folder:n,level:i,field:a,name:o,state:1,REQUEST_TOKEN:Contao.request_token}),!1)},toggleSubpalette:function(e,t,n){e.blur();var a=$(t);return a?void(e.value?(e.value="",e.checked="",a.setStyle("display","none"),a.getElements("[required]").each(function(e){e.set("required",null).set("data-required","")}),new Request.Contao({field:e}).post({action:"toggleSubpalette",id:t,field:n,state:0,REQUEST_TOKEN:Contao.request_token})):(e.value=1,e.checked="checked",a.setStyle("display",null),a.getElements("[data-required]").each(function(e){e.set("required","").set("data-required",null)}),new Request.Contao({field:e}).post({action:"toggleSubpalette",id:t,field:n,state:1,REQUEST_TOKEN:Contao.request_token}))):void new Request.Contao({field:e,evalScripts:!1,onRequest:AjaxRequest.displayBox(Contao.lang.loading+" …"),onSuccess:function(n,a){var o=new Element("div",{id:t,class:"subpal",html:n,styles:{display:"block"}}).inject($(e).getParent("div").getParent("div"),"after");a.javascript&&(document.write=function(e){var t="";e.replace(/