Field formatter is incompatible with smart dates provided by smart date module

Created on 23 August 2024, 4 months ago
Updated 20 September 2024, 3 months ago

Problem/Motivation

I have a site where I use smart dates to provide date functionality for events. I had a request for ical links to be added to these events. I realised that the date ical module was not compatible with the smart date fields even though it seemed to be on the display mode. After looking at the viewElements method in the field formatter, I noticed that there was no logic to handle smart dates.

Proposed resolution

Add logic to determine method used to create array of elements depending on whether it is a smart date, date range or date. Add additional method to handle creation of array elements for smart dates.

I've written a small patch to handle this, I haven't tested this on a variety of use cases but it covers mine and could be used for a more comprehensive solution.

✨ Feature request
Status

Fixed

Version

4.0

Component

Other

Created by

πŸ‡¬πŸ‡§United Kingdom kristiantosney

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kristiantosney
  • Status changed to Needs review 4 months ago
  • πŸ‡¬πŸ‡§United Kingdom kristiantosney
  • πŸ‡«πŸ‡·France lazzyvn paris

    This patch needs a lot of work
    $this->smartDateElements($items, $langcode);
    but methode smartDateElements has only $items without $langcode;
    and errors with phpcs
    395 | ERROR | [ ] Missing parameter comment
    395 | ERROR | [x] Data types in @param tags need to be fully namespaced
    397 | ERROR | [ ] Description for the @return value is missing
    I think smartDate must have a service to get the date and end date, it must use the service if it exists

    • lazzyvn β†’ committed 965224e6 on 4.x
      Issue #3469868: Field formatter is incompatible with smart dates...
  • Status changed to Fixed 3 months ago
  • πŸ‡«πŸ‡·France lazzyvn paris
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡¬πŸ‡§United Kingdom kristiantosney

    It doesn't work to just have smart dates using the existing date range method as the way days are stored is different so I'd advise either using what I've added in the patch or adding something of your own rather than just trying to use the existing date range method. I've added an updated patch to work with the change you made.

  • πŸ‡«πŸ‡·France lazzyvn paris

    why in your patch don't you check if value and end_date are not null?
    i think it's better if you can apply the patch by checking $item->get('value') and $item->get('start_date')
    something like this

    {
          /** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
          $start_date = $item->start_date ?? $item->value;
          /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */
          $end_date = $item->end_date;
    
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    I'm also interested in providing support for smart_date type fields through this module, and am happy to test this. However, based on my review of the code and functional testing of the above patch, it appears that the scope of this issue is to handle date spans in smart_date fields only. As far as I can tell, there is still the more fundamental issue of supporting repeating/recurring date instances. It seems that the maintainer has suggested this is not supportable per ✨ Smart Date Support? Closed: won't fix .

    Can @lazzyvn confirm whether there is openness to supporting recurring smart_date fields?

    Can the @kristiantosney revise the issue description and title to better define the scope of the intended change here?

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    *If* there was interest in supporting smart date recurring dates, this is a proof of concept for how the correct delta values could be retrieved. It would simply require the View to be configured to include a "delta" field from the smartdate field, and the code here would use that from the row output to find the correct delta.

    Not expecting this to be incorporated as-is, of course. Just sharing to provoke ideas & consideration.

  • πŸ‡«πŸ‡·France lazzyvn paris

    smartdate works with ical date in base case (start/end date) another feature, i think smartDate has a service or method to get the correct date. I add code to development but I think there are other correct ways to get value.

Production build 0.71.5 2024