feat: change mappers API
This commit is contained in:
parent
7caa526e47
commit
4959a7dd7b
|
@ -14,7 +14,7 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
* REST_Metadatum_Mappers_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->rest_base = 'metadatum-mappers';
|
||||
$this->rest_base = 'mappers';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,38 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
),
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<slug>[a-z0-9-_]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
),
|
||||
array(
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_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'),
|
||||
),
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<slug>[a-z0-9-_]+)' ,
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
),
|
||||
array(
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
|
@ -68,6 +100,29 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$collection_id = isset($request['collection_id']) ? $request['collection_id'] : '';
|
||||
$disabled_mappers = get_post_meta($collection_id, 'disabled_mappers');
|
||||
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
||||
|
||||
$metadatum_mappers = $Tainacan_Mappers->get_mappers( 'OBJECT' );
|
||||
|
||||
$prepared = [];
|
||||
foreach ($metadatum_mappers as $metadatum_mapper){
|
||||
if($metadatum_mapper->show_ui) {
|
||||
$mapper = $this->prepare_item_for_response($metadatum_mapper, $request);
|
||||
$mapper['disabled'] = in_array($metadatum_mapper->slug, $disabled_mappers) ? true : false;
|
||||
array_push($prepared, $mapper);
|
||||
}
|
||||
}
|
||||
return new \WP_REST_Response($prepared, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
||||
|
||||
$metadatum_mappers = $Tainacan_Mappers->get_mappers( 'OBJECT' );
|
||||
|
|
|
@ -44,7 +44,8 @@ abstract class Mapper {
|
|||
'metadata' => $this->metadata,
|
||||
'prefix' => $this->prefix,
|
||||
'sufix' => $this->sufix,
|
||||
'header' => $this->header
|
||||
'header' => $this->header,
|
||||
'add_meta_form' => ''
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ class Mappers_Handler {
|
|||
|
||||
function init() {
|
||||
$this->register_mapper('Tainacan\Mappers\Dublin_Core');
|
||||
$this->register_mapper('Tainacan\Mappers\Wiki_Data');
|
||||
|
||||
do_action('tainacan-register-mappers', $this);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Mappers;
|
||||
|
||||
/**
|
||||
* Support Dublin Core Mapping
|
||||
* http://purl.org/dc/elements/1.1/
|
||||
*
|
||||
*/
|
||||
class Wiki_Data extends Mapper {
|
||||
public $slug = 'wiki-data';
|
||||
public $name = 'WikiData';
|
||||
public $allow_extra_metadata = true;
|
||||
public $context_url = 'http://??????';
|
||||
public $header = '??????';
|
||||
public $prefixes = [
|
||||
'dc' => 'http://purl.org/dc/elements/1.1/'
|
||||
];
|
||||
public $metadata = [
|
||||
|
||||
];
|
||||
}
|
|
@ -261,7 +261,7 @@ export const updateMetadatumTypes = ({commit}, metadatumTypes) => {
|
|||
// METADATA MAPPERS
|
||||
export const fetchMappers = ({commit}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.get('/metadatum-mappers')
|
||||
axios.tainacan.get('/mappers')
|
||||
.then((res) => {
|
||||
let mappers = res.data;
|
||||
commit('setMappers', mappers);
|
||||
|
@ -280,7 +280,7 @@ export const updateMapper = ({ dispatch }, {metadataMapperMetadata, mapper}) =>
|
|||
metadata_mappers: metadataMapperMetadata,
|
||||
};
|
||||
param[tainacan_plugin.exposer_mapper_param] = mapper;
|
||||
axios.tainacan.post('/metadatum-mappers', param).then((res) => {
|
||||
axios.tainacan.post('/mappers', param).then((res) => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
Loading…
Reference in New Issue