| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace WP_Syntex\Polylang\Switcher\Layout; |
| 7 |
|
| 8 |
use PLL_Language; |
| 9 |
use WP_Syntex\Polylang\Switcher\Element\Nav as Element; |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class that displays a language switcher as a list. |
| 15 |
* |
| 16 |
* @since 3.9 |
| 17 |
*/ |
| 18 |
class Nav extends Abstract_Layout { |
| 19 |
/** |
| 20 |
* Returns the markup of the switcher. |
| 21 |
* |
| 22 |
* @since 3.9 |
| 23 |
* |
| 24 |
* @return string |
| 25 |
*/ |
| 26 |
public function get(): string { |
| 27 |
$out = ''; |
| 28 |
|
| 29 |
foreach ( $this->get_elements() as $element ) { |
| 30 |
$out .= $element->get(); |
| 31 |
} |
| 32 |
|
| 33 |
if ( empty( $out ) || ! $this->settings->show_wrapper ) { |
| 34 |
return $out; |
| 35 |
} |
| 36 |
|
| 37 |
$cr = $this->settings->preserve_spacing ? "\n" : ''; |
| 38 |
$out = sprintf( |
| 39 |
'<%1$s id="%2$s" class="%3$s" aria-label="%4$s">%5$s</%1$s>', |
| 40 |
$this->get_nav_tag(), |
| 41 |
esc_attr( $this->settings->unique_id ), |
| 42 |
esc_attr( implode( ' ', $this->get_wrapper_classes() ) ), |
| 43 |
esc_attr( __( 'Choose a language', 'polylang' ) ), |
| 44 |
"{$cr}<ul>{$cr}{$out}</ul>" |
| 45 |
); |
| 46 |
|
| 47 |
return "{$cr}{$out}{$cr}"; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Returns an instance of `Element\Nav`. |
| 52 |
* |
| 53 |
* @since 3.9 |
| 54 |
* |
| 55 |
* @param PLL_Language $language Instance of `PLL_Language`. |
| 56 |
* @return Element |
| 57 |
*/ |
| 58 |
protected function get_element( PLL_Language $language ): Element { |
| 59 |
return new Element( $language, $this->settings, $this->links ); |
| 60 |
} |
| 61 |
} |
| 62 |
|