← Back
Editing: term-seo-field-map.php
<?php // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. namespace Yoast\WP\SEO\Abilities\Infrastructure; use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Surfaces\Meta_Surface; /** * Translates between the ability input, a term indexable, and the term SEO data output. * * Terms support fewer fields than posts: there are no advanced robots flags and no * Schema.org page or article type overrides for terms. */ class Term_SEO_Field_Map extends Abstract_SEO_Field_Map { /** * Maps the string input fields to the indexable column they write to. * * @var array<string, string> */ private const STRING_FIELDS = [ 'seo_title' => 'title', 'meta_description' => 'description', 'canonical' => 'canonical', 'open_graph_title' => 'open_graph_title', 'open_graph_description' => 'open_graph_description', 'twitter_title' => 'twitter_title', 'twitter_description' => 'twitter_description', ]; /** * Maps the boolean input fields to the indexable column they write to. * * @var array<string, string> */ private const BOOLEAN_FIELDS = [ 'is_cornerstone' => 'is_cornerstone', ]; /** * The meta surface. * * @var Meta_Surface */ private $meta_surface; /** * Constructor. * * @param Meta_Surface $meta_surface The meta surface. */ public function __construct( Meta_Surface $meta_surface ) { $this->meta_surface = $meta_surface; } /** * Builds the term SEO data array from an indexable: the identity fields of the term, then the shared SEO fields. * * @param Indexable $indexable The indexable to read from. * * @return array<string, int|string|bool|null> The term SEO data, keyed by output-schema property name. */ public function to_seo_array( $indexable ): array { $meta = $this->meta_surface->for_indexable( $indexable, 'Term_Archive' ); return \array_merge( [ 'term_id' => (int) $indexable->object_id, 'term_name' => $indexable->breadcrumb_title, 'permalink' => $indexable->permalink, 'taxonomy' => $indexable->object_sub_type, ], $this->get_shared_seo_fields( $indexable, $meta ), ); } /** * Returns the string input fields mapped to the indexable column they write to. * * @return array<string, string> The string fields. */ protected function get_string_fields(): array { return self::STRING_FIELDS; } /** * Returns the boolean input fields mapped to the indexable column they write to. * * @return array<string, string> The boolean fields. */ protected function get_boolean_fields(): array { return self::BOOLEAN_FIELDS; } }
Save File
Cancel