Changeset 19234
- Timestamp:
- 06/13/09 18:17:54 (4 years ago)
- Files:
-
- plugins/sfWidgetFormTreePlugin/lib/sfWidgetFormCheckboxTree.php (modified) (4 diffs)
- plugins/sfWidgetFormTreePlugin/lib/sfWidgetFormRadioTree.php (modified) (4 diffs)
- plugins/sfWidgetFormTreePlugin/lib/sfWidgetFormTree.php (modified) (2 diffs)
- plugins/sfWidgetFormTreePlugin/sfWidgetFormTreePlugin-1.0.2.tgz (added)
- plugins/sfWidgetFormTreePlugin/sfWidgetFormTreePlugin-1.0.3.tgz (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfWidgetFormTreePlugin/lib/sfWidgetFormCheckboxTree.php
r18792 r19234 72 72 $this->addOption('value_key', false); 73 73 $this->addOption('level_key', 'level'); 74 $this->addOption('hidden_nodes', false); 74 75 $this->addOption('children_key', 'children'); 75 76 $this->addOption('class', 'checkbox_tree'); … … 97 98 } 98 99 $choices = sfWidgetFormTree::normalizeChoices($this->getOption('choices'), $this->getOption('label_key'), $this->getOption('value_key'), $this->getOption('level_key'), $this->getOption('children_key')); 100 $hidden_nodes = $this->getOption('hidden_nodes'); 101 if($hidden_nodes !== false && !is_array($hidden_nodes)) 102 $hidden_nodes = array($hidden_nodes); 103 99 104 if ($choices instanceof sfCallable) 100 105 { 101 106 $choices = $choices->call(); 102 107 } 103 return $this->formatChoices($name, $value, $choices, $attributes );;108 return $this->formatChoices($name, $value, $choices, $attributes, $hidden_nodes); 104 109 } 105 110 106 protected function formatChoices($name, $value, $choices, $attributes )111 protected function formatChoices($name, $value, $choices, $attributes, $hidden_nodes) 107 112 { 108 113 $inputs = array(); … … 111 116 foreach($choices AS $key => $option) 112 117 { 118 if(is_array($hidden_nodes) && in_array($key, $hidden_nodes)) 119 continue; 113 120 if(!is_array($option)) throw new InvalidArgumentException(sprintf('Choice value must be an array, %s given.', gettype($option))); 114 121 if(!isset($option[$this->getOption('label_key')])) throw new InvalidArgumentException(sprintf('Choice with key %s must have a label.', $key)); … … 132 139 'input' => $this->renderTag('input', array_merge($baseAttributes, $attributes)), 133 140 'label' => $this->renderContentTag('label', $option[$this->getOption('label_key')], array('for' => $id_attr)), 134 'children' => isset($option['children']) ? $this->formatChoices($name, $value, $option['children'], $attributes ) : null141 'children' => isset($option['children']) ? $this->formatChoices($name, $value, $option['children'], $attributes, $hidden_nodes) : null 135 142 ); 136 143 } plugins/sfWidgetFormTreePlugin/lib/sfWidgetFormRadioTree.php
r18797 r19234 72 72 $this->addOption('value_key', false); 73 73 $this->addOption('level_key', 'level'); 74 $this->addOption('hidden_nodes', false); 74 75 $this->addOption('children_key', 'children'); 75 76 $this->addOption('class', 'radio_tree'); … … 93 94 { 94 95 $choices = sfWidgetFormTree::normalizeChoices($this->getOption('choices'), $this->getOption('label_key'), $this->getOption('value_key'), $this->getOption('level_key'), $this->getOption('children_key')); 96 $hidden_nodes = $this->getOption('hidden_nodes'); 97 if($hidden_nodes !== false && !is_array($hidden_nodes)) 98 $hidden_nodes = array($hidden_nodes); 99 95 100 if ($choices instanceof sfCallable) 96 101 { 97 102 $choices = $choices->call(); 98 103 } 99 return $this->formatChoices($name, $value, $choices, $attributes );;104 return $this->formatChoices($name, $value, $choices, $attributes, $hidden_nodes); 100 105 } 101 106 102 protected function formatChoices($name, $value, $choices, $attributes )107 protected function formatChoices($name, $value, $choices, $attributes, $hidden_nodes) 103 108 { 104 109 $inputs = array(); … … 107 112 foreach($choices AS $key => $option) 108 113 { 114 if(is_array($hidden_nodes) && in_array($key, $hidden_nodes)) 115 continue; 116 109 117 if(!is_array($option)) throw new InvalidArgumentException(sprintf('Choice value must be an array, %s given.', gettype($option))); 110 118 if(!isset($option[$this->getOption('label_key')])) throw new InvalidArgumentException(sprintf('Choice with key %s must have a label.', $key)); … … 128 136 'input' => $this->renderTag('input', array_merge($baseAttributes, $attributes)), 129 137 'label' => $this->renderContentTag('label', $option[$this->getOption('label_key')], array('for' => $id_attr)), 130 'children' => isset($option['children']) ? $this->formatChoices($name, $value, $option['children'], $attributes ) : null138 'children' => isset($option['children']) ? $this->formatChoices($name, $value, $option['children'], $attributes, $hidden_nodes) : null 131 139 ); 132 140 } plugins/sfWidgetFormTreePlugin/lib/sfWidgetFormTree.php
r18797 r19234 72 72 $this->addOption('value_key', false); 73 73 $this->addOption('level_key', 'level'); 74 $this->addOption('hidden_nodes', false); 74 75 $this->addOption('children_key', 'children'); 75 76 $this->addOption('multiple', false); … … 145 146 $class = sprintf('sfWidgetForm%sTree', ucfirst($type)); 146 147 } 147 return new $class(array_merge(array(' value_key'=>$this->getOption('value_key'), 'label_key'=>$this->getOption('label_key'), 'level_key'=>$this->getOption('level_key'), 'children_key'=>$this->getOption('children_key'), 'choices' => new sfCallable(array($this, 'getChoices'))), $this->options['renderer_options']), $this->getAttributes());148 return new $class(array_merge(array('hidden_nodes'=>$this->getOption('hidden_nodes'), 'value_key'=>$this->getOption('value_key'), 'label_key'=>$this->getOption('label_key'), 'level_key'=>$this->getOption('level_key'), 'children_key'=>$this->getOption('children_key'), 'choices' => new sfCallable(array($this, 'getChoices'))), $this->options['renderer_options']), $this->getAttributes()); 148 149 } 149 150