Permalink
Browse files

Merge pull request #181 from mmonguilod/master

Add the possibility to change the default label of a embedded realtion from new<RelationName> to an arbitrary name
  • Loading branch information...
2 parents 1a55297 + f55fb34 commit ce6aa334394cd90eec0b7d31286e869e1def84e0 @willdurand willdurand committed Jan 18, 2013
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/form/sfFormPropel.class.php
View
6 lib/form/sfFormPropel.class.php 100644 → 100755
@@ -549,6 +549,7 @@ public function mergeRelation($relationName, $options = array())
* - title: The title of the collection form once embedded. Defaults to the relation name.
* - decorator: The decorator for the sfWidgetFormSchemaDecorator
* - add_empty: Whether to allow the user to add new objects to the collection. Defaults to true
+ * - empty_name: Label showed to create a new related item. By default is new + name of the relation
* Additional options are passed to sfFromPropel::getRelationForm()
* - empty_label: The label of the empty form
*
@@ -564,12 +565,13 @@ public function embedRelation($relationName, $options = array())
'decorator' => null,
'add_empty' => true,
'max_additions' => 0,
+ 'empty_name' => 'new'.$relationName,
'empty_label' => null,
), $options);
$relationForm = $this->getRelationForm($relationName, $options);
- $this->addEmptyRelationForm($relationName, $relationForm, 'new' . $relationName, $relationName. '/', $options);
+ $this->addEmptyRelationForm($relationName, $relationForm, 'new'.$relationName, $relationName. '/', $options);
$this->embedForm($relationName, $relationForm, $options['decorator']);
@@ -578,6 +580,7 @@ public function embedRelation($relationName, $options = array())
return $this;
}
+
/**
* Get a Collection form based on a Relation of the current form's model.
* Available options:
@@ -669,6 +672,7 @@ protected function addEmptyRelationForm($relationName, $relationForm, $emptyName
$options['max_additions'] = $options['max_additions'] - $count;
}
$emptyForm = $this->getEmptyRelatedForm($relationName, $options);
+ $emptyForm->widgetSchema->setLabel($options['empty_name']);
$relationForm->embedOptionalForm($emptyName, $emptyForm, $options['empty_decorator'], $options);
$this->optionalForms[$prefix . $emptyName] = $emptyForm;
}

0 comments on commit ce6aa33

Please sign in to comment.