My goal:
- If a person select a start date the end date is 1 hour later, without the need of selecting the end date (2)
Normally the Form provides 2 selections of dates, start date (1) and end date (2).
I am able to succesfully hide end date (2), in bee_add_reservation_form, with hook_form_alter().
With hook_form_alter() in mymodule.module
I modified a form render array.
$end_date
is defined in class AddReservationForm
of the bee module.
How to alter or override the $end_date
in class AddreservationForm
?
I would like to modify it like so:
$end_date = clone($start_date);
$end_date->modify('+1 hour');
Although While doing this within the class this Error occurs:
Error: Call to protected method Drupal\bee\Form\AddReservationForm::getAvailableUnits() from global scope
mymodule.module:
<?php
/**
* Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == 'bee_add_reservation_form') {
/**
* Extends the AddReservationForm class.
*
*/
$form['end_date'] = [
// hides end_date
'#type' => 'hidden',
];
$form['repeat'] = [
// hides repeat option
'#type' => 'hidden',
];
// start date from protected method
// $start_date = new \DateTime($start_date->format('Y-m-d H:i'));
$start_date = AddReservationForm::getAvailableUnits($start_date);
// end date should be always 1 hour later
$end_date = clone($start_date);
$end_date->modify('+1 hour');
}
$end_date = clone($start_date);
to somehow override a similar line in a method within theAddReservationForm
form class? If so I'd strongly recommend reading up on some PHP OO basics, that just isn't how it works$end_date
is declared in different methods as anew \Datetime ...
and a input field. I would like to hideend_date
and is automatically + 1 hour