Blueprints function call for page titles

I want to use a function call in my blueprints where I fetch the titles of all pages located in a directory, but I have no idea how to do this. The example in the tutorial fetches all paths, so I want to do something similar where I can define which directory (ie ‘/blog/’ or ‘/filters/’) as a parameter and then get a list of all children in my select input where selected it will save the title of the page to the markdown file.

I kind of solved this myself by adding below to my themename.php file.

I don’t have much experience with PHP, doing mostly front-end, but this works perfectly and on first glance doesn’t look hacky at all.

—php
use Grav\Common\Grav;

/**
* Get page titles returned.
*
* @return array
*/
public static function getPageTitle($collection_options, $path)
{

    $grav = Grav::instance();
    $page = $grav['page'];
    $collection = $page->evaluate([$collection_options => $path]);
    $titles = [];

    foreach ($collection as $item) {
        $titles[$item->title()] = $item->title();
    }

    return $titles;
}

and then adding the method to my blueprint like this:

---yaml
header.taxonomy.functionality:
   type: select
   label: Functionalities
   multiple: true
   data-options@: ['\Grav\Theme\Themename::getPageTitle', '@page.modular', '/product/functionalities']
   validate:
      type: commalist
---