Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Pieces
Schema_Piece_Repository::get
Gets the indexables to be aggregated.
Метод класса: Schema_Piece_Repository{}
Хуков нет.
Возвращает
Schema_Piece_Collection. The aggregated schema.
Использование
$Schema_Piece_Repository = new Schema_Piece_Repository(); $Schema_Piece_Repository->get( $page, $page_size, $post_type ): Schema_Piece_Collection;
- $page(int) (обязательный)
- The page number (1-based).
- $page_size(int) (обязательный)
- The number of items per page.
- $post_type(строка) (обязательный)
- The post type to filter by.
Код Schema_Piece_Repository::get() Schema Piece Repository::get Yoast 27.7
public function get( int $page, int $page_size, string $post_type ): Schema_Piece_Collection {
$indexable_repository = $this->indexable_repository_factory->get_repository( $this->indexable_helper->should_index_indexables() );
$indexables = $indexable_repository->get( $page, $page_size, $post_type );
$schema_pieces = [];
foreach ( $indexables as $indexable ) {
if ( ! \in_array( $indexable->object_sub_type, $this->config->get_allowed_post_types(), true ) ) {
continue;
}
$page_type = $this->indexable_helper->get_page_type_for_indexable( $indexable );
$context = $this->memoizer->get( $indexable, $page_type );
$this->global_state_adapter->set_global_state( $indexable, $context );
try {
$context_array = $this->adapter->meta_tags_context_to_array( $context );
$pieces_data = $context_array['@graph'];
$pieces_data = $this->collect_external_schema( $pieces_data, $post_type, $indexable->object_id );
foreach ( $pieces_data as $piece_data ) {
$schema_piece = new Schema_Piece( $piece_data, $piece_data['@type'] );
$enhancer = $this->enhancement_factory->get_enhancer( $this->get_all_schema_types( $context_array['@graph'] ) );
if ( $enhancer !== null ) {
$schema_piece = $enhancer->enhance( $schema_piece, $indexable );
}
$schema_pieces[] = $schema_piece;
}
} catch ( Throwable $e ) {
$this->logger->warning(
'Schema aggregation failed for indexable #{indexable_id} ({object_type}/{object_sub_type}): {message}',
[
'indexable_id' => $indexable->id,
'object_type' => $indexable->object_type,
'object_sub_type' => $indexable->object_sub_type,
'message' => $e->getMessage(),
],
);
} finally {
$this->global_state_adapter->reset_global_state();
}
}
return new Schema_Piece_Collection( $schema_pieces );
}