| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
namespace Yoast\WP\SEO\Llms_Txt\Infrastructure\Markdown_Services; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Helpers\Taxonomy_Helper; |
| 7 |
use Yoast\WP\SEO\Llms_Txt\Domain\Markdown\Items\Link; |
| 8 |
use Yoast\WP\SEO\Llms_Txt\Domain\Markdown\Sections\Link_List; |
| 9 |
|
| 10 |
/** |
| 11 |
* The collector of terms. |
| 12 |
*/ |
| 13 |
class Terms_Collector { |
| 14 |
|
| 15 |
/** |
| 16 |
* The taxonomy helper. |
| 17 |
* |
| 18 |
* @var Taxonomy_Helper |
| 19 |
*/ |
| 20 |
private $taxonomy_helper; |
| 21 |
|
| 22 |
/** |
| 23 |
* The constructor. |
| 24 |
* |
| 25 |
* @param Taxonomy_Helper $taxonomy_helper The taxonomy helper. |
| 26 |
*/ |
| 27 |
public function __construct( Taxonomy_Helper $taxonomy_helper ) { |
| 28 |
$this->taxonomy_helper = $taxonomy_helper; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Returns the content types in a link list. |
| 33 |
* |
| 34 |
* @return Link_List[] The content types in a link list. |
| 35 |
*/ |
| 36 |
public function get_terms_lists(): array { |
| 37 |
$taxonomies = $this->taxonomy_helper->get_indexable_taxonomy_objects(); |
| 38 |
$link_list = []; |
| 39 |
|
| 40 |
foreach ( $taxonomies as $taxonomy ) { |
| 41 |
if ( $this->taxonomy_helper->is_indexable( $taxonomy->name ) === false ) { |
| 42 |
continue; |
| 43 |
} |
| 44 |
|
| 45 |
$terms = \get_categories( |
| 46 |
[ |
| 47 |
'taxonomy' => $taxonomy->name, |
| 48 |
'number' => 5, |
| 49 |
'orderby' => 'count', |
| 50 |
'order' => 'DESC', |
| 51 |
], |
| 52 |
); |
| 53 |
|
| 54 |
$term_links = new Link_List( $taxonomy->label, [] ); |
| 55 |
foreach ( $terms as $term ) { |
| 56 |
$term_link = new Link( $term->name, \get_term_link( $term, $taxonomy->name ) ); |
| 57 |
$term_links->add_link( $term_link ); |
| 58 |
} |
| 59 |
|
| 60 |
$link_list[] = $term_links; |
| 61 |
} |
| 62 |
|
| 63 |
return $link_list; |
| 64 |
} |
| 65 |
} |
| 66 |
|