That’s not difficult, $tag->attr() gives you an array of all attributes:
page::$methods['getTaggedLinklist'] = function($page, $field = null) {
if(!is_null($field) && in_array($field, $page->content()->fields())) {
$raw = $page->{$field}();
} else {
$raw = $page->content()->raw();
}
// find all tags
preg_match_all('!(?=[^\]])\([a-z0-9_-]+:.*?\)!', $raw, $matches);
$list = [];
if(count($matches[0]) > 0) {
// loop through the matches
foreach($matches[0] as $match) {
// remove the brackets
$tag = trim(rtrim(ltrim($match, '('), ')'));
// get the name of the tag
$name = trim(substr($tag, 0, strpos($tag, ':')));
// check if it is a link tag
if($name == 'link') {
// create a new Kirbytag instance
$tag = new Kirbytag(null, $name, $tag);
// get all the attributes and add them to our list
$attributes = $tag->attr();
$list[] = $attributess;
}
}
}
return $list;
};
dump($page->getTaggedLinklist());
We could, of course, make this more versatile by passing the tags we want to catch as a parameter array instead of hard-coding the link tag… but this is just an example.