When using the smart date contrib module, add to calendar does not provide the correct data to the calendar. Smart date stores dates as timestamps so these need some special handling.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

selwynpolit created an issue. See original summary.

selwynpolit’s picture

Here is a quick patch in case it is helpful to folks

selwynpolit’s picture

StatusFileSize
new1.59 KB

This version of my patch will actually apply via composer. If you jam a local copy of it in a patches folder at the same level as composer.json

You will need to update your composer.json with the patch. See the example below:

    "extra": {
        "composer-exit-on-patch-failure": true,
        "patchLevel": {
            "drupal/core": "-p2"
        },
        "patches": {
            "drupal/field_tools": {
                "Clone a field to be reused in the same content type": "https://www.drupal.org/files/issues/2019-09-26/field_tools-clone_fields_same_bundle-1350808-21.patch"
            },
            "drupal/addtocalendar": {
                "Add support for smart_date fields": "./patches/add_to_calendar_smart_date_handling.patch"
            },
            "drupal/core": {
                "Drupal alter's svg fill path's with base url -> broken svg": "https://www.drupal.org/files/issues/2019-08-29/2362643-63.patch"
            }
        },
selwynpolit’s picture

Ok, here is the patch using the more appropriate naming convention so it can be applied from Drupal.org

gg24’s picture

Status: Active » Needs review
smustgrave’s picture

Patch #4 seems to work for me.

smustgrave’s picture

Rerolled the patch for 3.2

jdearie’s picture

Tested #7 with Addtocalendar 3.2 and SmartDate 3.1

1) Added new field for add to calendar
2) Added its block to events display
3) Settings for field and calendar invite settings here (made the addtocalendar checkbox on by default and required)
4) Add to calendar Button shows up, and it creates the .ics file, but the date and/or time don't match.

The ICS created and downloaded fine, but my event was 9-10 and the ICS had 1123-1223 - not even close. I thought maybe it was a
timezone issue, but that wouldn't explain the minutes.

A separate example was an all day event for March 7 - the ICS showed the date as Feb 26 and a time from 9-10.

Has anyone else had success with the patch for 3.2?

vj2150’s picture

The patch doesn't work for me. I am trying on Drupal 9.
I see the following error in the log.
Error: Call to a member function getColumns() on bool in Drupal\Core\Entity\Query\Sql\Tables->addField()

nicoschi’s picture

Patch reroll working on Drupal 9.

sharique’s picture

Status: Needs review » Reviewed & tested by the community

The patch at #10 is working, please note that it works best with [node:field_schedule:value] as token value.

gg24’s picture

Status: Reviewed & tested by the community » Needs work

@nicoschi,

I have reviewed your patch. I suggest few changes in the code.

1- Please use the ternary operator instead of if else

if (isset($options['end_date']) ) {
+            $timestamp = strip_tags($entity->{$field}->end_value);
+          }
+          else {
+            $timestamp = strip_tags($entity->{$field}->value);
+          }

can be changed to

+          $timestamp = isset($options['end_date']) ? strip_tags($entity->{$field}->end_value) : strip_tags($entity->{$field}->value);

2- Unnecessary variable

+          $tz = 'UTC';
+          $date = DrupalDateTime::createFromTimestamp($timestamp, $tz);

can be changed to as $tz is only being used at one place.

+          $date = DrupalDateTime::createFromTimestamp($timestamp, 'UTC');

caesius made their first commit to this issue’s fork.

caesius’s picture

Version: 8.x-3.1 » 8.x-3.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.21 KB

Updated to apply to latest 3.x-dev.

Status: Needs review » Needs work

caesius’s picture

Status: Needs work » Needs review

Switched to using an MR. The crucial difference from the previous patches is the use of an elseif so as not to override use_raw_value.

ckng made their first commit to this issue’s fork.

ckng’s picture

Patch in #17 not working for me.
atcDateStart and atcDateEnd are always using the `use_raw_value`. Updated patch to correct the logic checking.