/** * @param dmDoctrineTable $table * @param string $fieldName * @param string $label * @return dmFormDoctrine */ protected function updateNestedSetWidget(dmDoctrineTable $table, $fieldName = null, $label = null) { if ($table->isNestedSet()) { if (null === $fieldName) { $fieldName = 'nested_set_parent_id'; } // create if not exists if (!$this->widgetSchema[$fieldName] instanceof sfWidgetFormDoctrineChoice) { $this->widgetSchema[$fieldName] = new sfWidgetFormDoctrineChoice(array('model' => $table->getComponentName())); } if (!$this->validatorSchema[$fieldName] instanceof sfValidatorDoctrineChoice) { $this->validatorSchema[$fieldName] = new sfValidatorDoctrineChoice(array('model' => $table->getComponentName())); } if (null !== $label) { $this->widgetSchema[$fieldName]->setLabel('$label'); } // set sorting $orderBy = 'lft'; if ($table->getTemplate('NestedSet')->getOption('hasManyRoots', false)) { $orderBy = $table->getTemplate('NestedSet')->getOption('rootColumnName', 'root_id') . ', ' . $orderBy; } $options = array('method' => 'getNestedSetIndentedName', 'order_by' => array($orderBy, '')); if ($fieldName == 'nested_set_parent_id') { $options['add_empty'] = '~'; $this->validatorSchema[$fieldName]->setOptions(array_merge($this->validatorSchema[$fieldName]->getOptions(), array('required' => false))); } $this->widgetSchema[$fieldName]->setOptions(array_merge($this->widgetSchema[$fieldName]->getOptions(), $options)); } return $this; }