feat: remove disabled mapper in exposers #783
This commit is contained in:
parent
3e4264309a
commit
d9eb5a6285
|
@ -42,6 +42,13 @@ class REST_Exposers_Controller extends REST_Controller {
|
||||||
'permission_callback' => array($this, 'get_items_permissions_check')
|
'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();
|
$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 = [];
|
$response = [];
|
||||||
|
|
||||||
|
|
||||||
foreach ($exposers as $exposer) {
|
foreach ($exposers as $exposer) {
|
||||||
if ( class_exists($exposer) ) {
|
if ( class_exists($exposer) ) {
|
||||||
$e = new $exposer();
|
$e = (new $exposer())->_toArray();
|
||||||
$response[] = $e->_toArray();
|
$e['mappers'] = array_filter($e['mappers'], function($n) use ($disabled_mappers) {
|
||||||
|
return !in_array($n, $disabled_mappers);
|
||||||
|
});
|
||||||
|
$response[] = $e;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
||||||
if ($disabled == true && !in_array($slug_mapper, $disabled_mappers)) {
|
if ($disabled == true && !in_array($slug_mapper, $disabled_mappers)) {
|
||||||
$disabled_mappers[] = $slug_mapper;
|
$disabled_mappers[] = $slug_mapper;
|
||||||
} elseif (
|
} 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]);
|
unset($disabled_mappers[$key]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue