fix: get disabled mappers in collections #783
This commit is contained in:
parent
4959a7dd7b
commit
d3efbdaf93
|
@ -100,8 +100,8 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
||||||
* @return \WP_Error|\WP_REST_Response
|
* @return \WP_Error|\WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public function get_items( $request ) {
|
public function get_items( $request ) {
|
||||||
$collection_id = isset($request['collection_id']) ? $request['collection_id'] : '';
|
$collection_id = isset($request['collection_id']) ? $request['collection_id'] : 'default';
|
||||||
$disabled_mappers = get_post_meta($collection_id, 'disabled_mappers');
|
$disabled_mappers = get_post_meta($collection_id, 'disabled_mappers', false);
|
||||||
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
||||||
|
|
||||||
$metadatum_mappers = $Tainacan_Mappers->get_mappers( 'OBJECT' );
|
$metadatum_mappers = $Tainacan_Mappers->get_mappers( 'OBJECT' );
|
||||||
|
@ -110,7 +110,7 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
||||||
foreach ($metadatum_mappers as $metadatum_mapper){
|
foreach ($metadatum_mappers as $metadatum_mapper){
|
||||||
if($metadatum_mapper->show_ui) {
|
if($metadatum_mapper->show_ui) {
|
||||||
$mapper = $this->prepare_item_for_response($metadatum_mapper, $request);
|
$mapper = $this->prepare_item_for_response($metadatum_mapper, $request);
|
||||||
$mapper['disabled'] = in_array($metadatum_mapper->slug, $disabled_mappers) ? true : false;
|
$mapper['disabled'] = !empty($disabled_mappers) && in_array($metadatum_mapper->slug, $disabled_mappers) ? true : false;
|
||||||
array_push($prepared, $mapper);
|
array_push($prepared, $mapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,16 +123,29 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
||||||
* @return \WP_Error|\WP_REST_Response
|
* @return \WP_Error|\WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public function get_item( $request ) {
|
public function get_item( $request ) {
|
||||||
|
if( !isset( $request['slug'] ) ) {
|
||||||
|
return new \WP_REST_Response([
|
||||||
|
'error_message' => __('Slug mapper not informed', 'tainacan'),
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$collection_id = isset($request['collection_id']) ? $request['collection_id'] : 'default';
|
||||||
|
$disabled_mappers = get_post_meta($collection_id, 'disabled_mappers', false);
|
||||||
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
||||||
|
|
||||||
$metadatum_mappers = $Tainacan_Mappers->get_mappers( 'OBJECT' );
|
$metadatum_mappers = $Tainacan_Mappers->get_mappers( 'OBJECT' );
|
||||||
|
|
||||||
$prepared = [];
|
$slug_mapper = $request['slug'];
|
||||||
foreach ($metadatum_mappers as $metadatum_mapper){
|
$mapper_key = array_search($slug_mapper, array_column($metadatum_mappers, 'slug') );
|
||||||
if($metadatum_mapper->show_ui) array_push($prepared, $this->prepare_item_for_response($metadatum_mapper, $request));
|
if( $mapper_key === false ) {
|
||||||
|
return new \WP_REST_Response([
|
||||||
|
'error_message' => __('Mapper not found', 'tainacan'),
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
|
$mapper = $metadatum_mappers[$mapper_key];
|
||||||
|
$prepared_mapper = $this->prepare_item_for_response($mapper, $request);
|
||||||
|
$prepared_mapper['disabled'] = !empty($disabled_mappers) && in_array($slug_mapper, $disabled_mappers) ? true : false;
|
||||||
|
|
||||||
return new \WP_REST_Response($prepared, 200);
|
return new \WP_REST_Response($prepared_mapper, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace Tainacan\Mappers;
|
||||||
class Dublin_Core extends Mapper {
|
class Dublin_Core extends Mapper {
|
||||||
public $slug = 'dublin-core';
|
public $slug = 'dublin-core';
|
||||||
public $name = 'Dublin Core';
|
public $name = 'Dublin Core';
|
||||||
|
public $description = 'The mapper of the Dublin Core standard';
|
||||||
public $allow_extra_metadata = true;
|
public $allow_extra_metadata = true;
|
||||||
public $context_url = 'http://dublincore.org/documents/dcmi-terms/';
|
public $context_url = 'http://dublincore.org/documents/dcmi-terms/';
|
||||||
public $header = '<?xml version="1.0"?><!DOCTYPE rdf:RDF SYSTEM "http://dublincore.org/2000/12/01-dcmes-xml-dtd.dtd"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" ></rdf:RDF>';
|
public $header = '<?xml version="1.0"?><!DOCTYPE rdf:RDF SYSTEM "http://dublincore.org/2000/12/01-dcmes-xml-dtd.dtd"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" ></rdf:RDF>';
|
||||||
|
|
|
@ -4,7 +4,8 @@ namespace Tainacan\Mappers;
|
||||||
|
|
||||||
abstract class Mapper {
|
abstract class Mapper {
|
||||||
public $slug = null; // Slug of Mapper, used as option on api call
|
public $slug = null; // Slug of Mapper, used as option on api call
|
||||||
public $name = null; // Public name do mapper
|
public $name = null; // Public name of the mapper
|
||||||
|
public $description = null; // Public descript of the mapper
|
||||||
public $allow_extra_metadata = true; // Allow more metadatum to be register
|
public $allow_extra_metadata = true; // Allow more metadatum to be register
|
||||||
public $context_url = null; // URL of mapper documentation
|
public $context_url = null; // URL of mapper documentation
|
||||||
public $type = ''; // The Class of the ontology that this mapping refers to. For example `CreativeWork`, which is a class of Schema.org if applied
|
public $type = ''; // The Class of the ontology that this mapping refers to. For example `CreativeWork`, which is a class of Schema.org if applied
|
||||||
|
@ -39,6 +40,7 @@ abstract class Mapper {
|
||||||
return [
|
return [
|
||||||
'slug' => $this->slug,
|
'slug' => $this->slug,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
|
'description' => $this->description,
|
||||||
'allow_extra_metadata' => $this->allow_extra_metadata,
|
'allow_extra_metadata' => $this->allow_extra_metadata,
|
||||||
'context_url' => $this->context_url,
|
'context_url' => $this->context_url,
|
||||||
'metadata' => $this->metadata,
|
'metadata' => $this->metadata,
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace Tainacan\Mappers;
|
||||||
class Wiki_Data extends Mapper {
|
class Wiki_Data extends Mapper {
|
||||||
public $slug = 'wiki-data';
|
public $slug = 'wiki-data';
|
||||||
public $name = 'WikiData';
|
public $name = 'WikiData';
|
||||||
|
public $description = 'The model mapper using the WikiData source';
|
||||||
public $allow_extra_metadata = true;
|
public $allow_extra_metadata = true;
|
||||||
public $context_url = 'http://??????';
|
public $context_url = 'http://??????';
|
||||||
public $header = '??????';
|
public $header = '??????';
|
||||||
|
|
Loading…
Reference in New Issue