Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How can one modify the value of an ical field (in my case the Location field) before importing it?
I want to do this because the ical field is mapped to a taxonomy field in Drupal. The ics file is the following
BEGIN:VCALENDAR
VERSION:2.0
PRODID:shapes
BEGIN:VTIMEZONE
TZID:GTB Standard Time
BEGIN:STANDARD
DTSTART:20161002T040000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYHOUR=4;BYMINUTE=0;BYMONTH=10
TZNAME:GTB Standard Time
TZOFFSETFROM:+0300
TZOFFSETTO:+0200
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20160301T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYHOUR=3;BYMINUTE=0;BYMONTH=3
TZNAME:GTB Daylight Time
TZOFFSETFROM:+0200
TZOFFSETTO:+0300
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
DESCRIPTION:
DTEND;VALUE=DATE:20170811
DTSTAMP:20170809T125455Z
DTSTART;VALUE=DATE:20170809
LOCATION:Building 11
SEQUENCE:0
SUMMARY:Morning
UID:96b6fe5b-4092-40f8-9ed3-76909bd2d778
END:VEVENT
END:VCALENDAR
What I want is, instead of LOCATION:Building 11
, to have LOCATION:Room #11
, because the terms on my taxonomy are of the form "Room #number".
I don't know if I'm thinking correctly about it but I should modify this part of date_ical.api.php
? What would I have to add there?
/**
* Alter the parsed data for an event imported from an iCal feed.
*
* @param array $data
* An associative array of field data that represents an imported event.
* @param array $context
* An associative array of context, with the following keys and values:
* - 'calendar': The iCalcreator vcalendar parent object of this component.
* - 'source': FeedsSource object for this Feed.
* - 'fetcher_result': The FeedsFetcherResult object for this Feed.
*/
function hook_date_ical_import_post_parse_alter(&$data, $context) {
// Example of what might be done with this alter hook.
if (!empty($context['calendar']->xprop['X-WR-CALNAME']['value'])) {
// Do something with the calendar name....
}
}
I'd appreciate any help, thanks!
Comments
Comment #2
coredumperror CreditAttribution: coredumperror commentedIf you want to take advantage of the
hook_date_ical_import_post_parse_alter
hook, you need to implement the hook in your own module. Check out < ahref="https://www.drupal.org/docs/7/creating-custom-modules/writing-comments-and-implementing-your-first-hook">this part of the Creating Custom Modules guide for instructions on how to do that.