Port of the adsense module from Drupal 7 to Drupal 8. Lessons learned, and a few of the major differences between D7 and D8 module development. Advise to use the drupalmoduleupgrader module to handle the automatic parts.
Baheyeldin (4.7 and 5) • I ported the module to Drupal 6 in 2008 (with a backport to Drupal 5), and have been maintaining it ever since. • Support for pre-2007 AdSense ad codes and for the new Managed Ads (synchronous and asynchronous). Also supports Custom search engines. • Ad-blocker detection. • Used in over 12.000 sites.
of 7>8 ports (currently very incomplete) ‣ https://www.drupal.org/update/modules/7/8 ‣ Drupal Module Upgrader (DMU) module ‣ https://www.drupal.org/project/drupalmoduleupgrader ‣ Beta releases are out, and Drupal 8.0.0 will be released “soon”. ‣ It’s only called Drupal because it’s the work of the same community ‣ Drupal is mostly object-oriented now (exc. some hook_*) ‣ Symfony, HTML5, Twig, YAML, WYSIWYG editor, etc.
= ‘', $edit = array()) function adsense_managed_block_view($delta = ‘') managed/src/Plugin/Block/ManagedAdBlock.php /** * Provides an AdSense managed ad block. * * @Block( * id = "adsense_managed_ad_block", * admin_label = @Translation("Managed ad"), * category = @Translation("Adsense") * ) */ class ManagedAdBlock extends BlockBase implements AdBlockInterface { public function defaultConfiguration() public function build() public function buildConfigurationForm(array $form, FormStateInterface $form_state) public function blockSubmit($form, FormStateInterface $form_state) public function getCacheMaxAge() public function isCacheable() }
code obsoleted in Drupal 8 ‣ DMU converted most of this, leaving dead code and @FIXMEs ‣ Converted all the sub-modules to OO plugins ‣ Only 3 .module files remain ‣ adsense.module: 2 theme and 1 API function ‣ adsense_managed.module: 1 hook_preprocess_block function ‣ revenue_sharing_basic.module: port to D8 TBD
module.info to module.info.yml • Converts your hook_menu() to module.routing.yml • Converts the configuration forms to src/Form/FormName.php • etc. • NOT a magic wand. You still have to port your functionality to work with D8
won’t be a wait period between core and Views releases. • It’s a complete rewrite of your code. Approach it as a new project. • If you can, make it a plug-in. • Make your code shine with objects. • Don’t stop until that .module file is empty.