Community Documentation

D7 to D8 tutorial: pathinfo module

Last updated March 11, 2013. Created by cam8001 on March 9, 2013.
Log in to edit this page.

This is a live step-by-step tutorial of my process of porting pathinfo module form Drupal 7.x to Drupal 8.x as part of the global sprint weekend, March 9th-10th, 2013.

The commit of Drupal 8 I was working against is:

* 957b556 - (HEAD, origin/HEAD, origin/8.x, 8.x) Issue #1932596 by ACF: Change site_name() into config in userpasswordreset.test and formtest. (4 hours ago)

Prerequisites

I installed a copy of Drupal 8 locally to test against. With that done:

  • Start a new branch of my module: $ git checkout -b 8.x-1.x
  • On my first push, create a new upstream branch git push --set-upstream origin 8.x-1.x
  • Create a development release

Steps to upgrade

Problem Reason Solution Commit
Can't enable module. .info files are now .info.yml files Rename file and change to YAML format. 1241617
Using variable_* functions instead of CMI. Site information variables converted to config system How to upgrade variables into configuration efbe1eb
Config form doesn't change variables stored via CMI. system_settings_form() deprecated in favour of system_config_form() or \Drupal\system\SystemConfigFormBase Refactor form to use system_config_form(). b4c2b57
Config form implemented procedurally. While I used system_config_form() above, the preferred method is to extend \Drupal\system\SystemConfigFormBase. Refactor form to be implemented via a routing.yml, and a controller class. e9c4566
Some paths (like admin/structure/views) are not parsed correctly by pathinfo. New Symfony-based routing system Use "request" and "controller_resolver" Drupal services to find callback. Can't get this to work. Pattern is
$request = Drupal::service('request');
$foo = $request->attributes->all();

There's some issue with multiple requests on one page load. Will come back to this.
I want to use the new theming system, Twig. Completely new theme/template system: Twig Create a templates/pathinfo-served-by.html.twig file, move theme function to preprocess. This can be useful: Theming Drupal 8 47086f2

Notes

I have to admit, somewhat embarassingly, that the module worked almost perfectly after my first commit above. Drupal 8 still has many Drupal 7 API calls intact, but I wanted to upgrade it to use D8 paradigms, so I kept going.

Page status

About this page

Drupal version
Drupal 8.x
Audience
Contributors, Programmers
Level
Intermediate
Keywords
d8
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.