Porting Scanner Module to D8 - Part 1

2019-05-06

Christian Crawford

Porting Scanner Module to D8 - Part 1

First part of tutorial on porting Drupal 7 scanner module to Drupal 8, covering routing, menu links, permissions, and forms.

This is the first part in a series of posts on porting the scanner module to Drupal 8.

I recently found myself needing to port the scanner module to Drupal 8. When I first embarked on this endeavor, I estimated that it would take me a three or four days to get it to feature parity with the Drupal 7 version. When all was said and done however, I had put in roughly 105 hours.

Routing

Instead of adding a hook_menu function to our module file we create a mymod.routing.yml:

scanner.admin_content:
  path: 'admin/content/scanner'
  defaults:
    _title: 'Search and Replace Scanner'
    _form: '\Drupal\scanner\Form\ScannerForm'
  requirements:
    _permission: 'administer nodes'

Permissions

administer scanner settings:
  title: 'Administer scanner settings'
perform search and replace:
  title: 'Perform search and replace'
  description: 'Users with this permission can perform both the search and replace operations.'

Forms

The D8 port contains 4 forms. Two extend ConfirmFormBase which has getCancelUrl() and getQuestion() methods.

This topic is continued in part two.