Skip to content

Commit

Permalink
Update to use farm_timeline render element.
Browse files Browse the repository at this point in the history
  • Loading branch information
paul121 authored and mstenta committed Sep 23, 2024
1 parent f44c95e commit 55ac7a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions farm_crop_plan.routing.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
farm_crop_plan.timeline_by_planting:
path: /plan/{plan}/timeline/plant-type
farm_crop_plan.timeline_by_plant_type:
path: /plan/{plan}/timeline/plant_type
defaults:
_controller: Drupal\farm_crop_plan\Controller\CropPlanTimeline::byPlantType
requirements:
Expand Down
15 changes: 7 additions & 8 deletions src/Form/CropPlanTimelineForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\farm_crop_plan\CropPlanInterface;
use Drupal\plan\Entity\PlanInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -73,10 +74,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $plan = N

// Toggle the timeline view by plant type (default) or by location.
$mode_options = [
'plant-type' => $this->t('Plant type'),
'plant_type' => $this->t('Plant type'),
'location' => $this->t('Location'),
];
$mode_default = 'plant-type';
$mode_default = 'plant_type';
$form['options'] = [
'#type' => 'details',
'#title' => $this->t('Options'),
Expand Down Expand Up @@ -106,15 +107,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $plan = N
// Get the selected display mode from form state.
$display_mode = $form_state->getValue('mode', $mode_default);

// Render the timeline gantt chart.
// Render the timeline.
$row_url = Url::fromRoute("farm_crop_plan.timeline_by_$display_mode", ['plan' => $plan->id()]);
$form['timeline']['gantt'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#type' => 'farm_timeline',
'#rows' => [$row_url->setAbsolute()->toString()],
'#attributes' => [
'id' => 'timeline',
'data-table-header' => $mode_options[$display_mode],
'data-timeline-url' => 'plan/' . $plan->id() . '/timeline/' . $display_mode,
'data-timeline-instantiator' => 'farm_crop_plan',
],
'#attached' => [
'library' => ['farm_crop_plan/timeline'],
Expand Down

0 comments on commit 55ac7a2

Please sign in to comment.