• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / bce64cd247c6a27acec1d76069b69b2f7d7be199

13 May 2024 11:43AM UTC coverage: 52.638% (-0.02%) from 52.654%
bce64cd247c6a27acec1d76069b69b2f7d7be199

push

github

web-flow
Merge pull request #21359 from Yoast/feature/v3-api-breadcrumbs

Convert the Breadcrumbs block to the Blocks V3 API

7403 of 13443 branches covered (55.07%)

Branch coverage included in aggregate %.

0 of 12 new or added lines in 3 files covered. (0.0%)

10 existing lines in 2 files now uncovered.

28308 of 54399 relevant lines covered (52.04%)

41291.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/integrations/blocks/breadcrumbs-block.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Blocks;
4

5
use WPSEO_Replace_Vars;
6
use Yoast\WP\SEO\Helpers\Request_Helper;
7
use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
8
use Yoast\WP\SEO\Presenters\Breadcrumbs_Presenter;
9
use Yoast\WP\SEO\Repositories\Indexable_Repository;
10
use Yoast\WP\SEO\Surfaces\Helpers_Surface;
11

12
/**
13
 * Siblings block class
14
 */
15
class Breadcrumbs_Block extends Dynamic_Block_V3 {
16

17
        /**
18
         * The name of the block.
19
         *
20
         * @var string
21
         */
22
        protected $block_name = 'breadcrumbs';
23

24
        /**
25
         * The editor script for the block.
26
         *
27
         * @var string
28
         */
29
        protected $script = 'yoast-seo-dynamic-blocks';
30

31
        /**
32
         * The Meta_Tags_Context_Memoizer.
33
         *
34
         * @var Meta_Tags_Context_Memoizer
35
         */
36
        private $context_memoizer;
37

38
        /**
39
         * The Replace vars helper.
40
         *
41
         * @var WPSEO_Replace_Vars
42
         */
43
        private $replace_vars;
44

45
        /**
46
         * The helpers surface.
47
         *
48
         * @var Helpers_Surface
49
         */
50
        private $helpers;
51

52
        /**
53
         * The indexable repository.
54
         *
55
         * @var Indexable_Repository
56
         */
57
        private $indexable_repository;
58

59
        /**
60
         * The request helper.
61
         *
62
         * @var Request_Helper
63
         */
64
        private $request_helper;
65

66
        /**
67
         * Siblings_Block constructor.
68
         *
69
         * @param Meta_Tags_Context_Memoizer $context_memoizer     The context.
70
         * @param WPSEO_Replace_Vars         $replace_vars         The replace variable helper.
71
         * @param Helpers_Surface            $helpers              The Helpers surface.
72
         * @param Indexable_Repository       $indexable_repository The indexable repository.
73
         * @param Request_Helper             $request_helper       The request helper.
74
         */
75
        public function __construct(
×
76
                Meta_Tags_Context_Memoizer $context_memoizer,
77
                WPSEO_Replace_Vars $replace_vars,
78
                Helpers_Surface $helpers,
79
                Indexable_Repository $indexable_repository,
80
                Request_Helper $request_helper
81
        ) {
82
                $this->context_memoizer     = $context_memoizer;
×
83
                $this->replace_vars         = $replace_vars;
×
84
                $this->helpers              = $helpers;
×
85
                $this->indexable_repository = $indexable_repository;
×
86
                $this->request_helper       = $request_helper;
×
87

NEW
88
                $this->base_path = \WPSEO_PATH . 'blocks/dynamic-blocks/';
×
89
        }
90

91
        /**
92
         * Presents the breadcrumbs output for the current page or the available post_id.
93
         *
94
         * @param array<string, bool|string|int|array> $attributes The block attributes.
95
         *
96
         * @return string The block output.
97
         */
98
        public function present( $attributes ) {
×
99
                $presenter = new Breadcrumbs_Presenter();
×
100
                // $this->context_memoizer->for_current_page only works on the frontend. To render the right breadcrumb in the
101
                // editor, we need the repository.
102
                if ( $this->request_helper->is_rest_request() || \is_admin() ) {
×
103
                        $post_id = \get_the_ID();
×
104
                        if ( $post_id ) {
×
105
                                $indexable = $this->indexable_repository->find_by_id_and_type( $post_id, 'post' );
×
106

107
                                if ( ! $indexable ) {
×
108
                                        $post      = \get_post( $post_id );
×
109
                                        $indexable = $this->indexable_repository->query()->create(
×
110
                                                [
111
                                                        'object_id'        => $post_id,
×
112
                                                        'object_type'      => 'post',
×
113
                                                        'object_sub_type'  => $post->post_type,
×
114
                                                ]
115
                                        );
116
                                }
117

118
                                $context = $this->context_memoizer->get( $indexable, 'Post_Type' );
×
119
                        }
120
                }
121
                if ( ! isset( $context ) ) {
×
122
                        $context = $this->context_memoizer->for_current_page();
×
123
                }
124

125
                /** This filter is documented in src/integrations/front-end-integration.php */
126
                $presentation            = \apply_filters( 'wpseo_frontend_presentation', $context->presentation, $context );
×
127
                $presenter->presentation = $presentation;
×
128
                $presenter->replace_vars = $this->replace_vars;
×
129
                $presenter->helpers      = $this->helpers;
×
130
                $class_name              = 'yoast-breadcrumbs';
×
131

132
                if ( ! empty( $attributes['className'] ) ) {
×
133
                        $class_name .= ' ' . \esc_attr( $attributes['className'] );
×
134
                }
135

136
                return '<div class="' . $class_name . '">' . $presenter->present() . '</div>';
×
137
        }
138
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc