The Bee module has a addReservationFrom form class. I would like to override it.

I copied addReservationFrom to MyaddReservationForm and made the necessary modifications. This works as excepted, but MyaddReservationForm is in the original module and I would like to move the changes into a custom module.

I created a custom module, but when I move MyaddReservationForm to custom/my_reservations/src/Form, MyReservationsForm is not used.


name: my reservations
type: module
description: overrides bee reservation
package: custom
core_version_requirement: ^9 || ^10
  - bee
  - bat:bat_booking
  - bat:bat_event_series
  - bat:bat_event_ui
  - office_hours:office_hours


  path: '/my-reservations/my-reservations'
    _title: 'My reservations'
    _form: 'Drupal\my_reservations\Form\MyReservationsForm'
    _title_callback: '\Drupal\bee\Controller\MyBeeController::addReservationTitle'
    _permission: 'access content'


namespace Drupal\my_reservations\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\bat_event_series\Entity\EventSeries;
use Drupal\commerce_cart\CartManagerInterface;
use Drupal\commerce_cart\CartProviderInterface;
use Drupal\node\NodeInterface;
use Drupal\node\Entity\Node;
use Drupal\office_hours\OfficeHoursDateHelper;
use RRule\RRule;
use Symfony\Component\DependencyInjection\ContainerInterface;

 * Provides a My reservations form.
class MyReservationsForm extends FormBase {
  // ...
  • If this is a new route you need to alter the existing route and change the _form property. Alternatively, do a form alter.
    – Kevin
    Aug 10, 2022 at 11:34

1 Answer 1


In Drupal you have two options that are preferable to copying the file across as you've done. Drupal is OOP, and also contains alter hooks, which are meant to prevent code from being copied.

The common way to do what you are doing is to use hook_form_alter(), to massage the form render array and alter it to make the form you want. This is good for minor changes. For major changes, you can extend the form using OOP principles, then [replace the form used at the route][1].

  • Due to major changes I prefer to extend the form using OOP principles. I don't know how to do this exactly. Therefore I will create a new question, thnx
    – Joehoe
    Aug 19, 2022 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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