Coder Social home page Coder Social logo

helpfulrobot / titledk-silverstripe-uploaddirrules Goto Github PK

View Code? Open in Web Editor NEW

This project forked from titledk/silverstripe-uploaddirrules

0.0 2.0 0.0 65 KB

Rules to keep the SilverStripe assets directory tidy

License: MIT License

PHP 100.00%

titledk-silverstripe-uploaddirrules's Introduction

Upload Dir Rules

by title.dk/Anselm Christophersen

Rules and utilities to keep the SilverStripe assets directory tidy.

By installing this module and adding extensions to the objects you want affected, these objects will receive an associated folder inside of assets.
Now instead of bluntly uploading everything to assets/Uploads your site will upload files more controlled - defaults are set, which are easy to override.

Each object's folder can subsequently easily be changed through the admin, which allows for sophisticated files & assets strategies.

Administration

Upload rules are enforced both when uploading through an upload field, but also when uploading through the text editor
(thanks to the AssetsFolderAdmin extension)

This is especially helpful when working with Subsites (we're specifically catering for those with SubsitesUploadDirRules), but also helpful in general, or when needing a basic gallery, a downloads page, or anything else where you wont' want your files scattered all over the place.

Configuration example

SiteTree:
  extensions:
    - AssetsFolderExtension
SiteConfig:
  extensions:
    - AssetsFolderExtension
Subsite:
  extensions:
    - AssetsFolderExtension
LeftAndMain:
  extensions:
    - AssetsFolderAdmin

Basic rules

The basic rules are defined in UploadDirRules::calc_base_directory_for_object(), basically putting all files related to DataObject into a dataobjects folder, everything related to SiteTree into a pages folder and everything related to SiteConfig into a site folder.

Overriding default upload dir rules

Just implement the UploadDirRulesInterface.
Customization through SilverStripe's config is planned, send a pull request if you need it!

Rules can be anything, from just being a common folder to containing id and or title.

Planned enhancements

  • method that lists all rules for printing or display, alseo those set via UploadDirRulesInterface e.g.
    • pages: /my-subsite/pages/
    • siteconfig: /my-subsite/site
    • etc.
  • method that lists all objects and their asset folders
    • mainly for review / checking up, will probably be used on UploadDirRulesTestTask

Unit tests

This module will contain unit tests. Run like this:

vendor/bin/phpunit uploaddirrules/tests

Make sure that you've got phpunit set up:

composer require --dev "phpunit/phpunit:*@stable"

Test task

php ./public/framework/cli-script.php /UploadDirRulesTestTask

add flush=1 for first run...

titledk-silverstripe-uploaddirrules's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.