diff --git a/farm_crop_plan.module b/farm_crop_plan.module index 0105034..bb9a288 100644 --- a/farm_crop_plan.module +++ b/farm_crop_plan.module @@ -67,3 +67,21 @@ function farm_crop_plan_form_plan_record_crop_planting_edit_form_alter(&$form, F $form['plant']['#access'] = FALSE; } } + +/** + * Implements hook_form_FORM_ID_alter(). + */ +function farm_crop_plan_form_quick_form_planting_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { + + // Alter the planting quick form, if a crop plan was specified. + /** @var \Drupal\plan\Entity\PlanInterface $plan */ + $plan = \Drupal::entityTypeManager()->getStorage('plan')->load(\Drupal::request()->query->get('plan')); + if (empty($plan) || $plan->bundle() !== 'crop') { + return; + } + + // If the crop plan has a season, set the plant season default value. + if (!empty($plan->get('season')->referencedEntities())) { + $form['seasons']['#default_value'] = $plan->get('season')->referencedEntities(); + } +}