Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to define subdirectories for file uploads (2.x) #922

Open
wants to merge 2 commits into
base: 7.x-2.x
Choose a base branch
from

Conversation

rhclayto
Copy link

@rhclayto rhclayto commented May 29, 2016

This change makes it possible to set an option for creating a subdirectory when saving a file, & it also adds the ability to optionally place files in a dated (Y-m-d) subdirectory within your named subdirectory.

This mimics the ability to set subdirectories & dated subdirectories when cteating a file field on a content type in Drupal core. For instance, you can add a file field & in the field settings you can put something like the following in the 'File directory' field: avatars/[current-date:custom:Y]-[current-date:custom:m]-[current-date:custom:d].

If setting a dated subdirectory, the date format is configurable using any format accepted by PHP's date function: https://secure.php.net/manual/en/function.date.php .

Example annotation for file upload plug-in:

/**
 * Class FilesUpload__1_0
 * @package Drupal\restful_example\Plugin\Resource
 *
 * @Resource(
 *   name = "files_upload:1.0",
 *   resource = "files_upload",
 *   label = "File upload",
 *   description = "A file upload wrapped with RESTful.",
 *   authenticationTypes = TRUE,
 *   dataProvider = {
 *     "entityType": "file",
 *     "options": {
 *       "scheme": "public",
 *       "subdir": "avatars",
 *       "datedir": TRUE,
 *       "date_format": "Y-m-d"
 *     }
 *   },
 *   menuItem = "file-upload",
 *   majorVersion = 1,
 *   minorVersion = 0
 * )
 */

This change makes it possible to set an option for creating a subdirectory when saving a file, & it also adds the ability to optionally places files in a dated (Y-m-d) subdirectory within your named subdirectory.
This change makes it possible to set an option for creating a subdirectory when saving a file, & it also adds the ability to optionally places files in a dated (Y-m-d) subdirectory within your named subdirectory.

This mimics the ability to set subdirectories & dated subdirectories when cteating a file field on a content type in Drupal core. For instance, you can add a file field & in the field settings you can put something like the following in the 'File directory' field: `avatars/[current-date:custom:Y]-[current-date:custom:m]-[current-date:custom:d`.
@rhclayto rhclayto changed the title Add the ability to define subdirectories for file uploads Add the ability to define subdirectories for file uploads (2.x) May 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant