Changeset 6455
- Timestamp:
- 12/11/07 11:45:26 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/lib/config/sfViewConfigHandler.class.php
r6259 r6455 82 82 $data[] = $this->addHtmlHead($viewName); 83 83 $data[] = $this->addEscaping($viewName); 84 84 $data[] = $this->addAttributes($viewName); 85 85 $data[] = $this->addHtmlAsset($viewName); 86 86 … … 97 97 $data[] = $this->addHtmlHead(); 98 98 $data[] = $this->addEscaping(); 99 99 $data[] = $this->addAttributes(); 100 100 $data[] = $this->addHtmlAsset(); 101 101 $data[] = ($first ? '' : "}")."\n"; … … 147 147 148 148 $components = $this->mergeConfigValue('components', $viewName); 149 149 150 foreach ($components as $name => $component) 150 151 { 151 if (!is_array($component) || count($component) < 1) 152 { 153 $component = array(null, null); 154 } 155 156 $data .= " \$this->setComponentSlot('{$name}', '{$component[0]}', '{$component[1]}');\n"; 152 if(!is_array($component) || count($component) < 1) 153 { 154 $component = array(null, null, null); // set component empty 155 } 156 157 $attributes = isset($component[2]) && is_array($component[2]) ? array_values($component[2]) : array(); 158 if(!empty($attributes)) 159 { 160 $cnt = count($attributes); 161 for($i = 0; $i < $cnt; $i++) // normalize yaml parsing of nested array 162 { 163 foreach ($attributes[$i] as $key => $value) 164 { 165 $attributes[$key] = $value; 166 unset($attributes[$i]); 167 } 168 } 169 } 170 $attributes = var_export($attributes, true); 171 172 $data .= " \$this->setComponentSlot('{$name}', '{$component[0]}', '{$component[1]}', {$attributes});\n"; 157 173 $data .= " if (sfConfig::get('sf_logging_enabled')) { \$this->context->getEventDispatcher()->notify(new sfEvent(\$this, 'application.log', array(sprintf('Set component \"%s\" (%s/%s)', '{$name}', '{$component[0]}', '{$component[1]}')))); }\n"; 158 174 } … … 366 382 return implode("\n", $data)."\n"; 367 383 } 384 385 /** 386 * Adds attributes to the view. 387 * 388 * @param array The attributes to set 389 * 390 * @return string The PHP statement 391 */ 392 protected function addAttributes($viewName = '') 393 { 394 $data = array(); 395 396 $attributes = $this->getConfigValue('attributes', $viewName, array()); 397 398 if(is_array($attributes) && !empty($attributes)) 399 { 400 $data[] = sprintf(" \$this->getAttributeHolder()->add(%s);", var_export($attributes, true)); 401 } 402 403 return implode("\n", $data)."\n"; 404 } 368 405 } branches/dwhittle/lib/plugins/sfCompat10Plugin/lib/helper/PartialHelper.php
r6269 r6455 65 65 if ($componentSlot = $viewInstance->getComponentSlot($name)) 66 66 { 67 return get_component($componentSlot[0], $componentSlot[1], $vars); 67 if (!empty($componentSlot[0])) // ignore component slots that are present, but empty 68 { 69 return get_component($componentSlot[0], $componentSlot[1], array_merge($componentSlot[2], $vars)); 70 } 71 72 return null; 68 73 } 69 74 } branches/dwhittle/lib/view/sfView.class.php
r6180 r6455 401 401 402 402 /** 403 * Sets the module and action to be executed in place of a particular template attribute.404 * 405 * @param string A template attributename403 * Sets the module and action to be executed for component slot. 404 * 405 * @param string The component slot name 406 406 * @param string A module name 407 407 * @param string A component name 408 */ 409 public function setComponentSlot($attributeName, $moduleName, $componentName) 410 { 411 $this->componentSlots[$attributeName] = array(); 412 $this->componentSlots[$attributeName]['module_name'] = $moduleName; 413 $this->componentSlots[$attributeName]['component_name'] = $componentName; 408 * @param array Parameters to pass to component 409 */ 410 public function setComponentSlot($name, $moduleName, $componentName, $parameters = array()) 411 { 412 $this->componentSlots[$name] = array(); 413 $this->componentSlots[$name]['module_name'] = $moduleName; 414 $this->componentSlots[$name]['component_name'] = $componentName; 415 $this->componentSlots[$name]['parameters'] = is_array($parameters) ? $parameters : array(); 414 416 } 415 417 … … 435 437 public function getComponentSlot($name) 436 438 { 437 if (isset($this->componentSlots[$name]) && $this->componentSlots[$name]['module_name'] && $this->componentSlots[$name]['component_name'])438 { 439 return array($this->componentSlots[$name]['module_name'], $this->componentSlots[$name]['component_name'] );439 if (isset($this->componentSlots[$name]) && isset($this->componentSlots[$name]['module_name']) && isset($this->componentSlots[$name]['component_name']) && isset($this->componentSlots[$name]['parameters'])) 440 { 441 return array($this->componentSlots[$name]['module_name'], $this->componentSlots[$name]['component_name'], $this->componentSlots[$name]['parameters']); 440 442 } 441 443