Hi!
I’ve read the wiki article “Theming your Zii Widgets” and was a little bit disappointed that one has to configure each [font=“Courier New”]CJuiWidget[/font] individually. Why not configuring the base class instead? But than I saw that the [font=“Courier New”]CWidgetFactory[/font] only sets the properties of the concrete class and not also that of the ancestors.
Therefore I changed [font="Courier New"]CWidgetFactory[/font] to contain a new private method:
/*
* Merge all properties of parent classes first and than the properties of
* the more specific classes
*/
private function mergeProperties($className, $properties)
{
$parent = get_parent_class($className);
// Resolve up to CWidget
if (is_subclass_of($parent, 'CWidget') || $parent == 'CWidget')
{
$properties = $this->mergeProperties($parent, $properties);
}
if(isset($this->widgets[$className]))
{
$properties=$properties===array() ?
$this->widgets[$className] : CMap::mergeArray($this->widgets[$className],$properties);
}
return $properties;
}
and then let the method [font="Courier New"]CWidgetFactory->createWidget[/font] call it:
public function createWidget($owner,$className,$properties=array())
{
$className=Yii::import($className,true);
$widget=new $className($owner);
$properties = $this->mergeProperties($className, $properties);
if($this->enableSkin)
{
if($this->skinnableWidgets===null || in_array($className,$this->skinnableWidgets))
{
$skinName=isset($properties['skin']) ? $properties['skin'] : 'default';
if($skinName!==false && ($skin=$this->getSkin($className,$skinName))!==array())
$properties=$properties===array() ? $skin : CMap::mergeArray($skin,$properties);
}
}
foreach($properties as $name=>$value)
$widget->$name=$value;
return $widget;
}
Now it’s as easy as:
'widgetFactory' => array(
'widgets' => array(
'CJuiWidget' => array(
'themeUrl' => 'jui/themes',
'theme' => 'ghsv',
),
),
),
to add to your components (main.php configuration) to use a different jquery-ui theme in your application, just copy the generated (JQuery’s themeroller) “custom-theme” to an accessible directory (here [font=“Courier New”]jui/themes/ghsv[/font]).
Did I overlook a configuration option, which allows that already or is my idea a valuable enhancement?
Best regards,
Marco