From 4d77dd6d7d57647882d40fb8fb2fe8022dbb1b54 Mon Sep 17 00:00:00 2001 From: leogermani Date: Tue, 16 Apr 2019 10:27:08 -0300 Subject: [PATCH] Replace collections in taxonomy api response (#229) --- ...ss-tainacan-rest-taxonomies-controller.php | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php index 515575848..3ce312adc 100644 --- a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php +++ b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php @@ -101,16 +101,40 @@ class REST_Taxonomies_Controller extends REST_Controller { if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); $item_arr['current_user_can_delete'] = $item->can_delete(); - $item_arr['collections'] = []; - if ( is_array($tax_collections = $item->get_collections()) ) { - foreach ($tax_collections as $tax_collection) { - if ( $tax_collection instanceof \Tainacan\Entities\Collection ) { - $item_arr['collections'][] = $tax_collection->_toArray(); - } - } - - } + // $item_arr['collections'] = []; + // if ( is_array($tax_collections = $item->get_collections()) ) { + // foreach ($tax_collections as $tax_collection) { + // if ( $tax_collection instanceof \Tainacan\Entities\Collection ) { + // $item_arr['collections'][] = $tax_collection->_toArray(); + // } + // } + // + // } } + + /** + * + * + * See issue #229 + * + */ + $item_arr['collections'] = []; + $item_arr['collections_ids'] = []; + + $taxonomy = get_taxonomy( $item->get_db_identifier() ); + foreach ($taxonomy->object_type as $slug) { + + $tax_collection = Repositories\Collections::get_instance()->fetch_by_db_identifier($slug); + if ( $tax_collection instanceof \Tainacan\Entities\Collection ) { + $item_arr['collections'][] = $tax_collection->_toArray(); + $item_arr['collections_ids'][] = $tax_collection->get_id(); + } + + } + + + + } else { $attributes_to_filter = $request['fetch_only'];