diff --git a/recurring_events.tokens.inc b/recurring_events.tokens.inc index 85f70d181ecf091682e3255572a773d47d4eb611..3008e86540817e044c88838d613f0b4ef7b88925 100644 --- a/recurring_events.tokens.inc +++ b/recurring_events.tokens.inc @@ -85,11 +85,11 @@ function recurring_events_tokens($type, $tokens, array $data, array $options, Bu foreach ($tokens as $name => $original) { switch ($name) { case 'title': - $replacements[$original] = $event_instance->getInheritedTitle(); + $replacements[$original] = $event_instance->title->value; break; case 'description': - $replacements[$original] = $event_instance->getInheritedDescription(); + $replacements[$original] = $event_instance->description->value; break; case 'date': diff --git a/recurring_events.views.inc b/recurring_events.views.inc index 36e6714310b4951027f7584e2236eb0ea4d39128..f64c0b95dfa95f4c180c4470454a227c36da0ecc 100644 --- a/recurring_events.views.inc +++ b/recurring_events.views.inc @@ -29,25 +29,30 @@ function recurring_events_views_data_alter(array &$data) { ], ]; - // 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', - 'field_name' => 'title', - ], - ]; + // Create a views field for each of the inherited fields. + $inherited_fields = \Drupal::entityTypeManager()->getStorage('field_inheritance')->loadMultiple(); + $set = FALSE; + if (!empty($inherited_fields)) { + foreach ($inherited_fields as $field) { + if ($field->id() == 'title') { + $data['eventinstance_field_data']['table']['base']['defaults']['field'] = 'title'; + $set = TRUE; + } + $data['eventinstance_field_data'][$field->id()] = [ + 'title' => $field->label(), + 'field' => [ + 'title' => $field->label(), + 'help' => t('The inherited @field field', [ + '@field' => $field->label(), + ]), + 'id' => 'inherited_field', + 'field_name' => $field->id(), + ], + ]; + } + } - // 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', - 'field_name' => 'description', - ], - ]; + if (!$set) { + $data['eventinstance_field_data']['table']['base']['defaults']['field'] = 'id'; + } } diff --git a/src/Entity/EventInstance.php b/src/Entity/EventInstance.php index b000dd9a3493aed7ce86ac36f732db61e5df18db..200a13fba20879e091c0e9f7239f2af7394adc76 100644 --- a/src/Entity/EventInstance.php +++ b/src/Entity/EventInstance.php @@ -410,24 +410,4 @@ 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; - } - } diff --git a/src/Plugin/views/field/EventInstanceDescription.php b/src/Plugin/views/field/EventInstanceDescription.php deleted file mode 100644 index 84bc6c28b86db8d3a185de45e5d436ed81e576f6..0000000000000000000000000000000000000000 --- a/src/Plugin/views/field/EventInstanceDescription.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -namespace Drupal\recurring_events\Plugin\views\field; - -use Drupal\views\Plugin\views\field\EntityField; - -/** - * Field handler to show the inherited event instance description. - * - * @ingroup views_field_handlers - * - * @ViewsField("eventinstance_description") - */ -class EventInstanceDescription extends EntityField { - -} diff --git a/src/Plugin/views/field/EventInstanceTitle.php b/src/Plugin/views/field/EventInstanceTitle.php index a1564494a9cbb7780e6a7bf128a01380aebfff86..00c7107a78785919b0e00c8d8fd16f4094d1976b 100644 --- a/src/Plugin/views/field/EventInstanceTitle.php +++ b/src/Plugin/views/field/EventInstanceTitle.php @@ -5,12 +5,12 @@ namespace Drupal\recurring_events\Plugin\views\field; use Drupal\views\Plugin\views\field\EntityField; /** - * Field handler to show the inherited event instance title. + * Field handler to show the inherited field data. * * @ingroup views_field_handlers * - * @ViewsField("eventinstance_title") + * @ViewsField("inherited_field") */ -class EventInstanceTitle extends EntityField { +class InheritedField extends EntityField { }