/** * Embeds a dynamic relation in a form. * * @param sfForm $form A form * @param string $relationName A relation name and optional alias * @param string $formClass A form class * @param array $formArgs Arguments for the form constructor */ protected function embedDynamicRelation(sfForm $form, $relationName, $formClass = null, $formArgs = array()) { // get relation and determine the field name to use for embedding if (false !== ($pos = stripos($relationName, ' as '))) { $relation = $form->getObject()->getTable()->getRelation(substr($relationName, 0, $pos)); $field = substr($relationName, $pos + 4); } else { $relation = $form->getObject()->getTable()->getRelation($relationName); $field = sfInflector::underscore($relationName); } // validate relation type if (Doctrine_Relation::MANY != $relation->getType()) { throw new LogicException(sprintf('The %s "%s" relation is not a MANY relation.', get_class($form->getObject()), $relation->getAlias())); } // use the default form class if (null === $formClass) { $formClass = $relation->getClass() . 'Form'; } // store configuration for this relation to the form $config = $form->getOption('dynamic_relations'); $form->setOption('dynamic_relations', array_merge($config ? $config : array(), array($field => array('relation' => $relation, 'class' => $formClass, 'arguments' => $formArgs)))); // do the actual embedding $this->doEmbed($form, $field, $form->getObject()->get($relation->getAlias())); }
/** * Sets a sfForm as embedded by adding options * * @param sfForm $form the form to setup as embedded * @return sfForm */ protected function setFormEmbedded(sfForm $form) { $form->setOption('is_embedded', true); $form->setOption('embedder', $this); return $form; }