/**
   * Constructor.
   *
   * Available options:
   *
   *  * choices:         An array of possible choices (required)
   *  * label_separator: The separator to use between the input radio and the label
   *  * separator:       The separator to use between each input radio
   *  * class:           The class to use for the main <ul> tag
   *  * formatter:       A callable to call to format the radio choices
   *                     The formatter callable receives the widget and the array of inputs as arguments
   *  * template:        The template to use when grouping option in groups (%group% %options%)
   *
   * @param array $options     An array of options
   * @param array $attributes  An array of default HTML attributes
   *
   * @see sfWidgetFormChoiceBase
   */
 protected function configure($options = array(), $attributes = array())
  {
    parent::configure($options, $attributes);

    $this->addOption('class', 'radio_list');
    $this->addOption('label_separator', '');
    $this->addOption('separator', "\n");
    $this->addOption('formatter', array($this, 'formatter'));
    $this->addOption('template', '%group% %options%');

/*
    $arr = array (
      '1' => 'Mo',
      '2' => 'Di',
      3 => 'Mi',
      4 => 'Do',
      5 => 'Fr',
      6 => 'Sa',
      7 => 'So'
    );

    $this->setOption('choices', $arr);
*/
    
  }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $combinations = $this->getAllCombinations($this->getOption('choices'));
     // copy the array
     $this->setOption('choices', $this->getHTMLFromCombinations($combinations));
     return parent::render($name, $value, $attributes, $errors);
 }
  /**
   * Constructorz
   *
   * Available options:
   *
   *  * choices:         An array of possible choices (required)
   *  * label_separator: The separator to use between the input radio and the label
   *  * separator:       The separator to use between each input radio
   *  * class:           The class to use for the main <ul> tag
   *  * formatter:       A callable to call to format the radio choices
   *                     The formatter callable receives the widget and the array of inputs as arguments
   *  * template:        The template to use when grouping option in groups (%group% %options%)
   *
   * @param array $options     An array of options
   * @param array $attributes  An array of default HTML attributes
   *
   * @see sfWidgetFormChoiceBase
   */
 protected function configure($options = array(), $attributes = array())
  {
    parent::configure($options, $attributes);

    $this->addOption('class', 'radio_list');
    $this->addOption('label_separator', '');
    $this->addOption('separator', "\n");
    $this->addOption('formatter', array($this, 'formatter'));
    $this->addOption('template', '%group% %options%');
  }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * choices:         An array of possible choices (required)
  *  * label_separator: The separator to use between the input radio and the label
  *  * separator:       The separator to use between each input radio
  *  * formatter:       A callable to call to format the radio choices
  *                     The formatter callable receives the widget and the array of inputs as arguments
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *   
  * @see sfWidgetForm
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addOption('choices', array());
     $this->addOption('is_ternary', false);
     $this->setOption('separator', '&nbsp;');
     $this->setOption('label_separator', '');
     $this->setOption('formatter', array($this, 'ternaryFormat'));
     if (isset($options['is_ternary']) && $options['is_ternary'] == true) {
         $this->setOption('choices', array('1' => 'yes', '0' => 'no', '' => 'unknown'));
     }
 }
