ADA Compliance, aria-current, Accessibility, Accessbile Menu

Permalink 1 user found helpful
PHP is not my strong suit. I have this code on a view.php file within a blocks > autonav folder. I'm trying to add: aria-current="page" to the current page <li> and <a> on the main menu. I don't want "aria-current="" on the other <li> and <a> items. This is what I've come up with, but does not work:
...
foreach ($navItems as $ni) {
    $classes = array();
    $airaCurrent = array();
    if ($ni->isCurrent) {
        //class for the page currently being viewed
        $classes[] = 'drop-selected' ;
   $ariaCurrent[] = 'aria-current="page"';
    }
...
echo '<nav class="drop_down_menu" aria-labelledby="mainmenulabel"><ul>'; //opens the top-level menu
foreach ($navItems as $ni) {
    echo '<li class="' . $ni->classes . '" ' . $ni->airaCurrent . '>'; //opens a nav item
    $name = (isset($translate) && $translate == true) ? t($ni->name) : $ni->name;
    echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '" '. $ni->ariaCurrent .'>' . $name . '</a>';


Any help is appreciated.

haundavid
 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi haundavid,

You can try this:
- add an "ariaCurrentPage" property to the $ni object and set the value of the property to 'aria-current="page"'
if ($ni->isCurrent) {
    //class for the page currently being viewed
    $classes[] = 'nav-selected';
    $ni->ariaCurrentPage = 'aria-current="page"';
}

- display the "ariaCurrentPage" value
foreach ($navItems as $ni) {
    echo '<li class="' . $ni->classes . '" ' . $ni->ariaCurrentPage . '>';
    echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '" ' . $ni->ariaCurrentPage . '>' . h($ni->name) . '</a>';
haundavid replied on at Permalink Reply
haundavid
Perfect - Much appreciated! Works like a charm.