0

I have a D8 site with custom forms in a module. In the module there's a base class that extends FormBase, then subclass forms which extend my custom form base class. How can I obtain dynamically a list of the subclasses that extend my base class please?

Also, is this a good idea or an anti-pattern?

Thanks!

  • I am not sure if merely getting a dynamic list of subclasses is an anti-pattern. There isn't a use case or provided code to determine if it is best practice or not. Do you mean that is it an anti-pattern to have a base class that extends FormBase? – mradcliffe Sep 6 '16 at 13:35
  • Nope, extending FormBase is kosher, I'm cool with that. I'm saying if CustomFormBase extends FormBase, then I have several form classes which extend CustomFormBase, I'd love to have a way to dynamically get a list of classes (and therefore obtain form ids) that have extended CustomFormBase. I suggest it's an antipattern because maybe I need something registering these new forms, instead of merely extending and working backwards to getting a list of them dynamically. – Storsey Sep 6 '16 at 18:20
  • What is your use case for getting all the classes? Getting form ids doesn't seem to be a use case. – mradcliffe Sep 6 '16 at 18:32
  • Dynamically populating a select element with the classes as values in order to reference the forms via paragraphs.. – Storsey Sep 6 '16 at 18:48

Your Answer

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

Browse other questions tagged or ask your own question.