Skip to content

Commit

Permalink
wip form alter
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed Feb 13, 2024
1 parent 4e31cef commit c006046
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions farm_crop_plan.module
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit c006046

Please sign in to comment.