daYamlEditorPlugin
1.0.0stable
for sf 1.4sf 1.3 MIT
This plugin allow you to easily create a Yaml edition form. Just define the file(s) and the field(s) and that's done.
You can edit any Yaml file (your app.yml, or your customAwesomeConfig.yml, even both in the same form), and use all the sfValidator options you want.
Check the README for more informations.
Developers
License
Copyright (c) 2010 Damien ALEXANDRE
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Releases for sf 1.4
| Version |
License |
API |
Released |
|
1.0.0stable
|
MIT license |
1.0.0stable
|
13/09/2010 |
|
0.1.2beta
|
MIT license |
0.1.0beta
|
27/01/2010 |
|
0.1.1beta
|
MIT license |
0.1.0beta
|
26/01/2010 |
|
0.1.0beta
|
MIT license |
0.1.0beta
|
13/01/2010 |
Releases for sf 1.3
| Version |
License |
API |
Released |
|
1.0.0stable
|
MIT license |
1.0.0stable
|
13/09/2010 |
|
0.1.2beta
|
MIT license |
0.1.0beta
|
27/01/2010 |
|
0.1.1beta
|
MIT license |
0.1.0beta
|
26/01/2010 |
|
0.1.0beta
|
MIT license |
0.1.0beta
|
13/01/2010 |
Changelog for release 1.0.0 - 13/09/2010
- dalexandre: Beta to stable \o/
- dalexandre: Fix the Base class to ease extending (thx to Alecs)
Other releases
Release 1.0.0 - 13/09/2010
- dalexandre: Beta to stable \o/
- dalexandre: Fix the Base class to ease extending (thx to Alecs)
Release 0.1.2 - 27/01/2010
- dalexandre: Clean up and README completion
Release 0.1.1 - 26/01/2010
- dalexandre: Fix some bugs, make it easy to extend
Release 0.1.0 - 13/01/2010
- dalexandre: First release of the plugin
daYamlEditorPlugin
This plugin allow you to easily create a Yaml edition form. Just define the file(s) and the field(s) and that's done.
You can edit any Yaml file (your app.yml, or your customAwesomeConfig.yml, even both in the same form), and use all the sfValidator options you want.
Important notice
Use this plugin at your own risk,
if you dont "ignore" the yaml files in your rsync and subversion settings, all your online modifications will be lost at your next deployement.
So I suggest to add your edited yamls in the rsync_exclude.txt file and off course in your backup strategy.
Important notice 2
All the Yamls files edited will lose their comments
Installation
Install the plugin (download the package, or use a svn:externals)
http://svn.symfony-project.com/plugins/daYamlEditorPlugin/trunk/
Active the plugin in your ProjectConfiguration
$this->enablePlugins('aNicePlugin', 'daYamlEditorPlugin');
Enable the daYamlEditor module in your settings.yml
all:
.settings:
enabled_modules: [default, daYamlEditor]
Create your daYamlEditor.yml file and save it in one of your config/ dir.
all:
myaboutconfigform: # Add this block for each Yaml. It's also the name used create specific form
file: %SF_CONFIG_DIR%/app.yml # Path of the Yaml file to parse, can be anywhere, must be writable
fields:
sitename: # The unique name of the field, must be unique
label: Nom du site
path: "all/sitename" # Path to the var in the yaml file (levels separated by "/")
type: string # Can be integer, number, string, boolean, email
help: Min 10 char. # A text helper can be set
validate: # Validator options
required: true # Any option can be add here
min_length: 10
message: # Any message can be override here
required: Le nom du site est obligatoire
from:
label: Expéditeur
path: "all/mailer/from"
type: email
help: L'email utilisé par le site
message:
invalid: L'email doit être un email valide
As you can see, you can define field for each env and use config var in the file (%VAR%). Messages and validates are optionals.
The allowed types are :
- string
- number (float allowed)
- integer
- email
- boolean
You can also define unexisting path, the value will be add to the yaml file. Take a look at the config/daYamlEditor.yml file in the plugin, it's a great exemple.
Make your yaml files writtable
$ chmod +rw ./config/app.yml
Clear you cache
$ symfony cc
Enjoy your new form ! Navigate to the daYamlEditor module.
Create multiple forms
If you want to separate your fields in multiple forms, you just have to create a new form and say to it witch config block to use.
class myYamlEditorForm extends daYamlEditorForm
{
protected $daYamlEditorName = "myaboutconfigform";
public function configure()
{
parent::configure();
// You can override the generated form here
}
}
If $daYamlEditorName is null, all the blocks are used (it's the default behavior of daYamlEditorForm).
The next step is to build your form action :
public function executeIndex(sfWebRequest $request)
{
$this->form = new myYamlEditorForm();
if ($request->isMethod('post'))
{
$this->form->bind(
$request->getParameter($this->form->getName())
);
if ($this->form->isValid())
{
if ($this->form->save())
{
// Do what you want, the config file is saved
}
}
}
}
You can also override daYamlEditorActions, it's up to you.
Tips
Clear the cache after updating a config file
If you need to clear the cache after edit some yaml (that's sound obvious), you will need to do it manualy.
You can connect some code to the daYamlEditor.save event :
$this->dispatcher->connect('daYamlEditor.save', array($this, 'clearCache'));
(the first param of the sfEvent object will be the name of the block, or null). Read the symfony documentation to do it.
The quick and dirty way for clearing the cache :
sfToolkit::clearDirectory( sfConfig::get('sf_cache_dir').'/frontend/prod/template' );
sfToolkit::clearDirectory( sfConfig::get('sf_cache_dir').'/frontend/prod/config' );
Remove the "Doctrine" style on my form
By default, the form markup is close to the Doctrine Admin Generator one, thanks to the sfWidgetFormSchemaFormatterDaYamlEditor formatter. That's allow you to have consistant backend style. To remove this behavior, you can call this method :
$this->widgetSchema->setFormFormatterName('table');
// or
$form->getWidgetSchema()->setFormFormatterName('table');
And override the modules/daYamlEditor/templates/indexSuccess.php file with your own HTML.
Secure the module
If you use sfGuard (you should), add some credentials restrictions on the daYamlEditor module :
daYamlEditor:
is_secure: true
credentials: admin
TODO
- Write unit and fonctionnal test
- Allow array editing (ability to add multiple value to a yaml key)