| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
namespace Yoast\WP\SEO\Dashboard\Application\Taxonomies; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Dashboard\Application\Filter_Pairs\Filter_Pairs_Repository; |
| 7 |
use Yoast\WP\SEO\Dashboard\Domain\Taxonomies\Taxonomy; |
| 8 |
use Yoast\WP\SEO\Dashboard\Infrastructure\Taxonomies\Taxonomies_Collector; |
| 9 |
|
| 10 |
/** |
| 11 |
* The repository to get taxonomies. |
| 12 |
*/ |
| 13 |
class Taxonomies_Repository { |
| 14 |
|
| 15 |
/** |
| 16 |
* The taxonomies collector. |
| 17 |
* |
| 18 |
* @var Taxonomies_Collector |
| 19 |
*/ |
| 20 |
private $taxonomies_collector; |
| 21 |
|
| 22 |
/** |
| 23 |
* The filter pairs repository. |
| 24 |
* |
| 25 |
* @var Filter_Pairs_Repository |
| 26 |
*/ |
| 27 |
private $filter_pairs_repository; |
| 28 |
|
| 29 |
/** |
| 30 |
* The constructor. |
| 31 |
* |
| 32 |
* @param Taxonomies_Collector $taxonomies_collector The taxonomies collector. |
| 33 |
* @param Filter_Pairs_Repository $filter_pairs_repository The filter pairs repository. |
| 34 |
*/ |
| 35 |
public function __construct( |
| 36 |
Taxonomies_Collector $taxonomies_collector, |
| 37 |
Filter_Pairs_Repository $filter_pairs_repository |
| 38 |
) { |
| 39 |
$this->taxonomies_collector = $taxonomies_collector; |
| 40 |
$this->filter_pairs_repository = $filter_pairs_repository; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Returns the object of the filtering taxonomy of a content type. |
| 45 |
* |
| 46 |
* @param string $content_type The content type that the taxonomy filters. |
| 47 |
* |
| 48 |
* @return Taxonomy|null The filtering taxonomy of the content type. |
| 49 |
*/ |
| 50 |
public function get_content_type_taxonomy( string $content_type ) { |
| 51 |
// First we check if there's a filter that overrides the filtering taxonomy for this content type. |
| 52 |
$taxonomy = $this->taxonomies_collector->get_custom_filtering_taxonomy( $content_type ); |
| 53 |
if ( $taxonomy ) { |
| 54 |
return $taxonomy; |
| 55 |
} |
| 56 |
|
| 57 |
// Then we check if there is a filter explicitly made for this content type. |
| 58 |
$taxonomy = $this->filter_pairs_repository->get_taxonomy( $content_type ); |
| 59 |
if ( $taxonomy ) { |
| 60 |
return $taxonomy; |
| 61 |
} |
| 62 |
|
| 63 |
// If everything else returned empty, we can always try the fallback taxonomy. |
| 64 |
return $this->taxonomies_collector->get_fallback_taxonomy( $content_type ); |
| 65 |
} |
| 66 |
} |
| 67 |
|