I have some code in the .theme file that renders an array list. I wish to add one additional entry at the end.
I found I could do that with a quick and dirty PHP echo
statement, and it works just fine, but I would love to know the right way to do this, how to actually insert an entry at the end, one additional $row
after all the others. Here's my code so far (that works, but seems inelegant).
function csurg_barrio_preprocess_views_view_summary_unformatted(&$variables) {
$view = variables['view'];
$view_display_id = $view->getDisplay()->display['id'];
if ($view->id() === 'content_display' && $view_display_id === 'attachment_1') { // create a list of filters from a to z
$rows = $variables['rows'];
foreach ($rows as $row) {
// kint($row);
$url = $row->url;
$link = $row->link;
$wanted_url = '/conditions-and-treatments/' . $link;
if ($url !== $wanted_url) {
$row->url = $wanted_url;
}
}
// append a value to the end of the list
// $url = "/conditions-and-treatments/all";
// $link = "Full List";
// $row->url = $url;
// the below works but is not particularly elegant
echo '<span class="views-filter-all-option views-summary views-summary-unformatted"> | <a href="/conditions-and-treatments/all">Full List</a></span>';
}
}
What's a better way to achieve this?