Skip to content

Attach this plugin to any model to enable revision version control of the records in that model. Useful for a way of saving blog posts, or web page drafts and revisions.

Notifications You must be signed in to change notification settings

CodeBlastr/Drafts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drafts Plugin for Zuha & Cakephp

Mainly a behavior in the form of a plugin, that adds the ability to easily save draft versions of a record without editing the current version of a record. Used for things like editing blog posts or web pages, but saving changes which aren't ready for prime time just yet. Version 1

Installation

  1. Create a plugins folder called Drafts
  2. Put this plugin into that folder. (or git clone [email protected]:zuha/Drafts-Zuha-Cakephp-Plugin.git app/Plugin/Drafts)

Save Usage

# in your model
public $actsAs = array('Drafts.Draftable');

# in your view
echo $this->Form->input('Article.draft', array('value' => 1));
  1. In the model you want to use drafts with, attach the Drafts.Draftable Behavior
  2. The default settings should do most of the work, but if you need something custom change the settings during behavior attachment.
  3. When you save a record add a field called 'draft' and set it to 1. For example...
  4. Click save and instead of editing the article it will save a draft which you can then preview by going to the view and

View Usage

# in your controller
public function beforeFilter() {
	parent::beforeFilter();
	if (!empty($this->request->params['named']['draft'])) { 
		$this->Article->Behaviors->attach('Drafts.Draftable', array(
			'returnVersion' => $this->request->params['named']['draft'],
			));
	}
}
  1. In your controller add a beforeFilter method, similar to the above...
  2. Visit a url similar to http:https://example.com/articles/articles/view/3/draft:1
  3. It will return the results of the newest draft instead of the actual live version
  4. Visit a url similar to http:https://example/articles/articles/view/3/draft:4
  5. It will return the results of the fourth oldest draft instead of the actual live version
  6. If there are only 2 drafts, then it will return the oldest available instead of the fourth.

Configuration Options

  1. triggerField ... Change the name of the field you send in a form from 'draft', to whatever you want.
  2. foreignKeyName ... If you want to hard code something other than 'id' as the primary key.
  3. reviseDateField ... unused as of 4/15/2012, meant to be for rolling back to older versions via post data.
  4. conditions ... Set conditions so that viewing a draft only works with a filtered subset of records. (ie. Article.type = public)
  5. returnVersion ... a setting to choose which version is returned during the find

Callbacks

  1. None

Requirements

  • PHP version: PHP 5.3+
  • CakePHP version: 2.x Stable

Support

For support and feature request, please visit submit an issue through Github.com.

For more information about our Professional Web Design, Development, and Marketing Services please visit the Zuha Development Corporation website.

License

Copyright 2009-2012, RazorIT LLC

Licensed under GPLv3 Redistributions of files must retain the below copyright notice.

Copyright

Copyright 2009-2012 RazoIT LLC 8417 Oswego Rd. #121 Baldwinsville, NY 13027 http:https://razorit.com

About

Attach this plugin to any model to enable revision version control of the records in that model. Useful for a way of saving blog posts, or web page drafts and revisions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages