diff --git a/src/classes/entities/class-tainacan-filter.php b/src/classes/entities/class-tainacan-filter.php
index 76ea74548..45e8e2c86 100644
--- a/src/classes/entities/class-tainacan-filter.php
+++ b/src/classes/entities/class-tainacan-filter.php
@@ -82,23 +82,35 @@ class Filter extends Entity {
}
/**
- * Retorna o objeto filtro
+ * Retorna o objeto Filter Type
*
- * @return Filter
+ * @return array || object
*/
function get_filter_type_object(){
- return unserialize( base64_decode( $this->get_mapped_property('filter_type_object') ) );
+ $class_name = $this->get_filter_type();
+ $object_type = new $class_name();
+ $object_type->set_options( $this->get_filter_options() );
+ return $object_type;
}
/**
- * Retorna o filtro
+ * Retorna o objeto field type
*
- * @return string
+ * @return array || object
*/
function get_filter_type(){
return $this->get_mapped_property('filter_type');
}
+ /**
+ * Retorna o objeto Metadado
+ *
+ * @return array || object
+ */
+ function get_filter_options(){
+ return $this->get_mapped_property('filter_type_options');
+ }
+
/**
* Atribui nome ao filtro
*
@@ -157,14 +169,14 @@ class Filter extends Entity {
* @param \Tainacan\Filter_Types\Filter_Type $value
* @return void
*/
- function set_filter_type_object( \Tainacan\Filter_Types\Filter_Type $value ){
- // TODO: validate primitive type with filter
- //if filter matches the metadata type
- //if( in_array( $type->get_primitive_type(), $value->get_supported_types() ) ){
- $this->set_filter_type( get_class( $value ) );
- $this->set_mapped_property('filter_type_object', base64_encode( serialize($value) ) );
- //}
- }
+// function set_filter_type_object( \Tainacan\Filter_Types\Filter_Type $value ){
+// // TODO: validate primitive type with filter
+// //if filter matches the metadata type
+// //if( in_array( $type->get_primitive_type(), $value->get_supported_types() ) ){
+// $this->set_filter_type( get_class( $value ) );
+// $this->set_mapped_property('filter_type_object', base64_encode( serialize($value) ) );
+// //}
+// }
/**
* Atribui o filter type.
@@ -173,7 +185,7 @@ class Filter extends Entity {
* @param string
*
*/
- private function set_filter_type($value){
- $this->set_mapped_property('filter_type', $value );
+ public function set_filter_type($value){
+ $this->set_mapped_property('filter_type', get_class( $value ) );
}
}
\ No newline at end of file
diff --git a/src/classes/entities/class-tainacan-metadata.php b/src/classes/entities/class-tainacan-metadata.php
index d58da42be..505e760a8 100644
--- a/src/classes/entities/class-tainacan-metadata.php
+++ b/src/classes/entities/class-tainacan-metadata.php
@@ -150,7 +150,10 @@ class Metadata extends Entity {
* @return array || object
*/
function get_field_type_object(){
- return unserialize(base64_decode( $this->get_mapped_property('field_type_object') ) );
+ $class_name = $this->get_field_type();
+ $object_type = new $class_name();
+ $object_type->set_options( $this->get_field_options() );
+ return $object_type;
}
/**
@@ -159,7 +162,16 @@ class Metadata extends Entity {
* @return array || object
*/
function get_field_type(){
- return base64_decode($this->get_mapped_property('field_type'));
+ return $this->get_mapped_property('field_type');
+ }
+
+ /**
+ * Retorna o objeto Metadado
+ *
+ * @return array || object
+ */
+ function get_field_options(){
+ return $this->get_mapped_property('get_field_options');
}
/**
@@ -272,18 +284,13 @@ class Metadata extends Entity {
$this->set_mapped_property('default_property', $value);
}
- function set_field_type_object(\Tainacan\Field_Types\Field_Type $value){
- $this->set_field_type( get_class( $value ) );
- $this->set_mapped_property('field_type_object', base64_encode( serialize($value) ) ); // Encode to avoid backslaches removal
- }
-
/**
- * Este metodo é privado, porque é utilizado apenas neste contexto pelo @method set_field_type_object()
+ * save the class field class name
*
* @param $value
*/
- private function set_field_type($value){
- $this->set_mapped_property('field_type', base64_encode($value) ) ; // Encode to avoid backslaches removal
+ public function set_field_type($value){
+ $this->set_mapped_property('field_type', get_class( $value ) ) ; // Encode to avoid backslaches removal
}
// helpers
diff --git a/src/classes/filter-types/class-tainacan-filter-type.php b/src/classes/filter-types/class-tainacan-filter-type.php
index c00efd9ab..0a1310676 100644
--- a/src/classes/filter-types/class-tainacan-filter-type.php
+++ b/src/classes/filter-types/class-tainacan-filter-type.php
@@ -7,6 +7,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
abstract class Filter_Type {
private $supported_types = [];
+ public $options;
abstract function render( $metadata );
@@ -17,4 +18,11 @@ abstract class Filter_Type {
public function set_supported_types($supported_types){
$this->supported_types = $supported_types;
}
+
+ /**
+ * @param $options
+ */
+ public function set_options( $options ){
+ $this->options = ( is_array( $options ) ) ? $options : unserialize( $options );
+ }
}
\ No newline at end of file
diff --git a/src/classes/repositories/class-tainacan-filters.php b/src/classes/repositories/class-tainacan-filters.php
index 23063f20e..04e2a735a 100644
--- a/src/classes/repositories/class-tainacan-filters.php
+++ b/src/classes/repositories/class-tainacan-filters.php
@@ -40,11 +40,11 @@ class Filters extends Repository {
'description'=> __('The filter description', 'tainacan'),
'validation' => ''
],
- 'filter_type_object' => [
+ 'filter_type_options' => [
'map' => 'meta',
- 'title' => __('Type', 'tainacan'),
+ 'title' => __('Filter type options', 'tainacan'),
'type' => 'string',
- 'description'=> __('The filter type object', 'tainacan'),
+ 'description'=> __('The filter type options', 'tainacan'),
'validation' => ''
],
'filter_type' => [
diff --git a/src/classes/repositories/class-tainacan-metadatas.php b/src/classes/repositories/class-tainacan-metadatas.php
index 33af396ad..e4d8e3127 100644
--- a/src/classes/repositories/class-tainacan-metadatas.php
+++ b/src/classes/repositories/class-tainacan-metadatas.php
@@ -124,11 +124,11 @@ class Metadatas extends Repository {
'type' => 'string',
'description'=> __('The value default fot the metadata', 'tainacan'),
],
- 'field_type_object' => [ // not showed in form
+ 'field_type_options' => [ // not showed in form
'map' => 'meta',
- 'title' => __('Type', 'tainacan'),
+ 'title' => __('Field Type options', 'tainacan'),
'type' => 'string',
- 'description'=> __('The object type', 'tainacan'),
+ 'description'=> __('Options specific for field type', 'tainacan'),
// 'validation' => ''
],
'collection_id' => [ // not showed in form
diff --git a/src/dev-interface/class-tainacan-dev-interface.php b/src/dev-interface/class-tainacan-dev-interface.php
index fc462c87e..bf4980fa6 100644
--- a/src/dev-interface/class-tainacan-dev-interface.php
+++ b/src/dev-interface/class-tainacan-dev-interface.php
@@ -138,10 +138,10 @@ class DevInterface {
collections_dropdown($value); ?>
collections_checkbox_list($value); ?>
-
+
-
- field_type_dropdown($value); ?>
+
+ field_type_dropdown($post->ID,$value); ?>
@@ -315,11 +315,11 @@ class DevInterface {
fetch_field_types('NAME');
?>
-