statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Year - name conflict - when using "year" as name for a date fieldset. #2496

Open MichaelBrauner opened 4 years ago

MichaelBrauner commented 4 years ago

Describe the bug When u give a date-field the field variable of "year" and u set Extras/Date Format to "Y" and Input Format to "YYYY" u are not able anymore to map the route with a wildcard anymore. This issue (I am sure) does even occour when u want to let the users set the "year" with an integer. The format of the field in this case does't matter - the NAME is the crucial thing.

To Reproduce Reproduce it - like I said. But there is no need to.

Expected behavior Statamic should realize - that in this case there is no DATE field - and year is just a field.

SOLUTION

Change in Data/Content/UrlBuilder.php on Line 108 - 125:

 private function getSpecialValue($variable)
     {
         switch ($variable) {
             case 'year':
                 $value = $this->content->date()->format('Y');
                 break;
             case 'month':
                 $value = $this->content->date()->format('m');
                 break;
             case 'day':
                 $value = $this->content->date()->format('d');
                 break;
             default:
                 $value = null;
         }

         return $value;
     }

To

 private function getSpecialValue($variable)
     {
         switch ($variable) {
             case 'year':
                 $value = $this->content->date() ? $this->content->date()->format('Y') : null;
                 break;
             case 'month':
                 $value = $this->content->date() ? $this->content->date()->format('m') : null;
                 break;
             case 'day':
                 $value = $this->content->date() ? $this->content->date()->format('d') : null;
                 break;
             default:
                 $value = null;
         }

         return $value;
     }

Also I found out - that this causes problems in the vue - control panel. When I want to order my collection according to "year" now - I does not work. No error message. But just did not do it.