2

In my Joomla component i add a style sheet according to phpstorm is $document->addStyleSheet deprecated.

This is the code i use:

$uri = JUri::base();
$document = JFactory::getDocument();

$document->addStyleSheet(JUri::base() .  "components/com_exampe/views/stats/tmpl/style.css");

I also tryed this code:

JHtml::stylesheet('com_hccxmlkadernet/views/statistiek/tmpl/style.css', array(), true);

But thats also deprecated

Can some one tell what te correct way is to do this ?

  • I dont know why you say it is deprecated but this page suggest the first method you used. https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page – Amit Ray Sep 27 '18 at 15:48
  • 1
    @Bas I'll urge you to post your Joomla-specific questions at Joomla Stack Exchange because that is where Team Joomla wants you to post your questions. When Joomla users (askers and answers) are all looking in one place, everyone can be more efficient and productive. You may or may not have noticed that in the **Administrator** backend, there is a **Help** menu and the 2nd last item says **Stack Exchange** <-- that's Joomla Stack Exchange. Hope we see you there in the future. – mickmackusa Sep 28 '18 at 14:26
  • @mickmackusa Thanks i didn't know that wil do that the next thime – Bas van den Dikkenberg Sep 29 '18 at 12:39

2 Answers2

3

According to this page: https://api.joomla.org/cms-3/classes/Joomla.CMS.Document.Document.html#method_addStyleSheet

It says addStyleSheet() is deprecated. Actually the whole method is not deprecated, it's just that the expected arguments have slightly changed.

v4.0 (url, mime, media, attribs) method signature is deprecated, use (url, options, attributes) instead.

So, as long as you use;

$document->addStyleSheet($url)

You don't need to worry about anything, you are good to go (because arg1 is $url in both version).

Don't use JHTML. It has been deprecated in J2.5 and removed from J3.x:

It used to be possible to do this with JHTML, however, this was deprecated in Joomla 2.5 and removed in Joomla 3.x.

reference: https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Must Ckr
  • 310
  • 2
  • 5
0

The bug is in Joomla. I contacted phpstorm This was the answer

That's an incorrect usage of the tag: http://docs.phpdoc.org/references/phpdoc/tags/deprecated.html You can't deprecate a certain signature, only the whole structural element (the method in this case). Is It Possible to Deprecate Method Parameters in PHP?