1
votes

I'm having trouble getting Drupal 8 to load my custom module's classes from the same namespace. Here's what I've got:

<?php

namespace Drupal\sign_up\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
// ... snip ...

class StandardForm extends CLESignUpForm
{

Which all works perfectly well on my local environment. When deployed the server says: PHP Fatal error: Class 'Drupal\sign_up\Form\CLESignUpForm' not found in /path/to/drupal/modules/sign_up/src/Form/StandardForm.php on line 21

If I add the line:

include 'CLESignupForm.php';

It works just fine. But that defeats the purpose of auto-loading classes, doesn't it? get_declared_classes() does not show my base class .. or even the currently loaded class for that matter.

Any thoughts on how to make this particular environment comply? I've already loaded the db and config directly from my local setup where it's working. Could it be a php / apache setting somehow?

1
Why don't you add use Drupal\sign_up\Form\CLESignUpForm;? - Stanislav Agapov
Actually I thought it was unnecessary if they share the namespace? That must be a setting somewhere? - Brandon Prudent
There is no way for PHP to get know about your CLESignupForm class without help from you. So you must either use direct include statement or rely on Drupal's autoloading feature using use statement (preferred). - Stanislav Agapov
Even with 'use Drupal\sign_up\Form\CLESignUpForm;' it throws the same error. 'include' is the only thing that seems to solve it. The infuriating thing is it seems to work in every other environment. - Brandon Prudent

1 Answers

0
votes

Turns out I'm a knucklehead. CLESignUpForm is the incorrect capitalization of the type. The correct capitalization is CLESignupForm. Still not clear why it works in every other environment and not this one, but it makes me feel like there's a bit more sanity at least.