Skip to content
Snippets Groups Projects
Commit c2955f11 authored by Owen Bush's avatar Owen Bush
Browse files

Initial commit of the views integration

parent 7d5d402f
No related branches found
No related tags found
No related merge requests found
date_format: 'F jS, Y h:iA'
......@@ -4,16 +4,27 @@ recurring_events.eventseries.config:
mapping:
interval:
type: integer
label: 'The interval between times when creating events'
label: 'The interval between times when creating event series'
min_time:
type: string
label: 'The earliest an event can start'
max_time:
type: string
label: 'The latest an event can start'
date_format:
type: string
label: 'The formatting of dates when displaying event series'
time_format:
type: string
label: 'The formatting of times when creating events'
label: 'The formatting of times when creating event series'
days:
type: string
label: 'The days of the week available when creating events'
\ No newline at end of file
label: 'The days of the week available when creating event series'
recurring_events.eventinstance.config:
type: config_object
label: 'Recurring Events Instance Config'
mapping:
date_format:
type: string
label: 'The formatting of dates when displaying event instances'
\ No newline at end of file
<?php
/**
* @file
* Views functionality for the recurring_events module.
*/
/**
* Implements hook_views_data_alter().
*/
function recurring_events_views_data_alter(array &$data) {
// Create a field to show the number of instances of an eventseries.
$data['eventseries_field_data']['eventseries_instance_count'] = [
'title' => t('Event series instance count'),
'field' => [
'title' => t('Event series instance count'),
'help' => t('The number of event instances in a series.'),
'id' => 'eventseries_instance_count',
],
];
// Create a field to show the start date of an event series.
$data['eventseries_field_data']['eventseries_start_date'] = [
'title' => t('Event series start date'),
'field' => [
'title' => t('Event series start date'),
'help' => t('The date on which an event first occurs.'),
'id' => 'eventseries_start_date',
],
];
// Create a field to show the inherited title of an event instance.
$data['eventinstance_field_data']['eventinstance_title'] = [
'title' => t('Event instance title'),
'field' => [
'title' => t('Event instance title'),
'help' => t('The inherited title of an event instance.'),
'id' => 'eventinstance_title',
],
];
// Create a field to show the inherited description of an event instance.
$data['eventinstance_field_data']['eventinstance_description'] = [
'title' => t('Event instance description'),
'field' => [
'title' => t('Event instance description'),
'help' => t('The inherited description of an event instance.'),
'id' => 'eventinstance_description',
],
];
}
......@@ -426,4 +426,24 @@ class EventInstance extends EditorialContentEntityBase implements EventInterface
return $this->get('eventseries_id')->entity;
}
/**
* Get event instance inherited title.
*
* @return string
* The event instance inherited title.
*/
public function getInheritedTitle() {
return $this->get('title')->value;
}
/**
* Get event instance inherited description.
*
* @return string
* The event instance inherited description.
*/
public function getInheritedDescription() {
return $this->get('description')->value;
}
}
......@@ -70,7 +70,7 @@ use Drupal\user\UserInterface;
*
* @ContentEntityType(
* id = "eventseries",
* label = @Translation("Event entity"),
* label = @Translation("Event series entity"),
* handlers = {
* "storage" = "Drupal\Core\Entity\Sql\SqlContentEntityStorage",
* "list_builder" = "Drupal\recurring_events\EventSeriesListBuilder",
......@@ -499,6 +499,16 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
return $date;
}
/**
* Get the number of instances.
*
* @return int
* A count of instances.
*/
public function getInstanceCount() {
return count($this->get('event_instances')->getValue());
}
/**
* Get EventSeries recur type.
*
......
......@@ -120,7 +120,7 @@ class EventSeriesListBuilder extends EntityListBuilder {
'#url' => $entity->toUrl(),
];
$row['type'] = $entity->recur_type->value;
$row['instances'] = count($entity->event_instances->getValue());
$row['instances'] = $entity->getInstanceCount();
$row['starts'] = $this->t('None');
if (!empty($entity->getSeriesStart())) {
$config = $this->config->get('recurring_events.eventseries.config');
......
<?php
namespace Drupal\recurring_events\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* Field handler to show the inherited event instance description.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventinstance_description")
*/
class EventInstanceDescription extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$event = $values->_entity;
return $event->getInheritedDescription();
}
}
<?php
namespace Drupal\recurring_events\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* Field handler to show the inherited event instance title.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventinstance_title")
*/
class EventInstanceTitle extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$event = $values->_entity;
return $event->getInheritedTitle();
}
}
<?php
namespace Drupal\recurring_events\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* Field handler to show the count of event instances.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventseries_instance_count")
*/
class EventSeriesInstanceCount extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$event = $values->_entity;
return $event->getInstanceCount();
}
}
<?php
namespace Drupal\recurring_events\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* Field handler to show the start date of an event series.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventseries_start_date")
*/
class EventSeriesStartDate extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$start_date = 'N/A';
$event = $values->_entity;
$event_start = $event->getSeriesStart();
if (!empty($event_start)) {
$format = \Drupal::config('recurring_events.eventseries.config')->get('date_format');
$start_date = $event_start->format($format);
}
return $start_date;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment