3

I'm finding Drupal 8 a pretty steep learning curve, and quite often when I do find a solution that works PhpStorm tells me that the function I'm using is deprecated.

E.g. this answer shows how to list a bundles fields, however entityManager is deprecated and will removed before Drupal 9.

How long before Drupal 9 will this be removed? Like next week, next month, next year or in several years just before D9 is released.

Do I need to worry about using deprecated functions? Is it best practice to avoid them all together?

1 Answer 1

4

I don't have a reference handy, but I had the conversation about removal with one of the Drupal committers this weekend.

Right now, the committers will not remove any functions from core that are marked as deprecated.

Currently, there is no work being done on Drupal 9. When the 9.0.x branch gets forked from 8.x.y, they will start to accept patches against 9.0.x that remove deprecated functions.

However, there is work to remove usage of deprecated functions in core. For example, format_date() is marked as deprecated. This function will remain until 9.0.0 is released, and it will never actually be removed from any 8.x.y version. However, patches against 8.x.y will be accepted to replace format_date() in core with use of the date formatter service. And, in general, no new usages of deprecated functions are allowed in patches (there are some small exceptions for this for consistency sake, mainly in tests).

Should you use them? In general, no. Typically, a deprecated function was a placeholder from Drupal 7 while Drupal 8 was being developed that didn't get replaced (eg, format_date()), or left for backwards compatibility as Drupal 8 got refactored (eg, the Entity Manager service). Nearly all of the docs on deprecated functions describe what should be done instead. In PhpStorm, Command-B will take you to the function definition, and Command-[ will take you back to where you were.

4
  • Command-[ is taking me to the top of the class as opposed to back where I was? I've tried to find a back shortcut in PhpStorm before but never found one...
    – Felix Eve
    Commented May 3, 2016 at 23:40
  • 1
    @FelixEve Could be a key mapping thing. That works for me. You can also use the menu, Navigate -> Back. That will show you the key mapping, too, if one is set. Also check out jetbrains.com/help/phpstorm/2016.1/…
    – mpdonadio
    Commented May 3, 2016 at 23:44
  • Nice one - back for me is Ctrl Alt Left.
    – Felix Eve
    Commented May 4, 2016 at 0:41
  • Nice answer. One thing to add is that for most deprecated functions, the function actually implements the new way of doing it, just go there and copy that code. EntityManager is a bit more complicated sometimes because things moved to many new services and it is not immediately visible to where. drupal.org/node/2549139 is a great overview for that.
    – Berdir
    Commented May 4, 2016 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.