Skip to content

Commit

Permalink
Merge pull request #767 from USEPA/EPAD8-1808-add-to-calendar-descrip…
Browse files Browse the repository at this point in the history
…tion

[EPAD8-1808] - adds add_to_cal_description field to events, creates n…
  • Loading branch information
azinck authored Nov 14, 2022
2 parents 33194a4 + 7caa017 commit eb79951
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 18 deletions.
4 changes: 3 additions & 1 deletion services/drupal/composer.patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@
"Allow specifying links to specific paths on the other environments": "https://www.drupal.org/files/issues/2022-06-23/environment_indicator-configure_switcher_path-3274102-5.patch"
},
"drupal/addtocal":{
"patch for smart date": "https://www.drupal.org/files/issues/2022-02-10/3224310-4-smartdate-integration.patch"
"patch for smart date": "https://www.drupal.org/files/issues/2022-02-10/3224310-4-smartdate-integration.patch",
"patch for newline handling": "https://www.drupal.org/files/issues/2022-09-26/addtocal-fix-newlines-3311870-2.patch",
"patch for escaping commas in location field": "patches/addtocal-escape_location_commas-3319571-3-rolled-to-apply-on-3311870-2.patch"
},
"drupal/show_email": {
"Fix config schema": "https://www.drupal.org/files/issues/2020-10-15/show_email-config_schema_issues-3177062-2.patch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ langcode: en
status: true
dependencies:
config:
- field.field.node.event.field_add_to_cal_description
- field.field.node.event.field_channel
- field.field.node.event.field_date
- field.field.node.event.field_daterange
Expand Down Expand Up @@ -102,7 +103,7 @@ third_party_settings:
label: 'Additional Fields'
region: content
parent_name: ''
weight: 12
weight: 13
format_type: tabs
format_settings:
classes: ''
Expand All @@ -115,7 +116,7 @@ mode: default
content:
created:
type: datetime_timestamp
weight: 14
weight: 15
region: content
settings: { }
third_party_settings: { }
Expand All @@ -129,6 +130,19 @@ content:
multiple: false
required: true
third_party_settings: { }
field_add_to_cal_description:
type: string_textarea
weight: 7
region: content
settings:
rows: 5
placeholder: ''
third_party_settings:
maxlength:
maxlength_js: 1024
maxlength_js_label: 'Content limited to @limit characters, remaining: <strong>@remaining</strong>'
maxlength_js_enforce: false
maxlength_js_truncate_html: false
field_channel:
type: options_buttons
weight: 13
Expand Down Expand Up @@ -203,15 +217,15 @@ content:
third_party_settings: { }
field_event_host:
type: string_textfield
weight: 10
weight: 11
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_event_type:
type: options_select
weight: 9
weight: 10
region: content
settings: { }
third_party_settings: { }
Expand All @@ -233,7 +247,7 @@ content:
third_party_settings: { }
field_hublinks:
type: entity_reference_autocomplete
weight: 11
weight: 12
region: content
settings:
match_operator: CONTAINS
Expand All @@ -259,7 +273,7 @@ content:
third_party_settings: { }
field_links:
type: link_default
weight: 8
weight: 9
region: content
settings:
placeholder_url: ''
Expand Down Expand Up @@ -294,7 +308,7 @@ content:
maxlength_js_truncate_html: false
field_paragraphs:
type: paragraphs
weight: 7
weight: 8
region: content
settings:
title: Paragraph
Expand Down Expand Up @@ -331,27 +345,27 @@ content:
third_party_settings: { }
moderation_state:
type: moderation_state_default
weight: 18
weight: 19
region: content
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
weight: 15
weight: 16
region: content
settings:
display_label: true
third_party_settings: { }
status:
type: boolean_checkbox
weight: 17
weight: 18
region: content
settings:
display_label: true
third_party_settings: { }
sticky:
type: boolean_checkbox
weight: 16
weight: 17
region: content
settings:
display_label: true
Expand All @@ -366,7 +380,7 @@ content:
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 13
weight: 14
region: content
settings:
match_operator: CONTAINS
Expand All @@ -375,7 +389,7 @@ content:
placeholder: ''
third_party_settings: { }
url_redirects:
weight: 19
weight: 20
region: content
settings: { }
third_party_settings: { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ langcode: en
status: true
dependencies:
config:
- field.field.node.event.field_add_to_cal_description
- field.field.node.event.field_channel
- field.field.node.event.field_date
- field.field.node.event.field_daterange
Expand Down Expand Up @@ -59,7 +60,7 @@ content:
tokenized: ''
description:
value: field_description
tokenized: ''
tokenized: 'This value is dynamically generated in epa_core_addtocal_alter().'
past_events: false
separator: '-'
date_format: 'Y-m-d\TH:i:s'
Expand Down Expand Up @@ -132,6 +133,7 @@ content:
hidden:
content_moderation_control: true
entitygroupfield: true
field_add_to_cal_description: true
field_channel: true
field_date: true
field_description: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.link
- field.field.node.event.field_add_to_cal_description
- field.field.node.event.field_channel
- field.field.node.event.field_date
- field.field.node.event.field_daterange
Expand Down Expand Up @@ -47,6 +48,7 @@ content: { }
hidden:
content_moderation_control: true
entitygroupfield: true
field_add_to_cal_description: true
field_channel: true
field_date: true
field_daterange: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.search_index
- field.field.node.event.field_add_to_cal_description
- field.field.node.event.field_channel
- field.field.node.event.field_date
- field.field.node.event.field_daterange
- field.field.node.event.field_deadline
- field.field.node.event.field_description
- field.field.node.event.field_display_arcgis_map
Expand Down Expand Up @@ -80,6 +82,7 @@ content:
hidden:
content_moderation_control: true
entitygroupfield: true
field_add_to_cal_description: true
field_channel: true
field_date: true
field_daterange: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.event.field_add_to_cal_description
- field.field.node.event.field_channel
- field.field.node.event.field_date
- field.field.node.event.field_daterange
Expand Down Expand Up @@ -66,6 +67,7 @@ content:
hidden:
content_moderation_control: true
entitygroupfield: true
field_add_to_cal_description: true
field_channel: true
field_date: true
field_deadline: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
uuid: d7b30d87-1c87-4324-b4c6-bf6c298691d3
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_add_to_cal_description
- node.type.event
module:
- custom_add_another
third_party_settings:
custom_add_another:
custom_add_another: ''
custom_remove: ''
id: node.event.field_add_to_cal_description
field_name: field_add_to_cal_description
entity_type: node
bundle: event
label: 'Add to Calendar Description'
description: 'Event description that goes with the Add to Calendar button.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string_long
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
uuid: 2958cd2c-88c9-4842-9098-22dcc36521a2
langcode: en
status: true
dependencies:
module:
- node
id: node.field_add_to_cal_description
field_name: field_add_to_cal_description
entity_type: node
type: string_long
settings:
case_sensitive: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/src/Plugin/AddToCal/Type/Generic.php b/src/Plugin/AddToCal/Type/Generic.php
index 755f412..aacd882 100644
--- a/src/Plugin/AddToCal/Type/Generic.php
+++ b/src/Plugin/AddToCal/Type/Generic.php
@@ -110,6 +110,9 @@ class Generic extends AddToCalTypeBase {
$title = Html::escape($info['title']);
$description = str_replace(PHP_EOL, '\n', $info['description']);

+ // Apple Calendar wants commas escaped in the location field.
+ $location = str_replace(',','\,',$info['location']);
+
$ics = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
@@ -121,7 +124,7 @@ DTSTART:{$info['rfc3339']['start']}
DTEND:{$info['rfc3339']['end']}
SUMMARY:{$title}
DESCRIPTION:{$description}
-LOCATION:{$info['location']}
+LOCATION:{$location}
END:VEVENT
END:VCALENDAR
ICS;
47 changes: 44 additions & 3 deletions services/drupal/web/modules/custom/epa_core/epa_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ use Drupal\node\NodeInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\search_api\Utility\Utility;
use Drupal\taxonomy\Entity\Term;
use Drupal\Component\Utility\UrlHelper;

/**
* Implements hook_theme().
Expand Down Expand Up @@ -285,8 +288,8 @@ function epa_core_token_info() {
'argument-1' => $view_argument_1,
],
'term' => [
'term-description' => $term_description
]
'term-description' => $term_description,
],
];
return $tokens;
}
Expand Down Expand Up @@ -387,13 +390,49 @@ function epa_core_tokens($type, $tokens, array $data, array $options, Bubbleable
$term_description = PlainTextOutput::renderFromHtml($token->replace($term_description, ['term' => $data['term']]));
$replacements[$original] = $term_description;
}

break;
}
}
return $replacements;
}

function epa_core_addtocal_alter(array &$overridable_items) {
$overridable_items['override_status'] = TRUE;
$add_to_cal_components = [];
$node = \Drupal::routeMatch()->getParameter('node');
if ($node->bundle() == 'event') {
$description = $node->get('field_add_to_cal_description')->value;
if (empty($description)) {
$description = $node->get('field_description')->value;
}
if ($description) {
$add_to_cal_components[] = $description;
}

$event_type = Term::load($node->get('field_event_type')->target_id)->getName();
if (!empty($event_type)) {
$add_to_cal_components[] = "Event Type: $event_type";
}
$event_host = $node->get('field_event_host')->value;
if (!empty($event_host)) {
$add_to_cal_components[] = "Event host: $event_host";
}
$links_string = '';
foreach ($node->field_links as $link) {
$url = $link->getUrl();
$url->setAbsolute();
$title = $link->title;
$links_string .= ($title ? $title .': ':''). $url->toString() ."\n";
}
if (!empty($links_string)) {
$add_to_cal_components[] = "Links:\n". $links_string;
}
}
$overridable_items['description'] = implode("\n\n", $add_to_cal_components);
}



/**
* Implements hook_entity_revision_delete().
* Invalidate cache tags for a node when its revision is deleted.
Expand Down Expand Up @@ -738,3 +777,5 @@ function epa_core_entity_field_access($operation, \Drupal\Core\Field\FieldDefini
}
return AccessResult::neutral();
}


0 comments on commit eb79951

Please sign in to comment.