Fix DateArgumentWrapper::getArgFormat() to access protected argFormat and provide default values

Created on 20 November 2024, about 1 month ago

Problem/Motivation

The DateArgumentWrapper::getArgFormat() method currently has two key issues:

  • It cannot access the argFormat protected member variable of the Date Argument classes until the patch from issue #2325899 is applied.
  • It does not provide a default value for some other Date Argument classes, leading to errors or unexpected behavior in cases where the argFormat is not inferred from the class name.

This results in inconsistent behavior and errors when handling date arguments in certain scenarios like using date_recur.

Steps to reproduce

  1. Without applying the patch from issue #2325899, attempt to call DateArgumentWrapper::getArgFormat() on a Date Argument instance.
  2. Observe that it cannot access the argFormat protected member variable.
  3. Apply the patch from issue #2325899 to introduce access via a getter method.
  4. Call DateArgumentWrapper::getArgFormat() on a Date Argument class that does not define an argFormat.
  5. Observe that the method fails due to the lack of a default value.

Proposed resolution

Update the DateArgumentWrapper::getArgFormat() method as follows:

  • Ensure it uses the getter method introduced by the patch in issue #2325899 to access the argFormat property.
  • Provide a reasonable default value for cases where argFormat is not defined in the Date Argument class.

Remaining tasks

  • Update the DateArgumentWrapper::getArgFormat() method to use the new getter method introduced in issue #2325899.
  • Add a default return value for undefined argFormat cases.

User interface changes

None.

API changes

The DateArgumentWrapper::getArgFormat() method will now:

  • Utilize the getter method for argFormat, as introduced in issue #2325899.
  • Return a default value when argFormat is undefined, ensuring consistent API behavior.

Data model changes

None.

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada joelpittet Vancouver

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

Comments & Activities

  • Issue created by @joelpittet
  • @joelpittet opened merge request.
  • πŸ‡¨πŸ‡¦Canada joelpittet Vancouver
    1. Accessing argFormat via a getter method:

      β€’ The code now checks if the getArgFormat() method exists using method_exists(). This ensures compatibility with the patch in issue #2325899 while maintaining backward compatibility if the patch isn’t applied.

    2. Providing default values for other date argument classes:

      β€’ The method includes specific cases for additional date classes, such as WeekDate, MonthDate, and DayDate, providing appropriate formats for these cases.

      β€’ It adds a sensible default ('Y-m-d') for any unhandled cases, ensuring that the method will always return a valid date format.

  • πŸ‡¨πŸ‡¦Canada joelpittet Vancouver

    This looks great, thanks @ramil g. I will drop Drupal 9 support because they technically need PHP 7 support and the match statement isn't available until PHP 8.0.0

  • πŸ‡¨πŸ‡¦Canada joelpittet Vancouver
    • joelpittet β†’ committed 40d51b72 on 8.x-1.x
      Issue #3488505 by joelpittet: Fix DateArgumentWrapper::getArgFormat() to...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024