public function add_submenu_toggle_attributes( $attributes, $context, $args ) { $state_id = esc_attr( $args['state_id'] ); $submenu_index = esc_attr( $args['submenu_index'] ); $classes = isset( $attributes['class'] ) ? $attributes['class'] : $context; $classes = esc_attr( "{$classes} {$this->script_config['subMenuIconClass']}" ); $attributes['class'] = $classes; $attributes['aria-expanded'] = 'false'; $attributes['aria-pressed'] = 'false'; /* * Add the AMP event bindings. * In the 'on' attribute, toggle between the $submenu_index and 0 (not expanded). * There can only be one menu item in each menu depth expanded at a time. * For example, if there are 4 primary menu items, only one of them can have its submenu expanded. */ $attributes['on'] = "tap:AMP.setState( { {$state_id}: {$state_id} == {$submenu_index} ? {$this->submenu_not_expanded} : {$submenu_index} } )"; $attributes['[class]'] = "{$state_id} == {$submenu_index} ? '{$classes} activated toggled-on' : '{$classes}'"; $attributes['[aria-expanded]'] = "{$state_id} == {$submenu_index} ? 'true' : 'false'"; $attributes['[aria-pressed]'] = $attributes['[aria-expanded]']; return $attributes; }