feat: remove disabled mapper in exposers #783

This commit is contained in:
vnmedeiros 2023-09-29 00:51:00 -03:00
parent 3e4264309a
commit d9eb5a6285
2 changed files with 18 additions and 3 deletions

View File

@ -42,6 +42,13 @@ class REST_Exposers_Controller extends REST_Controller {
'permission_callback' => array($this, 'get_items_permissions_check')
)
));
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base, array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check')
)
));
}
/**
@ -53,13 +60,21 @@ class REST_Exposers_Controller extends REST_Controller {
$exposers = $this->exposers->get_exposers();
$collection_id = isset($request['collection_id']) ? $request['collection_id'] : 'default';
$collection = \Tainacan\Repositories\Collections::get_instance()->fetch($collection_id);
$disabled_mappers = isset($collection) ? $collection->get_disabled_mappers() : [];
$response = [];
foreach ($exposers as $exposer) {
if ( class_exists($exposer) ) {
$e = new $exposer();
$response[] = $e->_toArray();
$e = (new $exposer())->_toArray();
$e['mappers'] = array_filter($e['mappers'], function($n) use ($disabled_mappers) {
return !in_array($n, $disabled_mappers);
});
$response[] = $e;
}
}

View File

@ -260,7 +260,7 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
if ($disabled == true && !in_array($slug_mapper, $disabled_mappers)) {
$disabled_mappers[] = $slug_mapper;
} elseif (
($disabled == false && $key = array_search($slug_mapper, $disabled_mappers)) !== false
$disabled == false && (($key = array_search($slug_mapper, $disabled_mappers)) !== false)
) {
unset($disabled_mappers[$key]);
}