| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Builders; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 6 |
use Yoast\WP\SEO\Models\Indexable; |
| 7 |
use Yoast\WP\SEO\Values\Indexables\Indexable_Builder_Versions; |
| 8 |
|
| 9 |
/** |
| 10 |
* System page builder for the indexables. |
| 11 |
* |
| 12 |
* Formats system pages ( search and error ) meta to indexable format. |
| 13 |
*/ |
| 14 |
class Indexable_System_Page_Builder { |
| 15 |
|
| 16 |
/** |
| 17 |
* Mapping of object type to title option keys. |
| 18 |
*/ |
| 19 |
public const OPTION_MAPPING = [ |
| 20 |
'search-result' => [ |
| 21 |
'title' => 'title-search-wpseo', |
| 22 |
], |
| 23 |
'404' => [ |
| 24 |
'title' => 'title-404-wpseo', |
| 25 |
'breadcrumb_title' => 'breadcrumbs-404crumb', |
| 26 |
], |
| 27 |
]; |
| 28 |
|
| 29 |
/** |
| 30 |
* The options helper. |
| 31 |
* |
| 32 |
* @var Options_Helper |
| 33 |
*/ |
| 34 |
protected $options; |
| 35 |
|
| 36 |
/** |
| 37 |
* The latest version of the Indexable_System_Page_Builder. |
| 38 |
* |
| 39 |
* @var int |
| 40 |
*/ |
| 41 |
protected $version; |
| 42 |
|
| 43 |
/** |
| 44 |
* Indexable_System_Page_Builder constructor. |
| 45 |
* |
| 46 |
* @param Options_Helper $options The options helper. |
| 47 |
* @param Indexable_Builder_Versions $versions The latest version of each Indexable Builder. |
| 48 |
*/ |
| 49 |
public function __construct( Options_Helper $options, Indexable_Builder_Versions $versions ) { |
| 50 |
$this->options = $options; |
| 51 |
$this->version = $versions->get_latest_version_for_type( 'system-page' ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Formats the data. |
| 56 |
* |
| 57 |
* @param string $object_sub_type The object sub type of the system page. |
| 58 |
* @param Indexable $indexable The indexable to format. |
| 59 |
* |
| 60 |
* @return Indexable The extended indexable. |
| 61 |
*/ |
| 62 |
public function build( $object_sub_type, Indexable $indexable ) { |
| 63 |
$indexable->object_type = 'system-page'; |
| 64 |
$indexable->object_sub_type = $object_sub_type; |
| 65 |
$indexable->title = $this->options->get( static::OPTION_MAPPING[ $object_sub_type ]['title'] ); |
| 66 |
$indexable->is_robots_noindex = true; |
| 67 |
$indexable->blog_id = \get_current_blog_id(); |
| 68 |
|
| 69 |
if ( \array_key_exists( 'breadcrumb_title', static::OPTION_MAPPING[ $object_sub_type ] ) ) { |
| 70 |
$indexable->breadcrumb_title = $this->options->get( static::OPTION_MAPPING[ $object_sub_type ]['breadcrumb_title'] ); |
| 71 |
} |
| 72 |
|
| 73 |
$indexable->version = $this->version; |
| 74 |
|
| 75 |
return $indexable; |
| 76 |
} |
| 77 |
} |
| 78 |
|