Commit 2af2426a authored by nicola85's avatar nicola85

BAT-88: Improve order item label for bee bookings

parent f8c93ab2
...@@ -4,8 +4,12 @@ use Drupal\Core\Form\FormStateInterface; ...@@ -4,8 +4,12 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Render\Markup;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\views\ViewExecutable;
use Drupal\office_hours\OfficeHoursDateHelper; use Drupal\office_hours\OfficeHoursDateHelper;
use Drupal\commerce_product\Entity\ProductType; use Drupal\commerce_product\Entity\ProductType;
use Drupal\commerce_product\Entity\ProductVariationType; use Drupal\commerce_product\Entity\ProductVariationType;
...@@ -647,6 +651,30 @@ function bee_bat_api_events_index_calendar_alter(&$events, $context) { ...@@ -647,6 +651,30 @@ function bee_bat_api_events_index_calendar_alter(&$events, $context) {
} }
} }
/**
* Implements hook_views_pre_render().
*/
function bee_views_pre_render(ViewExecutable $view) {
if ($view->id() == 'commerce_order_item_table') {
foreach ($view->result as $id => $result) {
if ($result->_entity->bundle() == 'bee') {
if (($booking = $result->_entity->get('field_booking')->entity) &&
($node = $result->_entity->get('field_node')->entity)) {
$url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()]);
$link = Link::fromTextAndUrl($node->label(), $url)->toString();
$start_date = $booking->get('booking_start_date')->value;
$end_date = $booking->get('booking_end_date')->value;
$title = Markup::create('Booking for ' . $link . ' from ' . $start_date . ' to ' . $end_date);
$view->result[$id]->_entity->set('title', $title);
}
}
}
}
}
/** /**
* @param $field_name * @param $field_name
* @param $node_type * @param $node_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment