Aug 6, 2014

Drupal 8: alpha11 --> alpha13: AliasManager, hook_help(), getCancelRoute()

In upgrading the Optimizely module from Drupal 8, alpha 11 to alpha 13, I had to make the following changes. Yep, the D8 APIs have not been frozen!

The class Drupal\Core\Path\AliasManager has had two of its methods renamed.

getPathAlias() --> getAliasByPath()
getSystemPath() --> getPathByAlias()

For the earlier post about using the Alias Manager, see

The signature for hook_help() has changed.

alpha 11:  hook_help($path, $arg)

alpha 13:  hook_help($route_name, $route_match)

In other words, the first parameter is no longer a url path. Instead, it is the name of a route as defined in the module's .routing.yml file or possibly as defined elsewhere.

function optimizely_help($route_name, $route_match) {
  switch ($route_name) {

    case '':
      return t('Optimizely is a third party service ...');

    case 'optimizely.listing':
      return t('... A listing of the Optimizely ...');
    // Other cases ...

Note the special route in the first case of the switch statement. It corresponds to path admin/help#optimizely for the site's general help pages.

The obsolete post on hook_help() is at hook_help() is no longer unchanged from Drupal 7.

Fatal error: Call to a member function toRenderArray() on a non-object in  ...\opti\core\lib\Drupal\Core\Form\ConfirmFormHelper.php on line 44

This error message came up when I clicked on a link to bring up a delete confirmation form.

After looking at the code in class ConfirmFormHelper and checking how it is used by other core classes, I changed the return value of getCancelRoute() in my own class DeleteForm like this.


  public function getCancelRoute() {
    return array('route_name' => 'optimizely.listing');


use Drupal\Core\Url;

  public function getCancelRoute() {
    return new Url('optimizely.listing');


For the earlier post about creating a delete confirmation form, see


function hook_help()!modules!system!system.api.php/function/hook_help/8

Creating a content entity type in Drupal 8
"Call to a member function toRenderArray() on a non-object"

Releases for Drupal core[]=7234

1 comment: