| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations; |
| 4 |
|
| 5 |
use WPSEO_Replace_Vars; |
| 6 |
use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer; |
| 7 |
use Yoast\WP\SEO\Presenters\Breadcrumbs_Presenter; |
| 8 |
use Yoast\WP\SEO\Surfaces\Helpers_Surface; |
| 9 |
|
| 10 |
/** |
| 11 |
* Adds customizations to the front end for breadcrumbs. |
| 12 |
*/ |
| 13 |
class Breadcrumbs_Integration implements Integration_Interface { |
| 14 |
|
| 15 |
/** |
| 16 |
* The breadcrumbs presenter. |
| 17 |
* |
| 18 |
* @var Breadcrumbs_Presenter |
| 19 |
*/ |
| 20 |
private $presenter; |
| 21 |
|
| 22 |
/** |
| 23 |
* The meta tags context memoizer. |
| 24 |
* |
| 25 |
* @var Meta_Tags_Context_Memoizer |
| 26 |
*/ |
| 27 |
private $context_memoizer; |
| 28 |
|
| 29 |
/** |
| 30 |
* Breadcrumbs integration constructor. |
| 31 |
* |
| 32 |
* @param Helpers_Surface $helpers The helpers. |
| 33 |
* @param WPSEO_Replace_Vars $replace_vars The replace vars. |
| 34 |
* @param Meta_Tags_Context_Memoizer $context_memoizer The meta tags context memoizer. |
| 35 |
*/ |
| 36 |
public function __construct( |
| 37 |
Helpers_Surface $helpers, |
| 38 |
WPSEO_Replace_Vars $replace_vars, |
| 39 |
Meta_Tags_Context_Memoizer $context_memoizer |
| 40 |
) { |
| 41 |
$this->context_memoizer = $context_memoizer; |
| 42 |
$this->presenter = new Breadcrumbs_Presenter(); |
| 43 |
$this->presenter->helpers = $helpers; |
| 44 |
$this->presenter->replace_vars = $replace_vars; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Returns the conditionals based in which this loadable should be active. |
| 49 |
* |
| 50 |
* @return array The array of conditionals. |
| 51 |
*/ |
| 52 |
public static function get_conditionals() { |
| 53 |
return []; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Registers the `wpseo_breadcrumb` shortcode. |
| 58 |
* |
| 59 |
* @codeCoverageIgnore |
| 60 |
*/ |
| 61 |
public function register_hooks() { |
| 62 |
\add_shortcode( 'wpseo_breadcrumb', [ $this, 'render' ] ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Renders the breadcrumbs. |
| 67 |
* |
| 68 |
* @return string The rendered breadcrumbs. |
| 69 |
*/ |
| 70 |
public function render() { |
| 71 |
$context = $this->context_memoizer->for_current_page(); |
| 72 |
|
| 73 |
/** This filter is documented in src/integrations/front-end-integration.php */ |
| 74 |
$presentation = \apply_filters( 'wpseo_frontend_presentation', $context->presentation, $context ); |
| 75 |
|
| 76 |
$this->presenter->presentation = $presentation; |
| 77 |
|
| 78 |
return $this->presenter->present(); |
| 79 |
} |
| 80 |
} |
| 81 |
|