Panel setup for year ranges

I’m currently working on the blueprint for project pages and I stumbled upon a question I don’t know how to answer: how should I set up year ranges in the panel.

What’s a year range in this case? It’s a list of single years or year ranges a project was active in, like 2002, 2005 or 2013-2017 or 2010, 2015-2018.

My ideas:

  • First, I can think of using a select field that let’s me select all year from a start date until today. But this would have to be updated manually every year.

  • Second, it would be possible to use a tag field that lets me enter years or year ranges. But when having a range 2015-2018, it wouldn’t be possible to find that entry with the given years 2016 or 2017 because they are not directly mentioned in the field value.

  • Third, I could add a structure field with a start and end date field. But this make content editing tedious.

Is there anyone around who has tackled a similar use case and found a good solution how set this up?

Why not two date fields with start date and end date instead of a structure field? If same year, you could also leave the end date empty, if you are just interested in the years.

Or use a select field with years instead of the date fields, generating the relevant years as options dynamically.

With your second option, you could still calculate a year range from the string, if you prefer that option.

We are in need of multiple ranges.

Oh, alright. No matter how you do it, you’d still have to do calculations anyway if you want to find a given project by year–with the exception of the select field, where the user ticks all years (but then you have to do your calculations if you want to output consecutive years as ranges).

I’d use the one your users can handle best, because all options will work.

Thanks for your input – that helps a lot.
Maybe this “just” requires a custom UI to work better in the panel …

For now, I’ve settled with a multiselect field that’s fetching years from a custom route in the config:

    'routes' => [
        [
            'pattern' => 'hananils/years',
            'method' => 'GET',
            'action' => function () {
                $years = [];
                $year = date('Y');
                $start = 2009;

                while ($year >= $start) {
                    $years[$year] = (string) $year;
                    $year--;
                };

                return \Kirby\Http\Response::json(['years' => $years]);
            }
        ]
    ]

Thanks again for your input, @texnixe :slight_smile: