I think it's better to replace !empty by is_array, it should be more backward-compatible (most likely underlying idea is to don't pass full set of fields to setHeadData):
$this->_styleSheets = (isset($data['styleSheets']) && is_array($data['styleSheets'])) ? $data['styleSheets'] : $this-_styleSheets;
-------
Best regards,
Denis Ryabov
19.03.2013, 18:57, "piotr_cz" <
pkoni...@hotmail.com>:
> r...: I think your method won't work in case when in '_scripts' array
> there is only '..mootools.js'.
>
> Denis: Thanks!
>
> Folks, I think this behavior is buggy. We need to fix that for our
> sake and to contribute to our children's better future.
>
> I suggest replacing
> $this->_styleSheets = (isset($data['styleSheets']) && !
> empty($data['styleSheets'])) ? $data['styleSheets'] : $this-
>
>> _styleSheets;
>
> with
> $this->_styleSheets = (isset($data['styleSheets']) && !
> empty($data['styleSheets'])) ? $data['styleSheets'] : array();
>
> in
https://github.com/joomla/joomla-cms/blob/master/libraries/joomla/document/html/html.php#L165.
>
> What do you think?
> The reason is that at the moment 'setHeadData' method behaves kind
> like 'merge', so there's no way how to remove head items (just add).
>
> On Mar 19, 2:49О©╫pm, Denis Ryabov <
drya...@yandex.ru> wrote:
>
>>> О©╫What is the recommended way to remove stylesheet from document, when
>>> О©╫there's only one (template.css)?
>>> О©╫Works (but doesn't feel right):
>>> О©╫- unset($doc->_styleSheets['template.css']);
>> О©╫Yes, the best way is to use $_styleSheets property as it's public even in Joomla!3.0.
>> О©╫Except of this one, I know 2 solutions only (I keep them in mind in the case Joomla! team would make $_styleSheets private):
>>
>> О©╫1. Add "empty" css file using data-uri scheme:
>>
>> О©╫$headData = $doc->getHeadData();
>> О©╫unset ($headData['styleSheets']['template.css']);
>> О©╫if(!count($headData['styleSheets']))
>> О©╫О©╫ О©╫ $headData['styleSheets'] = array('data:text/css,'=>array('mime'=>'text/css'));
>> О©╫$doc->setHeadData($headData);
>>
>> О©╫2. Add a marker instead of filename and remove that link tag in onAfterRender event:
>>
>> О©╫$headData = $doc->getHeadData();
>> О©╫unset($headData['styleSheets']['template.css']);
>> О©╫if(!count($headData['styleSheets']))
>> О©╫{
>> О©╫О©╫ О©╫ $headData['styleSheets'] = array('MY_MARKER_HERE'=>array('mime'=>'text/css'));
>> О©╫О©╫ О©╫ $app = JFactory::getApplication();
>> О©╫О©╫ О©╫ $app->registerEvent('onAfterRender', 'RemoveMarkerEvent');}
>>
>> О©╫$doc->setHeadData($headData);
>>
>> О©╫class RemoveMarkerEvent extends JEvent
>> О©╫{
>> О©╫О©╫ О©╫ public function onAfterRender()
>> О©╫О©╫ О©╫ {
>> О©╫О©╫ О©╫ О©╫ О©╫ $doc = JFactory::getDocument();
>> О©╫О©╫ О©╫ О©╫ О©╫ $buffer = $doc->getBuffer('component');
>> О©╫О©╫ О©╫ О©╫ О©╫ $buffer = preg_replace('/<link [^>]*href="MY_MARKER_HERE"[^>]*>/s', '', $buffer);
>> О©╫О©╫ О©╫ О©╫ О©╫ $doc->setBuffer($buffer, 'component');
>> О©╫О©╫ О©╫ }
>>
>> О©╫}
>>
>> О©╫--
>> О©╫Best regards,
>> О©╫Denis Ryabov