1

I watched a tutorial on Drupal module development, and the namespace he used didn't include modules or src in the yml file (it is around 4:30). I'm sure this is a basic PHP question, but why didn't he have to put in those directories?

  • 1
    The summary here explains it pretty nicely – Clive Jun 2 '16 at 20:29
7

"Why", in a general sense, is for convenience. Drupal 8 uses PSR-4 autoloading and maps the respective module namespaces to each module's src/ directory. See drupal_classloader_register():

function drupal_classloader_register($name, $path) {
  $loader = \Drupal::service('class_loader');
  $loader->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src');
}

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.