/**
  * Overridden to allow the app to add to the form and then to process
  * those additions and turn them into one giant, embedded form
  */
 public function setup()
 {
     // allow the application to add fields to the form
     self::$dispatcher->notify(new sfEvent($this, 'sympal.load_config_form'));
     $otherSettings = array();
     foreach ($this->_settings as $group => $settings) {
         if (!is_numeric($group)) {
             $form = new BaseForm();
             foreach ($settings as $setting) {
                 $form->setWidget($setting['name'], $setting['widget']);
                 $form->getWidgetSchema()->setLabel($setting['name'], $setting['label']);
                 $form->setValidator($setting['name'], $setting['validator']);
             }
             $this->embedForm($group, $form);
         } else {
             $otherSettings[] = $settings;
         }
     }
     foreach ($otherSettings as $setting) {
         $this->setWidget($setting['name'], $setting['widget']);
         $this->getWidgetSchema()->setLabel($setting['name'], $setting['label']);
         $this->setValidator($setting['name'], $setting['validator']);
     }
     $defaults = $this->getDefaults();
     foreach ($this as $key => $value) {
         if ($value instanceof sfFormFieldSchema) {
             foreach ($value as $k => $v) {
                 $defaults[$key][$k] = sfSympalConfig::get($key, $k);
             }
         } else {
             $defaults[$key] = sfSympalConfig::get($key);
         }
     }
     $this->setDefaults($defaults);
     $this->widgetSchema->setNameFormat('settings[%s]');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
     parent::setup();
 }
示例#2
0
 public function executeDeletePair(sfWebRequest $request)
 {
     $pair = MappingPairTable::getInstance()->find($request->getParameter('id'));
     if (!$pair) {
         return $this->notFound();
     }
     /* @var $pair MappingPair */
     $form = new BaseForm();
     $form->getWidgetSchema()->setNameFormat('delete_pair[%s]');
     $form->bind($request->getPostParameter($form->getName()));
     if ($form->isValid()) {
         $id = $pair->getId();
         $pair->delete();
         return $this->ajax()->remove('#pair_' . $id)->remove('#pair_form_' . $id)->render();
     } else {
         return $this->ajax()->form($form)->render();
     }
 }
 /**
  * Embed a Doctrine_Collection relationship in to a form
  *
  *     [php]
  *     $userForm = new UserForm($user);
  *     $userForm->embedRelationAndCreate('Groups');
  *
  * @param  string $relationName  The name of the relation
  * @param  string $formClass     The name of the form class to use
  * @param  array  $formArguments Arguments to pass to the constructor (related object will be shifted onto the front)
  *
  * @throws InvalidArgumentException If the relationship is not a collection
  */
 public function embedRelationAndCreate($relationName, $parentForm = null, $formClass = null, $formArgs = array(), $formatter = 'table')
 {
     if ($this->isNew()) {
         return;
     }
     if ($parentForm == null) {
         $parentForm = $this;
     }
     $this->_relations[] = $relationName;
     $relation = $this->getObject()->getTable()->getRelation($relationName);
     if ($relation->getType() !== Doctrine_Relation::MANY) {
         throw new InvalidArgumentException('You can only embed a relationship that is a collection.');
     }
     $r = new ReflectionClass(null === $formClass ? $relation->getClass() . 'Form' : $formClass);
     $subForm = new BaseForm();
     $relations = $parentForm->getObject()->getTable()->getRelations();
     $relationColumn = $relations[$relationName]['foreign'];
     foreach ($this->getObject()->{$relationName} as $index => $childObject) {
         $r = new ReflectionClass(null === $formClass ? get_class($childObject) . 'Form' : $formClass);
         $form = $r->newInstanceArgs(array_merge(array($childObject), $formArgs));
         unset($form[$relationColumn]);
         $form->setWidget('delete', new sfWidgetFormInputCheckbox());
         $subForm->embedForm($index, $form);
         $subForm->getWidgetSchema()->setLabel($index, (string) $childObject);
         $subForm->getWidgetSchema()->setFormFormatterName($formatter);
     }
     $object = $relation->getClass();
     $childObject = new $object();
     $childObject->{$relationColumn} = $parentForm->getObject()->id;
     $r = new ReflectionClass(null === $formClass ? $relation->getClass() . 'Form' : $formClass);
     $form = $r->newInstanceArgs(array_merge(array($childObject), $formArgs));
     $form->setWidget('create', new sfWidgetFormInputCheckbox());
     $form->setValidator('create', new sfValidatorPass());
     //$form->isNew(true);
     unset($form[$relationColumn]);
     $subForm->getWidgetSchema()->setFormFormatterName($formatter);
     $subForm->embedForm('new', $form);
     $this->embedForm($relationName, $subForm);
 }
示例#4
0
<?php

/* @var $pair MappingPair */
$form = new BaseForm();
$form->getWidgetSchema()->setNameFormat('delete_pair[%s]');
?>
<tr id="pair_<?php 
echo $pair['id'];
?>
">
  <td><?php 
echo $pair['a'];
?>
</td>
  <td><?php 
echo $pair['b'];
?>
</td>
  <td>
    <form class="ajax_form" method="post" action="<?php 
echo url_for('mapping_delete_pair', array('id' => $pair['id']));
?>
"><?php 
echo $form;
?>
      <a class="btn btn-mini ajax_link" href="<?php 
echo url_for('mapping_edit_pair', array('id' => $pair['id']));
?>
">edit</a>
      <button class="btn btn-mini  btn-warning">delete</button>
    </form>