sfFormPropel::getRelationForm PHP Method

getRelationForm() public method

Available options: - hide_on_new: If true, returns null for new objects. Defaults to false. - collection_form_class: class of the collection form to return. Defaults to sfFormPropelCollection. - criteria: Optional criteria to filter related objects Additional options are passed to sfFormPropelCollection::__construct()
public getRelationForm ( string $relationName, array $options = [] ) : sfFormPropelCollection
$relationName string The name of a relation of the current Model, e.g. 'Book'
$options array An array of options
return sfFormPropelCollection A form collection instance
    public function getRelationForm($relationName, $options = array())
    {
        $options = array_merge(array('hide_on_new' => false, 'collection_form_class' => 'sfFormPropelCollection', 'criteria' => null, 'add_delete' => true), $options);
        if ($this->getObject()->isNew() && $options['hide_on_new']) {
            return;
        }
        unset($options['hide_on_new']);
        // compute relation elements
        $relationMap = $this->getRelationMap($relationName);
        if ($relationMap->getType() != RelationMap::ONE_TO_MANY) {
            throw new sfException('embedRelation() only works for one-to-many relationships');
        }
        $collection = call_user_func_array(array($this->getObject(), sprintf('get%s', $relationMap->getPluralName())), array($options['criteria']));
        unset($options['criteria']);
        // compute relation fields, to be removed from embedded forms
        // because this data is not editable
        if (!isset($options['remove_fields'])) {
            $options['remove_fields'] = $this->getRelationFields($relationMap);
        }
        // create the relation form
        $collectionFormClass = $options['collection_form_class'];
        unset($options['collection_form_class']);
        $collectionForm = new $collectionFormClass($collection, $options);
        return $collectionForm;
    }