0

I am new to Drupal and I got stuck with the problem that I don't know how to debug even: I have made a simple module 'final', its structure:

Applications/MAMP/htdocs/drupal_dir_1/modules/final > ls
final.info.yml    final.routing.yml src

/Applications/MAMP/htdocs/drupal_dir_1/modules/final > ls src/Controller/
ExampleController.php

Files contents:

> cat final.info.yml
name: Final
type: module
description: This is an final module
core: 8.x⏎

> cat final.routing.yml
final.content:
  path: '/final'
  defaults:
    _controller: '\Drupal\final\Controller\ExampleController::content'
    _title: 'Hello world bitch!'
  requirements:
    _permission: 'access content'

> cat src/Controller/ExampleController.php
<?php
namespace Drupal\final\Controller;
use Drupal\Core\Controller\ControllerBase;
class ExampleController extends ControllerBase {
  public function content() {
    $build = [
      '#markup' => $this->t('Hello World, bitch!'),
    ];
return $build;
  }
} 
0

I believe you did not install the module

if you tried to install you would get

drush en final

ParseError: syntax error, unexpected 'final' (T_FINAL), expecting identifier (T_STRING) in /home/giorgos/share/gwebsites/dru8.dev/web/modules/custom/final/src/Controller/ExampleController.php on line 2 #0 /home/giorgos/share/gwebsites/dru8.dev/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/home/giorgos/s...') #1 [internal function]: Composer\Autoload\ClassLoader->loadClass('Drupal\final\Co...') ...

final is reserved keyword thus it confuses the php parser when it sees

namespace Drupal\final\Controller;

Can also be caught with my vscode setup and linter

enter image description here

You have to change final to something else but then you have to rename it elsewhere in your module (folder name, file names, reference to the class etc)

Otherwise the module is working fine.

  • Thank you very much! Kind of unexpected problem) – Nikolay Rozanov Mar 17 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.