Skip to content

Commit

Permalink
Merge pull request #195 from jstnthms/master
Browse files Browse the repository at this point in the history
Bundle configuration for visible mime types
  • Loading branch information
helios-ag committed Dec 8, 2015
2 parents 14c78d2 + 3ff9a11 commit b0dd43a
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Controller/ElFinderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
$pathPrefix = $parameters['path_prefix'];
$includeAssets = $parameters['include_assets'];
$theme = $parameters['theme'];
// convert to javascript array
$onlyMimes = count($parameters['visible_mime_types'])
? "['".implode("','", $parameters['visible_mime_types'])."']"
: '[]';
$result = array();

switch ($editor) {
Expand All @@ -79,6 +83,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
'prefix' => $assetsPath,
'theme' => $theme,
'pathPrefix' => $pathPrefix,
'onlyMimes' => $onlyMimes,
);

return $result;
Expand All @@ -94,6 +99,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
'prefix' => $assetsPath,
'theme' => $theme,
'pathPrefix' => $pathPrefix,
'onlyMimes' => $onlyMimes,
);

return $result;
Expand All @@ -109,6 +115,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
'prefix' => $assetsPath,
'theme' => $theme,
'pathPrefix' => $pathPrefix,
'onlyMimes' => $onlyMimes,
);

return $result;
Expand All @@ -123,6 +130,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
'prefix' => $assetsPath,
'theme' => $theme,
'pathPrefix' => $pathPrefix,
'onlyMimes' => $onlyMimes,
);

return $result;
Expand All @@ -137,6 +145,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
'prefix' => $assetsPath,
'theme' => $theme,
'pathPrefix' => $pathPrefix,
'onlyMimes' => $onlyMimes,
);

return $result;
Expand All @@ -151,6 +160,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
'prefix' => $assetsPath,
'theme' => $theme,
'pathPrefix' => $pathPrefix,
'onlyMimes' => $onlyMimes,
);

return $result;
Expand All @@ -167,6 +177,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
'prefix' => $assetsPath,
'theme' => $theme,
'pathPrefix' => $pathPrefix,
'onlyMimes' => $onlyMimes,
);

return $result;
Expand All @@ -179,6 +190,7 @@ private function selectEditor($parameters, $instance, $homeFolder, $assetsPath,
'instance' => $instance,
'homeFolder' => $homeFolder,
'prefix' => $assetsPath,
'onlyMimes' => $onlyMimes,
);

return $result;
Expand Down
10 changes: 10 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public function getConfigTreeBuilder()
->scalarNode('tinymce_popup_path')->defaultValue('')->end()
->booleanNode('relative_path')->defaultTrue()->end()
->scalarNode('path_prefix')->defaultValue('/')->end()
->arrayNode('visible_mime_types')
->beforeNormalization()
->ifTrue(function ($v) { return is_string($v); })
->then(function ($v) {
return array_map('trim', explode(',', $v));
})
->end()
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('connector')
->addDefaultsIfNotSet()
->fixXmlConfig('root')
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ fm_elfinder:
#fullscreen: true|false # defaults true, applies to simple and ckeditor editors
#theme: smoothness # jquery theme, default is 'smoothness'
include_assets: true # disable if you want to handle loading of the javascript and css assets yourself
#visible_mime_types: ['image/png', 'image/jpg', 'image/jpeg'] # only show these mime types, defaults to show all
connector:
#debug: true|false # defaults to false
roots: # at least one root must be defined
Expand Down
1 change: 1 addition & 0 deletions Resources/views/Elfinder/ckeditor.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
var f = $('.elfinder').elfinder({
url : '{{path('ef_connect', {'instance': instance, 'homeFolder': homeFolder })}}'+'?mode='+mode,
lang : '{{locale}}',
onlyMimes: {{ onlyMimes|raw }},
getFileCallback : function(file) {
if (funcNum) {
{% if relative_path %}
Expand Down
1 change: 1 addition & 0 deletions Resources/views/Elfinder/elfinder_type.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var $f = $('.elfinder').elfinder({
url : '{{path('ef_connect', { 'instance': instance, 'homeFolder': homeFolder } )}}',
lang : '{{locale}}',
onlyMimes: {{ onlyMimes|raw }},
getFileCallback: function(file) {
{% if relative_path %}
window.opener.setValue('{{ pathPrefix }}'+file.url.replace("{{ app.request.schemeAndHttpHost }}/", ""), "{{ id }}");
Expand Down
1 change: 1 addition & 0 deletions Resources/views/Elfinder/fm_tinymce.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// set your elFinder options here
url: '{{ path('ef_connect', {'instance': instance, 'homeFolder': homeFolder }) }}', // connector URL
lang : '{{ locale }}',
onlyMimes: {{ onlyMimes|raw }},
getFileCallback: function(file) { // editor callback
{% if relative_path %}
file.url = '{{ pathPrefix }}' + file.url.replace("{{ app.request.schemeAndHttpHost }}/", "");
Expand Down
3 changes: 2 additions & 1 deletion Resources/views/Elfinder/simple.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
$().ready(function() {
var $f = $('.elfinder').elfinder({
url : '{{path('ef_connect', { 'instance': instance, 'homeFolder': homeFolder } )}}',
lang : '{{locale}}'
lang : '{{locale}}',
onlyMimes: {{ onlyMimes|raw }}
});
{% if fullscreen %}
Expand Down
1 change: 1 addition & 0 deletions Resources/views/Elfinder/summernote.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var elf = $('.elfinder').elfinder({
url : '{{ path('ef_connect', {'instance': instance, 'homeFolder': homeFolder }) }}', // connector URL
lang : '{{locale}}',
onlyMimes: {{ onlyMimes|raw }},
destroyOnClose : true,
getFileCallback : function(files, fm) {
window.opener.$('.summernote').summernote('editor.insertImage',files.url);
Expand Down
1 change: 1 addition & 0 deletions Resources/views/Elfinder/tinymce.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
var f = $('.elfinder').elfinder({
url : '{{ path('ef_connect', {'instance': instance, 'homeFolder': homeFolder }) }}',
lang : '{{ locale }}',
onlyMimes: {{ onlyMimes|raw }},
getfile : {
onlyURL : true,
multiple : false,
Expand Down
1 change: 1 addition & 0 deletions Resources/views/Elfinder/tinymce4.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// set your elFinder options here
url: '{{ path('ef_connect', {'instance': instance, 'homeFolder': homeFolder }) }}', // connector URL
lang : '{{ locale }}',
onlyMimes: {{ onlyMimes|raw }},
getFileCallback: function(file) { // editor callback
{% if relative_path %}
FileBrowserDialogue.mySubmit('{{ pathPrefix }}'+file.url.replace("{{ app.request.schemeAndHttpHost }}/", "")); // pass selected file path to TinyMCE
Expand Down
1 change: 1 addition & 0 deletions Tests/DependencyInjection/ConfigurationLoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function testSupportsAllConfigFormats($path)
'tinymce_popup_path' => '/pop-up',
'relative_path' => false,
'path_prefix' => '/',
'visible_mime_types' => array(),
'connector' => array(
'debug' => true,
'binds' => array(),
Expand Down

0 comments on commit b0dd43a

Please sign in to comment.