context_memoizer = $context_memoizer;
$this->replace_vars = $replace_vars;
$this->helpers = $helpers;
$this->indexable_repository = $indexable_repository;
$this->base_path = \WPSEO_PATH . 'blocks/dynamic-blocks/';
}
/**
* Presents the breadcrumbs output for the current page or the available post_id.
*
* @param array $attributes The block attributes.
*
* @return string The block output.
*/
public function present( $attributes ) {
$presenter = new Breadcrumbs_Presenter();
// $this->context_memoizer->for_current_page only works on the frontend. To render the right breadcrumb in the
// editor, we need the repository.
if ( \wp_is_serving_rest_request() || \is_admin() ) {
$post_id = \get_the_ID();
if ( $post_id ) {
$indexable = $this->indexable_repository->find_by_id_and_type( $post_id, 'post' );
if ( ! $indexable ) {
$post = \get_post( $post_id );
$indexable = $this->indexable_repository->query()->create(
[
'object_id' => $post_id,
'object_type' => 'post',
'object_sub_type' => $post->post_type,
],
);
}
$context = $this->context_memoizer->get( $indexable, 'Post_Type' );
}
}
if ( ! isset( $context ) ) {
$context = $this->context_memoizer->for_current_page();
}
/** This filter is documented in src/integrations/front-end-integration.php */
$presentation = \apply_filters( 'wpseo_frontend_presentation', $context->presentation, $context );
$presenter->presentation = $presentation;
$presenter->replace_vars = $this->replace_vars;
$presenter->helpers = $this->helpers;
$class_name = 'yoast-breadcrumbs';
if ( ! empty( $attributes['className'] ) ) {
$class_name .= ' ' . \esc_attr( $attributes['className'] );
}
return '' . $presenter->present() . '
';
}
}