Authors taxonomy with flex-object


I have a flex-object for authors on my page, so I can use it as a directory. For this I have created a custom blueprint in user/blueprints/flex-objects/authors.yaml. In this file I have defined some fields for each author, like the name, avatar image, text for bio, and some tags.

I’ve created a twig template to display the authors with the following code (I’ve omitted some of the code to keep it short):

{# Flex authors directory #}
{% set flex = grav.get('flex_objects') %}
{% set authors ='authors') %}
{% set collection = authors.getCollection() %}

{% for author in collection %}
         <div class="col-2 col-6-medium col-12-large">
             {% if author.avatar %}
             <div class="align-center">
                 {# assign the uploaded file name to a variable #}
                 {% set avatar_data = author.avatar|first %}
                 {# append the filename to the intended source url #}
                 {% set avatar_url = url(avatar_data.path) %}
                 <img class="image fit" src="{{ avatar_url }}" title="" alt="">
             {% endif %}
         <div class="col-10 col-6-medium col-12-large">
                 Name: {{ author.authorname }} <br>
                 Biography: {{ author.biography }} <br>
                 Tags: {% for tag in author.tags %} {{ tag|raw }}{% if not loop.last %}, {% endif %}{% endfor %}
         {% end for %}

Everything works correctly, and without problems (for the moment).

Now what I would like is to be able to choose an author for a page, just like when defining an author taxonomy, but with a select field that shows all the authors previously created in the flex-objects page.

How can I do it?
I have tried something like:
               label: Author
               data-options@: '\Grav\Plugin\Admin\DataOptions::options'
               data-options-default@: 'admin.flex-objects.authors'
                 required: true

but it hasn’t worked. It shows nothing.

Thank you for your help in advance.

In your form you are calling a static function options in the class Grav\Plugin\Admin\DataOptions. However as far as I can tell that class does not exist in the Admin Plugin.

You do have all authors in Twig so you could use my Form Prefiller Plugin to prefill your select field from a Twig template, see the “Prefilling a select field from a template” example.

Or you could examine the plugin code and create a small dedicated plugin with the required static function which returns the author data.

Thank you very much @bleutzinn for your reply

I’m a novice programmer and I’m still learning about PHP, Javascript, and other technologies for web programming. However, I see that you refer to Function Calls (data-*@), about which there is very little information (something very common in the advanced aspects of Grav), so sometimes I feel like I should be one of the programmers who actively contribute to the development of Grav in order to understand and implement some features.

However, I will investigate the options that you offer me and yours plugin, to see how I can achieve what I expose in this post, although I think that there must be some native Grav option to be able to use the flex-objects inside forms.