/** * Constructor. * * Available options: * * * model: The model class (required) * * add_empty: Whether to add a first empty value or not (false by default) * If the option is not a Boolean, the value will be used as the text value * * method: The method to use to display object values (__toString by default) * * key_method: The method to use to display the object keys (getPrimaryKey by default) * * order_by: An array composed of two fields: * * The column to order by the results (must be in the PhpName format) * * asc or desc * * criteria: A criteria to use when retrieving objects * * connection: The Propel connection to use (null by default) * * multiple: true if the select tag must allow multiple selections * * peer_method: The peer method to use to fetch objects * * @see sfWidgetFormSelect */ protected function configure($options = array(), $attributes = array()) { $this->addOption('multiple', false); $this->addOption('add_empty', true); $this->addOption('current_zone', null); parent::configure($options, $attributes); }
/** * @see sfValidatorBase */ protected function doClean($value) { $choices = sfWidgetFormTree::normalizeChoices($this->getOption('choices'), $this->getOption('label_key'), $this->getOption('value_key'), $this->getOption('level_key'), $this->getOption('children_key')); $restrict_select_below = $this->getOption('restrict_select_below'); if ($restrict_select_below instanceof sfCallable) { $restrict_select_below = $restrict_select_below->call(); } if ($restrict_select_below !== false && !is_array($restrict_select_below)) { $restrict_select_below = array($restrict_select_below); } if ($choices instanceof sfCallable) { $choices = $choices->call(); } if ($this->getOption('multiple')) { if (!is_array($value)) { $value = array($value); } foreach ($value as $v) { if (!self::inChoices($v, $choices)) { throw new sfValidatorError($this, 'invalid', array('value' => $v)); } if ($restrict_select_below !== false) { if (self::valueIsParentOf($v, $restrict_select_below, $choices)) { throw new sfValidatorError($this, 'restricted', array('value' => $v)); } } } } else { if (!self::inChoices($value, $choices)) { throw new sfValidatorError($this, 'invalid', array('value' => $value)); } if ($restrict_select_below !== false) { if (self::valueIsParentOf($value, $restrict_select_below, $choices)) { throw new sfValidatorError($this, 'restricted', array('value' => $value)); } } } return $value; }
/** * @param string $name The element name * @param string $value The value selected in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { if ('[]' != substr($name, -2)) { $name .= '[]'; } $choices = sfWidgetFormTree::normalizeChoices($this->getOption('choices'), $this->getOption('label_key'), $this->getOption('value_key'), $this->getOption('level_key'), $this->getOption('children_key')); if ($choices instanceof sfCallable) { $choices = $choices->call(); } return $this->formatChoices($name, $value, $choices, $attributes); }
protected function configure($options = array(), $attributes = array()) { parent::configure($options, $attributes); $this->setOption('multiple', true); }