Coder Social home page Coder Social logo

wernerkrauss-folderperpage's Introduction

silverstripe-folderperpage

Extension that creates a folder per page or dataobject

Requirements

Installation

Download and install manually or use composer.

Make sure you add the extension to the classes you want to decorate. Add this to your config.yml to add it to all Pages:

Page:
  extensions:
    ['RootFolder']

Configuration

You can exclude several page types. Just use the RootFolder.ignored_classes config value. The module's config.yml has some default values to get you started:

RootFolder:
  ignored_classes:
    ['VirtualPage', 'ErrorPage']
  create_folder_for_translations: false
  folder_root: 'Articles'

Of course every decorated class can have a seperate folder root, e.g. "Articles" for all pages and "News" for a news data object. Just add the folder_root config to your object.

Update your forms

You can use $this->getRootFoldername() to set the upload folder.

Given you have a has_one relation "Avatar" => "Image" you can add the folder to the UploadField:

function getCMSFields() {
    /*...*/
    $pic = UploadField::create('Avatar', 'Your Avatar');
    $fields->addFieldToTab('Root.Main', $pic);

    $pic->setFolderName($this->getRootFolderName());
    /*...*/
}

TODO

  • make it work for other dataobjects
  • unit tests
  • add function that automatically updates all UploadFields and BulkUploads to use this folder in a form
  • add support for subsites module, e.g. a master root per subsite
  • task for updating / checking all existing pages
  • check if page is moved
    • should it move the rootfolder automatically or by switch? May be a timeout problem with very large trees

wernerkrauss-folderperpage's People

Contributors

wernerkrauss avatar

Watchers

James Cloos avatar helpfulrobot 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.