Its a php issue but maybe I missing a 'Drupal 8' thing ?

I have this custom module :

> mymodule (directory)
    > mymodule.module
    > src (directory)
        > myclass.php
        > myclassinterface.php

In myclass.php, I have :

namespace Drupal\mymodule\src;

Class myclass implements myclassinterface{

In my mymodule.module, I have :

use Drupal\mymodule\src\myclass;
function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
    $test = new myclass();
    // or $test = new Drupal\mymodule\src\myclass(); // same error, class not found

And when I load a page via my browser, I get a blank page and apache log tell me the class 'Drupal\mymodule\src\myclass' not found.

I don't understand..where is my mistake ?


Drop the "src" from your namespace and use statements. Wipe the cache after making that change.

  • remove src is the solution, thanks =) can you explan why the "src" cause issue ? Sep 15 '16 at 1:38
  • 4
    The autoloader looks in the src folder, so there is no need to specify it.
    – Kevin
    Sep 15 '16 at 1:40
  • 4
    Here is a link on how it works drupal.org/node/2156625
    – Kevin
    Sep 15 '16 at 1:41

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.