fnagel / t3extblog

A record based blog extension for TYPO3 CMS. Easy to use and packed with features (incl. comments, subscriptions for comments and posts, Wordpress like subscription manager, reasonable email sending in FE and BE, GDPR ready, BE modules, Dashboard widgets, RSS, Sitemap, ...). Flexible and powerful!
http://typo3.org/extensions/repository/view/t3extblog
GNU General Public License v2.0
33 stars 19 forks source link

PostMapper resolver datePrefix does not work with textual representation of a month #243

Closed mueller-sebastian closed 3 years ago

mueller-sebastian commented 3 years ago

TYPO3: 10.4.12 t3extblog: 6.1.1

When using the following datePrefix, the PostMapper is not able to resolve the post. datePrefix: 'Y/F/'

( = 2021/January)

Problem: When calculating the length of the date part to be stripped from the url, the current date is used.

        // Remove date prefix if existing
        $date = new \DateTime();
        $value = substr($value, strlen($date->format($this->datePrefix)));

Since the string length of the current month is possible not the same as the month the post is off, the result is not correct. ( now = 2021/January, Post may use 2020/May)

Same problem should occur if month without leading 0 is used as datePrefix (not tested).

Maybe add a datePrefixRegex configuration to be used to strip the date prefix from the slug?

fnagel commented 3 years ago

Thanks for the good bug report.

You are right, it won't work with written month or even single integer month. I'm not that happy with the whole date routing implementation in general, so I'm open for any ideas how to improve this!

Can you elaborate on the datePrefixRegex configuration you have in mind? Or even provide a PR?

mueller-sebastian commented 3 years ago

pull request is created. Not sure if you will get a notice since one test seems to be on hold?!

fnagel commented 3 years ago

I've received a notification. I will take a look asap.

fnagel commented 3 years ago

Closed with merging #244 manually. Again, thanks for the contribution!

@mueller-sebastian

One thing I'm not sure about: in your example we end up with first letter uppercase month names. URLs should be lowercase IMO. Seems using https://www.php.net/manual/en/datetime.format.php does not allow to use lowercase month names. Any ideas about this? We could add a "transformToLowercase" option.

I've added an example based upon your date format, see 383db81794119d3a71d0f49431a9d07da23eb19a

mueller-sebastian commented 3 years ago

Yes, I see only the two options: always cast to lowercase (less configruation but not possible to get uppercase) or add an option. I think an option is a good way to go.

fnagel commented 3 years ago

Agree. Added in master branch :-)