daYamlEditorPlugin - 1.0.0

Yaml edition form generator

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source


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


  • Install the plugin (download the package, or use a svn:externals)
  • Active the plugin in your ProjectConfiguration

    $this->enablePlugins('aNicePlugin', 'daYamlEditorPlugin');
  • Enable the daYamlEditor module in your settings.yml

        enabled_modules:      [default, daYamlEditor]
  • Create your daYamlEditor.yml file and save it in one of your config/ dir.

      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
          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
            label: Expéditeur
            path: "all/mailer/from"
            type: email
            help: L'email utilisé par le site
              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()
        // 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'))
        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.


  • 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 event :

    $this->dispatcher->connect('', 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 :

    // or

    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 :

      is_secure: true
      credentials: admin


  • Write unit and fonctionnal test
  • Allow array editing (ability to add multiple value to a yaml key)