diff --git a/src/classes/entities/class-tainacan-metadatum.php b/src/classes/entities/class-tainacan-metadatum.php index c28592eeb..2ee9ed470 100644 --- a/src/classes/entities/class-tainacan-metadatum.php +++ b/src/classes/entities/class-tainacan-metadatum.php @@ -258,8 +258,11 @@ class Metadatum extends Entity { * * @return string */ - function get_metadata_section_id(){ - return $this->get_mapped_property('metadata_section_id'); + function get_metadata_section_id() { + $mapped_metadata_section_id = $this->get_mapped_property('metadata_section_id'); + if($this->is_repository_level()) + return $mapped_metadata_section_id; + return is_array($mapped_metadata_section_id) ? $mapped_metadata_section_id[0] : $mapped_metadata_section_id; } /** diff --git a/tests/test-api-metadata-section.php b/tests/test-api-metadata-section.php index e5b93c499..774836a02 100644 --- a/tests/test-api-metadata-section.php +++ b/tests/test-api-metadata-section.php @@ -354,7 +354,7 @@ class TAINACAN_REST_Metadata_Sections_Controller extends TAINACAN_UnitApiTestCas $section1 = $this->tainacan_entity_factory->create_entity( 'Metadata_Section', array( - 'name' => 'Section', + 'name' => 'Section-1', 'description' => 'Section Description', 'collection' => $collection, // 'metadata_list' => [$metadatum_1->get_id(), $metadatum_2->get_id()] @@ -366,7 +366,7 @@ class TAINACAN_REST_Metadata_Sections_Controller extends TAINACAN_UnitApiTestCas $section2 = $this->tainacan_entity_factory->create_entity( 'Metadata_Section', array( - 'name' => 'Section', + 'name' => 'Section-2', 'description' => 'Section Description', 'collection' => $collection, // 'metadata_list' => [$metadatum_3->get_id(), $metadatum_4->get_id()] @@ -428,6 +428,21 @@ class TAINACAN_REST_Metadata_Sections_Controller extends TAINACAN_UnitApiTestCas true ); + $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); + $collection->set_metadata_section_order( + [ + array( 'id' => $section1->get_id(), 'enabled' => true, 'metadata_order' => [ + array( 'id' => $metadatum_1->get_id(), 'enabled' => true ), + array( 'id' => $metadatum_2->get_id(), 'enabled' => true ) + ] ), + array( 'id' => $section2->get_id(), 'enabled' => true, 'metadata_order' => [ + array( 'id' => $metadatum_3->get_id(), 'enabled' => true ), + array( 'id' => $metadatum_4->get_id(), 'enabled' => true ) + ]) + ] + ); + $Tainacan_Collections->update( $collection ); + $request = new \WP_REST_Request( 'GET', $this->namespace . '/collection/' . $collection->get_id() . '/metadata-sections'