Porting a Drupal 7 module
- Porting a Drupal 7 module to Drupal 8 (a real life example) #1- kicking off
- Porting a Drupal 7 module to Drupal 8 (a real life example) #2- basic routing
- Porting a Drupal 7 module to Drupal 8 (a real life example) #3- configuration form
- Porting a Drupal 7 module to Drupal 8 (a real life example) #4- making it work (almost)
- Porting a Drupal 7 module to Drupal 8 (a real life example) #5- css and js modifications
Drupal 8’s beta version was released a few month ago and now it is time to start porting modules. To demonstrate how to do it, we’re going to use a real module called scroll_to_top, which allow us to scroll to top when we are reading an article and we want to go to the menu for example.
If you prefer watching videos, here is the screencast version of this series.
Getting your hands dirty: .info file conversion
To start, we have to let Drupal know about our module. So, in Drupal 7 we did that using the .info file, but in Drupal 8 that was replaced by the .info.yml file.
name = Scroll to top description = Scroll to top module. package = Other core = 7.x files = scroll_to_top.css files = scroll_to_top.js configure = admin/config/user-interface/scrolltotop ; Information added by drupal.org packaging script on 2012-11-30 version = "7.x-2.1" core = "7.x" project = "scroll_to_top" datestamp = "1354268940"
name: 'Scroll to top' description: 'Scroll to top module.' core: 8.x type: module configure: scroll_to_top.form
As you can see the structure of this file is not too different than Drupal 7 .info file and a typical content would look like the above one. For more information, see https://www.drupal.org/node/2000204.
Once you created this file, you can now go to the module installation page and install it. Although it doesn’t do anything yet, we just started 🙂