sfEntityAttributeValuePlugin - 1.0.6

The `sfEntityAttributeValuePlugin` is a symfony plugin that allows use of the [Entity-Attribute-Value](http://en.wikipedia.org/wiki/Entity-attribute-value_model) data-model as a doctrine behavior.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfEntityAttributeValuePlugin

The sfEntityAttributeValuePlugin is a symfony plugin that allows use of the Entity-Attribute-Value data-model as a doctrine behavior.

This plugin provides a way to easily create dynamic fields with jQuery Form Builder Plugin and bind then to a specific object (DB line) of your model. It also allow you to fill in these fields from other models that have a ManyToOne relation with the first one. And finally, these stored EAV can be exploited in edit/read mode.

Installation

  • Install the plugin (via a package)

    $ symfony plugin:install sfEntityAttributeValuePlugin 
    
  • or (via a Svn checkout)

    $ svn co http://svn.symfony-project.com/plugins/sfEntityAttributeValuePlugin plugins/sfEntityAttributeValuePlugin
    
  • Activate the plugin in your project configuration file (in config/ProjectConfiguration.class.php).

    class ProjectConfiguration extends sfProjectConfiguration
    {
        public function setup()
        {
            //...
            $this->enablePlugins('sfEntityAttributeValuePlugin');
        }
    }
    
  • Apply the EAV behavior to your model in your schema file config/doctrine/schema.yml , ie: Assume that we want to bind dynamic fields to each object of a model called "ParentModel" and then insert data in these fields from a 'ChildModel' who is related as ManyToOne to the "ParentModel", the schema will contain config like this:

    ParentModel:
      actAs: 
        EavBehavior:       
          mode: create
        columns:
          ...
    
    ChildModel:
      actAs: 
        EavBehavior:       
          mode: insert
          parent_resource: ParentModel
        columns:
          parent_model_id:            { type: integer }
          ...
      relations:
        ParentModel:                  { local: parent_model_id, foreign: id }
    
  • Build Eav models and create tables :

    $ symfony doctrine:build --all
    

    alternatively you could build the models, the sql, then run the sql manually

  • Build (or update) the global resource file to affect unique id for all your models

    $ symfony eav:init-config
    

    Important note: this task will create/update the file resources.yml that hold the models ids, do not change manually this files, this may damage your EAV structure!

  • Activate the "eav" module in the settings.yml:

    all:
      .settings:
        enabled_modules: [ default, eav ]
    
  • publish assets

    $ symfony plugin:publish-assets
    
  • Clear your cache

    $ symfony cc
    
  • Add the sfWidgetFormEav as a widgetSchema in all forms that have the EavBehavior. The sfEntityAttributeValuePlugin is enough smart to render the widget in create or insert mode.

    # lib/form/doctrine/ParentModelForm.php
    class ParentModelForm extends BaseParentModelForm
    {
        public function configure()
        {
            $this->widgetSchema['eav'] = new sfWidgetFormEav($this);
        }
    }
    
    # lib/form/doctrine/ChildModelForm.php
    class ChildModelForm extends BaseChildModelForm
    {
        public function configure()
        {
            $this->widgetSchema['eav'] = new sfWidgetFormEav($this);
        }
    }
    
  • Add the widget "eav" in the form partial

    # _form.php
    echo $form['eav']-> renderRow();
    

(future improvements)

Ajax eav child binder: when editing a child entity, eav structure will be updated via Ajax.

Smart EAV tables cleaner: to clean obsolete data from eav tables.

Required Field support

Sortable EAV