本文整理汇总了PHP中BaseForm::embedForm方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseForm::embedForm方法的具体用法?PHP BaseForm::embedForm怎么用?PHP BaseForm::embedForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseForm
的用法示例。
在下文中一共展示了BaseForm::embedForm方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bind
public function bind(array $taintedValues = null, array $taintedFiles = null)
{
$new_occurrences = new BaseForm();
if (isset($taintedValues["EiBlockParams"])) {
try {
$formParams = $this->getEmbeddedForm("EiBlockParams");
} catch (InvalidArgumentException $exc) {
$formParams = null;
}
}
if (isset($taintedValues['EiBlockParams'])) {
foreach ($taintedValues['EiBlockParams'] as $key => $new_occurrence) {
try {
if (isset($new_occurrence["id"]) && $new_occurrence["id"] == "") {
$blockParam = new EiBlockParam();
$blockParam->setEiVersionStructureParent($this->getObject());
$blockParam->setId($new_occurrence["id"]);
$blockParam->setEiVersionId($this->getObject()->getEiVersionId());
$occurrence_form = new EiBlockParamForm($blockParam);
$new_occurrences->embedForm($key, $occurrence_form);
} elseif ($formParams != null && ($subForm = $formParams->getEmbeddedForm($key))) {
$occurrence_form = new EiBlockParamForm($subForm->getObject());
$new_occurrences->embedForm($key, $occurrence_form);
}
} catch (InvalidArgumentException $exc) {
// TODO: Traiter l'exception.
}
}
$this->embedForm('EiBlockParams', $new_occurrences);
} else {
$this->embedForm("EiBlockParams", new BaseForm());
}
parent::bind($taintedValues, $taintedFiles);
}
示例2: embedForm
/**
* Moves button below embedded forms
* @inheritdoc
* @param string $name
* @param sfForm $form
* @param string $decorator
*/
public function embedForm($name, sfForm $form, $decorator = null)
{
parent::embedForm($name, $form, $decorator);
if ($this->getOption('addByCloning')) {
$this->widgetSchema->moveField('_', sfWidgetFormSchema::LAST);
}
}
示例3: bind
public function bind(array $taintedValues = null, array $taintedFiles = null)
{
$new_occurrences = new BaseForm();
if (isset($taintedValues['kalParams'])) {
foreach ($taintedValues['kalParams'] as $key => $new_occurrence) {
$kalparam = new EiFunctionHasParam();
$kalparam->setKalFunction($this->getObject());
$occurrence_form = new EiFunctionHasParamForm($kalparam);
$new_occurrences->embedForm($key, $occurrence_form);
}
$this->embedForm('kalParams', $new_occurrences);
}
parent::bind($taintedValues, $taintedFiles);
}
示例4: bind
public function bind(array $taintedValues = null, array $taintedFiles = null)
{
if (array_key_exists('new', $taintedValues)) {
$new_occurrences = new BaseForm();
foreach ($taintedValues['new'] as $key => $new_occurrence) {
$occurrence = new UserSport();
$occurrence->setSport($this->getObject());
$occurrence_form = new UserSportForm($occurrence);
$new_occurrences->embedForm($key, $occurrence_form);
}
}
$this->embedForm('new', $new_occurrences);
parent::bind($taintedValues, $taintedFiles);
}
示例5: bind
public function bind(array $taintedValues = null, array $taintedFiles = null)
{
if (isset($taintedValues['new'])) {
$new_stop_times = new BaseForm();
foreach ($taintedValues['new'] as $key => $new_stop_time) {
$stop_time = new NjStopTime();
$stop_time->setNjTrip($this->getObject());
$stop_time_form = new NjStopTimeForm($stop_time);
$new_stop_times->embedForm($key, $stop_time_form);
}
$this->embedForm('new', $new_stop_times);
}
parent::bind($taintedValues, $taintedFiles);
}
示例6: embedRelationAndCreate
/**
* 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);
}
示例7: doEmbed
/**
* Does the actual embedding.
*
* This method is called when a relation is dynamically embedded during form
* configuration and again just before input values are validated.
*
* @param sfForm $form A form
* @param string $field A field name to use for embedding
* @param Doctrine_Collection|array $values An collection of values (objects or arrays) to use for embedding
*/
protected function doEmbed(sfForm $form, $field, $values)
{
$relations = $form->getOption('dynamic_relations');
$config = $relations[$field];
$r = new ReflectionClass($config['class']);
$parent = new BaseForm();
foreach ($values as $i => $value) {
if (is_object($value)) {
$child = $r->newInstanceArgs(array_merge(array($value), array($config['arguments'])));
} elseif (!empty($value['id'])) {
$child = $this->findEmbeddedFormById($form, $field, $value['id']);
if (!$child) {
throw new InvalidArgumentException(sprintf('Could not find a previously embedded form with id "%s".', $value['id']));
}
} else {
$object = $config['relation']->getTable()->create();
$object->fromArray($value);
$form->getObject()->get($config['relation']->getAlias())->add($object);
$child = $r->newInstanceArgs(array_merge(array($object), array($config['arguments'])));
}
// form must include PK widget
if (!isset($child['id'])) {
throw new LogicException(sprintf('The %s form must include an "id" field to be embedded as dynamic relation.', get_class($child)));
}
$parent->embedForm($i, $child);
}
// workaround embedding despite being bound
// this is why this class extends sfForm
$wasBound = $form->isBound;
$form->isBound = false;
$form->embedForm($field, $parent);
$form->isBound = $wasBound;
}
开发者ID:AUTOPLANNING,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:43,代码来源:sfDoctrineDynamicFormRelations.class.php
示例8: sfWidgetFormTextarea
$this->setWidget('body', new sfWidgetFormTextarea());
$this->setValidator('body', new sfValidatorString(array('min_length' => 12)));
}
}
$configuration = $configuration->getApplicationConfiguration('frontend', 'test', true, null, $configuration->getEventDispatcher());
sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir'));
$enhancer = new sfFormYamlEnhancerTest($configuration->getConfigCache());
// ->enhance()
$t->diag('->enhance()');
$form = new CommentForm();
$form->bind(array('body' => '+1'));
$enhancer->enhance($form);
$t->like($form['body']->renderLabel(), '/Please enter your comment/', '->enhance() enhances labels');
$t->like($form['body']->render(), '/class="comment"/', '->enhance() enhances widgets');
$t->like($form['body']->renderError(), '/You haven\'t written enough/', '->enhance() enhances error messages');
$form = new CommentForm();
$form->bind();
$enhancer->enhance($form);
$t->like($form['body']->renderError(), '/A base required message/', '->enhance() considers inheritance');
class SpecialCommentForm extends CommentForm
{
}
$form = new SpecialCommentForm();
$form->bind();
$enhancer->enhance($form);
$t->like($form['body']->renderLabel(), '/Please enter your comment/', '->enhance() applies parent config');
$form = new BaseForm();
$form->embedForm('comment', new CommentForm());
$form->bind();
$enhancer->enhance($form);
$t->like($form['comment']['body']->renderLabel(), '/Please enter your comment/', '->enhance() enhances embedded forms');