foo <ul class="radio_list"><li><input name="foo" type="radio" value="foo" id="foo_foo" checked="checked" />&nbsp;<label for="foo_foo">bar</label></li>
<li><input name="foo" type="radio" value="bar" id="foo_bar" />&nbsp;<label for="foo_bar">foo</label></li></ul>
bar <ul class="radio_list"><li><input name="foo" type="radio" value="foobar" id="foo_foobar" />&nbsp;<label for="foo_foobar">barfoo</label></li></ul>
EOF;
$t->is($w->render('foo', 'foo'), fix_linebreaks($output), '->render() has support for groups');
try {
    $w = new sfWidgetFormSelectRadio();
    $t->fail('__construct() throws an RuntimeException if you don\'t pass a choices option');
} catch (RuntimeException $e) {
    $t->pass('__construct() throws an RuntimeException if you don\'t pass a choices option');
}
// choices as a callable
$t->diag('choices as a callable');
function choice_callable()
{
    return array(1, 2, 3);
}
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable('choice_callable')));
$dom->loadHTML($w->render('foo'));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('input[type="radio"]')->getNodes()), 3, '->render() accepts a sfCallable as a choices option');
// __clone()
$t->diag('__clone()');
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable(array($w, 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($w1), '__clone() changes the choices is a callable and the object is an instance of the current object');
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable(array($a = new stdClass(), 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($a), '__clone() changes nothing if the choices is a callable and the object is not an instance of the current object');
Ejemplo n.º 6
0
 /**
  * DOCUMENT ME
  * @param mixed $options
  * @param mixed $attributes
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
 }
Ejemplo n.º 7
0
function choice_callable()
{
    return array(1, 2, 3);
}
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable('choice_callable')));
$dom->loadHTML($w->render('foo'));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('input[type="radio"]')->getNodes()), 3, '->render() accepts a sfCallable as a choices option');
// choices are translated
$t->diag('choices are translated');
$ws = new sfWidgetFormSchema();
$ws->addFormFormatter('stub', new FormFormatterStub());
$ws->setFormFormatterName('stub');
$w = new sfWidgetFormSelectRadio(array('choices' => array('foo' => 'bar', 'foobar' => 'foo'), 'separator' => ''));
$w->setParent($ws);
$output = '<ul class="radio_list">' . '<li><input name="foo" type="radio" value="foo" id="foo_foo" />&nbsp;<label for="foo_foo">translation[bar]</label></li>' . '<li><input name="foo" type="radio" value="foobar" id="foo_foobar" />&nbsp;<label for="foo_foobar">translation[foo]</label></li>' . '</ul>';
$t->is($w->render('foo'), $output, '->render() translates the options');
// choices as escaped
$t->diag('choices are escaped');
$w = new sfWidgetFormSelectRadio(array('choices' => array('<b>Hello world</b>')));
$t->is($w->render('foo'), '<ul class="radio_list"><li><input name="foo" type="radio" value="0" id="foo_0" />&nbsp;<label for="foo_0">&lt;b&gt;Hello world&lt;/b&gt;</label></li></ul>', '->render() escapes the choices');
// __clone()
$t->diag('__clone()');
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable(array($w, 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($w1), '__clone() changes the choices is a callable and the object is an instance of the current object');
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable(array($a = new stdClass(), 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($a), '__clone() changes nothing if the choices is a callable and the object is not an instance of the current object');
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $this->id_attr = $this->generateId($name);
     return parent::render($name, $value, $attributes, $errors);
 }
 protected function configure($options = array(), $attributes = array())
 {
     $this->addRequiredOption('image_prefix');
     parent::configure($options, $attributes);
 }
    $t->pass('__construct() throws an RuntimeException if you don\'t pass a choices option');
}
// choices as a callable
$t->diag('choices as a callable');
function choice_callable()
{
    return array(1, 2, 3);
}
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable('choice_callable')));
$dom->loadHTML($w->render('foo'));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('input[type="radio"]')->getNodes()), 3, '->render() accepts a sfCallable as a choices option');
// choices are translated
$t->diag('choices are translated');
$ws = new sfWidgetFormSchema();
$ws->addFormFormatter('stub', new FormFormatterStub());
$ws->setFormFormatterName('stub');
$w = new sfWidgetFormSelectRadio(array('choices' => array('foo' => 'bar', 'foobar' => 'foo'), 'separator' => ''));
$w->setParent($ws);
$output = '<ul class="radio_list">' . '<li><input name="foo" type="radio" value="foo" id="foo_foo" />&nbsp;<label for="foo_foo">translation[bar]</label></li>' . '<li><input name="foo" type="radio" value="foobar" id="foo_foobar" />&nbsp;<label for="foo_foobar">translation[foo]</label></li>' . '</ul>';
$t->is($w->render('foo'), $output, '->render() translates the options');
// __clone()
$t->diag('__clone()');
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable(array($w, 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($w1), '__clone() changes the choices is a callable and the object is an instance of the current object');
$w = new sfWidgetFormSelectRadio(array('choices' => new sfCallable(array($a = new stdClass(), 'foo'))));
$w1 = clone $w;
$callable = $w1->getOption('choices')->getCallable();
$t->is(spl_object_hash($callable[0]), spl_object_hash($a), '__clone() changes nothing if the choices is a callable and the object is not an instance of the current object');