Deprecated function errors with PHP 8.1

Created on 24 April 2023, over 1 year ago
Updated 13 December 2023, about 1 year ago

After upgrading to PHP 8.1, we see deprecated function errors on our iCal feeds. Based on the error message I believe it traces back to views_ical.

Deprecated function: Calling static trait method Drupal\smart_date\SmartDateTrait::isAllDay is deprecated, it should only be called on a class using the trait in Drupal\views_ical\Plugin\views\row\IcalFieldsWizard->addSmartDateEvent() (line 511 of /path/to/web/modules/contrib/views_ical/src/Plugin/views/row/IcalFieldsWizard.php) 

I don't know how to create a patch for this, but I'm willing to test if someone else can provide the patch.

🐛 Bug report
Status

Needs work

Component

Code

Created by

🇺🇸United States sclsweb

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

Merge Requests

Comments & Activities

  • Issue created by @sclsweb
  • First commit to issue fork.
  • Assigned to akshaydalvi212
  • 🇮🇳India akshaydalvi212

    I will resolve the deprecated function error.

  • @akshaydalvi212 opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India akshaydalvi212

    resolved the error and raised the MR.
    kindly review.

  • 🇧🇷Brazil elber Brazil

    I will review it.

  • Assigned to elber
  • Issue was unassigned.
  • Status changed to RTBC over 1 year ago
  • 🇧🇷Brazil elber Brazil

    Hi congratulations it is sounds good to me. Moving to RTBC.

  • 🇺🇸United States ccjjmartin Austin, TX
  • First commit to issue fork.
  • 🇺🇸United States bburg Washington D.C.

    Apologies, some other recent changes are conflicting with these updates.

  • 🇺🇸United States bburg Washington D.C.

    Does this actually work? I see the change:

    -      if (SmartDateTrait::isAllDay($startDatetime->getTimestamp(), $endDatetime->getTimestamp(), $dateTZ)) {
    +      if ($this->isAllDay($startDatetime->getTimestamp(), $endDatetime->getTimestamp(), $dateTZ)) {\
    

    We don't add the SmartDateTrait to the class, so I don't see how the method could work here. I admit, I haven't checked out the code and tested personally yet. I have some catching up to do on this module, which I am to do today.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States bburg Washington D.C.

    Yes, just tested, and I get the below error. So this needs some work.

    The website encountered an unexpected error. Please try again later.<br /><em class="placeholder">Error</em>: Call to undefined method Drupal\views_ical\Plugin\views\row\IcalFieldsWizard::isAllDay() in <em class="placeholder">Drupal\views_ical\Plugin\views\row\IcalFieldsWizard-&gt;addSmartDateEvent()</em> (line <em class="placeholder">506</em> of <em class="placeholder">modules/contrib/views_ical/src/Plugin/views/row/IcalFieldsWizard.php</em>). <pre class="backtrace">Drupal\views_ical\Plugin\views\row\IcalFieldsWizard-&gt;addSmartDateEvent(Array, Object, Object, Array) (Line: 117)
    Drupal\views_ical\Plugin\views\row\IcalFieldsWizard-&gt;render(Object) (Line: 516)
    Drupal\views\Plugin\views\style\StylePluginBase-&gt;renderGroupingSets(Array) (Line: 476)
    Drupal\views\Plugin\views\style\StylePluginBase-&gt;render() (Line: 250)
    Drupal\views_ical\Plugin\views\style\IcalWizard-&gt;render(Array) (Line: 152)
    Drupal\views\Plugin\views\display\Feed-&gt;render() (Line: 77)
    Drupal\views_ical\Plugin\views\display\IcalDisplay-&gt;render() (Line: 1538)
    Drupal\views\ViewExecutable-&gt;render() (Line: 128)
    Drupal\views\Plugin\views\display\Feed-&gt;execute() (Line: 1635)
    Drupal\views\ViewExecutable-&gt;executeDisplay(&#039;ical_1&#039;, Array) (Line: 81)
    Drupal\views\Element\View::preRenderViewElement(Array)
    call_user_func_array(Array, Array) (Line: 101)
    Drupal\Core\Render\Renderer-&gt;doTrustedCallback(Array, Array, &#039;Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725&#039;, &#039;exception&#039;, &#039;Drupal\Core\Render\Element\RenderCallbackInterface&#039;) (Line: 788)
    Drupal\Core\Render\Renderer-&gt;doCallback(&#039;#pre_render&#039;, Array, Array) (Line: 374)
    Drupal\Core\Render\Renderer-&gt;doRender(Array, 1) (Line: 204)
    Drupal\Core\Render\Renderer-&gt;render(Array, 1) (Line: 148)
    Drupal\Core\Render\Renderer-&gt;Drupal\Core\Render\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 149)
    Drupal\Core\Render\Renderer-&gt;renderRoot(Array) (Line: 109)
    Drupal\views\Plugin\views\display\Feed::buildResponse(&#039;ical_test&#039;, &#039;ical_1&#039;, Array) (Line: 126)
    Drupal\views_ical\Plugin\views\display\IcalDisplay::buildResponse(&#039;ical_test&#039;, &#039;ical_1&#039;, Array) (Line: 56)
    Drupal\views\Routing\ViewPageController-&gt;handle(&#039;ical_test&#039;, &#039;ical_1&#039;, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 191)
    Drupal\page_cache\StackMiddleware\PageCache-&gt;fetch(Object, 1, 1) (Line: 128)
    Drupal\page_cache\StackMiddleware\PageCache-&gt;lookup(Object, 1, 1) (Line: 82)
    Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
    
    
  • Merge request !17Update IcalFieldsWizard.php to prevent WSOD → (Merged) created by sclsweb
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States sclsweb

    This issue was causing WSOD errors and filling up my site logs, so I attempted... something, based on following examples from other modules. I'm not sure it is proper code or if it actually fixes the issue, unfortunately -- I'm using SmartDate with recurring rules, and either something is broken (but silently, with the patch) or my feed is set up wrong, not sure which (I download the .ics feed, it has items in it; I subscribe with Google Calendar, nothing there)

    Could someone else test?

  • 🇺🇸United States j_s

    MR!17 from #14 fixes the deprecated error message for me.

    I'm able to add the calendar feed to my Outlook and Google Calendar using alpha12.

    I'm not sure if this is a good place to put it, but I also see other warnings in logs:

    Warning: Trying to access array offset on value of type null in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 435 of /drupal/web/modules/contrib/views_ical/src/ViewsIcalHelper.php)

    Warning: Undefined array key -1 in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 434 of /drupal/web/modules/contrib/views_ical/src/ViewsIcalHelper.php)

  • 🇺🇸United States bburg Washington D.C.

    I'm not seeing the warnings myself, even with error reporting turned the way up, but that may just be the configuration in the ddev environment I am using.

    Patch doesn't seem to cause issues. so going ahead and merging it. We can keep the issue open to look at the errors joshuasosa highlights.

    I assume the error is being generated from this line:

        $transitionPrev = $transitions[$transition['index'] - 1];
    

    Where we are attempting to handle timezones for potential daylight savings. Based on the error, it sounds like the $transitions variable is null. I assume this is for a timezone that doesn't utilize daylight savings? We can do add some type checking here and just return.

  • Status changed to Fixed about 1 year ago
  • 🇺🇸United States bburg Washington D.C.
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States bburg Washington D.C.

    Reopening to address those warnings.

  • 🇺🇸United States bburg Washington D.C.

    With an update like this:

        if ($transitionPrev !== null) {
    

    around that block in ViewsIcalHelper, I get this sample output:

    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//Drupal iCal API//EN
    X-WR-TIMEZONE:UTC
    BEGIN:VTIMEZONE
    TZID:UTC
    X-LIC-LOCATION:UTC
    BEGIN:STANDARD
    TZNAME:UTC
    TZOFFSETFROM:+0000
    TZOFFSETTO:+0000
    DTSTART:20221024T201320
    END:STANDARD
    BEGIN:STANDARD
    TZNAME:UTC
    TZOFFSETFROM:+0000
    TZOFFSETTO:+0000
    DTSTART:20221026T081319
    END:STANDARD
    END:VTIMEZONE
    BEGIN:VEVENT
    UID:Christmas
    DTSTART;TZID=UTC:20231225T000000
    SEQUENCE:0
    TRANSP:TRANSPARENT
    DTEND;TZID=UTC:20231226T115959
    SUMMARY: Christmas 
    CLASS:PUBLIC
    DESCRIPTION: Christmas 
    DTSTAMP:20231213T172851Z
    END:VEVENT
    END:VCALENDAR
    

    For good measure, I set the site default timezone and my user's timezone preference to UTC. Does that seem like a valid output to you?

  • 🇺🇸United States j_s

    Yes! It's for AZ time which uses MST without any daylight savings change. Putting in the suggested null check on $transitionPrev seems to clear up those warnings for me. Thanks!

  • 🇺🇸United States j_s

    It looks like adding

    if ($transition['index'] > 0) {
    

    before $transitionPrev on 434 and closing after the !in_array if-block clears up these warnings for me.

Production build 0.71.5 2024