Skip to content

Commit

Permalink
add frontend rename plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Jun 30, 2021
1 parent 33ac10c commit 076b05b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/download-cdn-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$files[] = "https://cdn.jsdelivr.net/gh/pqina/filepond-plugin-image-transform/dist/filepond-plugin-image-transform.min.js";
$files[] = "https://cdn.jsdelivr.net/gh/pqina/filepond-plugin-image-resize/dist/filepond-plugin-image-resize.min.js";
$files[] = "https://cdn.jsdelivr.net/gh/pqina/filepond-plugin-image-crop/dist/filepond-plugin-image-crop.min.js";
$files[] = "https://cdn.jsdelivr.net/gh/pqina/filepond-plugin-file-rename/dist/filepond-plugin-file-rename.min.js";
$files[] = "https://cdn.jsdelivr.net/gh/pqina/filepond/dist/filepond.min.css";
$files[] = "https://cdn.jsdelivr.net/gh/pqina/filepond/dist/filepond.min.js";

Expand Down
9 changes: 9 additions & 0 deletions javascript/FilePondField.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ function initFilePond() {
if (typeof FilePondPluginFileMetadata !== "undefined") {
FilePond.registerPlugin(FilePondPluginFileMetadata);
}
if (typeof FilePondPluginFileRename !== "undefined") {
FilePond.registerPlugin(FilePondPluginFileRename);
}
if (typeof FilePondPluginFilePoster !== "undefined") {
FilePond.registerPlugin(FilePondPluginFilePoster);
}
Expand Down Expand Up @@ -63,6 +66,12 @@ function attachFilePond(rootNode) {
if (typeof config["server"] === "string") {
config["server"] = window[config["server"]];
}
if (typeof config["fileRenameFunction"] === "string") {
var newName = config["fileRenameFunction"];
config["fileRenameFunction"] = function(file) {
return newName + file.extension;
}
}
for (var key in config) {
// We can set the properties directly in the instance
// @link https://pqina.nl/filepond/docs/patterns/api/filepond-instance/#properties
Expand Down
9 changes: 9 additions & 0 deletions javascript/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*!
* FilePondPluginFileRename 1.1.8
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/

/* eslint-disable */

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).FilePondPluginFileRename=n()}(this,function(){"use strict";var e=function(e){var n=e.addFilter,i=e.utils,t=i.Type,o=i.renameFile,u=i.isFile,a=i.getExtensionFromFilename,d=i.getFilenameWithoutExtension;return n("LOAD_FILE",function(e,n){var i=n.query;return new Promise(function(n,t){var l=i("GET_ALLOW_FILE_RENAME"),f=i("GET_FILE_RENAME_FUNCTION");if(u(e)&&l&&f){var r=f({name:e.name,basename:d(e.name),extension:".".concat(a(e.name))}),m=function(i){n(o(e,i))};"string"!=typeof r?r.then(m):m(r)}else n(e)})}),{options:{allowFileRename:[!0,t.BOOLEAN],fileRenameFunction:[null,t.FUNCTION]}}};return"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:e})),e});
19 changes: 18 additions & 1 deletion src/FilePondField.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ public function getImageSizeConfig($width, $height, $mode = null)
}

/**
* @link https://pqina.nl/filepond/docs/api/plugins/image-crop/
* @link https://pqina.nl/filepond/docs/api/plugins/image-resize/
* @link https://pqina.nl/filepond/docs/api/plugins/image-validate-size/
* @param int $width
* @param int $height
* @param string $mode min|max|crop|resize|crop_resize
Expand All @@ -339,7 +342,20 @@ public function setImageSize($width, $height, $mode = null)
// We need a custom poster size
$this->adjustPosterSize($width, $height);

return $config;
return $this;
}

/**
* This is a frontend alternative to setRenamePattern
*
* @link https://pqina.nl/filepond/docs/api/plugins/file-rename/
* @param string $name
* @return $this
*/
public function setRenameFile($name)
{
$this->addFilePondConfig('fileRenameFunction', $name);
return $this;
}

/**
Expand Down Expand Up @@ -692,6 +708,7 @@ public static function Requirements()
}

// Base elements
Requirements::javascript("$baseDir/filepond-plugin-file-rename/dist/filepond-plugin-file-rename.min.js");
Requirements::css("$baseDir/filepond/dist/filepond.min.css");
Requirements::javascript("$baseDir/filepond/dist/filepond.min.js");
}
Expand Down

0 comments on commit 076b05b

Please sign in to comment.