get options saved values
This commit is contained in:
parent
a77593cba4
commit
a4c93b2ed9
|
@ -9,8 +9,6 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|||
*/
|
||||
class Checkbox extends Field_Type {
|
||||
|
||||
public $options;
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
parent::__construct();
|
||||
|
@ -34,7 +32,7 @@ class Checkbox extends Field_Type {
|
|||
<tr>
|
||||
<td>
|
||||
<label><?php echo __('Options','tainacan'); ?></label><br/>
|
||||
<small><?php echo __('Insert the options, separate by ";" for the metadata value','tainacan'); ?></small>
|
||||
<small><?php echo __('Insert the options, separate by lines for the metadata value','tainacan'); ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="tnc_metadata_options"><?php echo ( $this->options ) ? $this->options : ''; ?></textarea>
|
||||
|
|
|
@ -10,6 +10,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|||
abstract class Field_Type {
|
||||
|
||||
private $primitive_type;
|
||||
public $options;
|
||||
|
||||
abstract function render( $metadata );
|
||||
|
||||
|
@ -38,4 +39,11 @@ abstract class Field_Type {
|
|||
$this->primitive_type = $primitive_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $options
|
||||
*/
|
||||
public function set_options( $options ){
|
||||
$this->options = ( is_array( $options ) ) ? $options : unserialize( $options );
|
||||
}
|
||||
|
||||
}
|
|
@ -9,8 +9,6 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|||
*/
|
||||
class Radio extends Field_Type {
|
||||
|
||||
public $options;
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
parent::__construct();
|
||||
|
|
|
@ -9,8 +9,6 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|||
*/
|
||||
class Selectbox extends Field_Type {
|
||||
|
||||
public $options;
|
||||
|
||||
function __construct(){
|
||||
// call field type constructor
|
||||
parent::__construct();
|
||||
|
@ -34,10 +32,10 @@ class Selectbox extends Field_Type {
|
|||
<tr>
|
||||
<td>
|
||||
<label><?php echo __('Options','tainacan'); ?></label><br/>
|
||||
<small><?php echo __('Insert the options, separate by ";" for the metadata value','tainacan'); ?></small>
|
||||
<small><?php echo __('Insert the options, separate by lines for the metadata value','tainacan'); ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="fieldtype_textarea[options]"><?php echo ( $this->options ) ? $this->options : ''; ?></textarea>
|
||||
<textarea name="field_type_selectbox[options]"><?php echo ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; ?></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
|
|
|
@ -300,12 +300,26 @@ class Metadatas extends Repository {
|
|||
/**
|
||||
* fetch all registered field type classes
|
||||
*
|
||||
* @return array of Entities\Field_Types\Field_Type objects
|
||||
* Possible outputs are:
|
||||
* CLASS (default) - returns the Class name of of field types registered
|
||||
* NAME - return an Array of the names of field types registered
|
||||
*
|
||||
* @param $output string CLASS | NAME
|
||||
* @return array of Entities\Field_Types\Field_Type classes path name
|
||||
*/
|
||||
public function fetch_field_types(){
|
||||
public function fetch_field_types( $output = 'CLASS'){
|
||||
$return = [];
|
||||
|
||||
do_action('register_field_types');
|
||||
|
||||
if( $output === 'NAME' ){
|
||||
foreach ($this->field_types as $field_type) {
|
||||
$return[] = str_replace('\Tainacan\Field_Types\\','', $field_type);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
return $this->field_types;
|
||||
}
|
||||
}
|
|
@ -139,9 +139,9 @@ class DevInterface {
|
|||
<?php elseif ($prop == 'collections_ids'): ?>
|
||||
<?php $this->collections_checkbox_list($value); ?>
|
||||
<?php elseif ($prop == 'field_type'): ?>
|
||||
<?php $this->field_type_dropdown($value); ?>
|
||||
<?php elseif ($prop == 'field_type_object'): ?>
|
||||
<?php echo $value; ?>
|
||||
<?php elseif ($prop == 'field_type_object'): ?>
|
||||
<?php echo $this->field_type_dropdown($value); ?>
|
||||
<?php else: ?>
|
||||
<textarea name="tnc_prop_<?php echo $prop; ?>"><?php echo htmlspecialchars($value); ?></textarea>
|
||||
<?php endif; ?>
|
||||
|
@ -316,18 +316,25 @@ class DevInterface {
|
|||
}
|
||||
|
||||
function field_type_dropdown($selected) {
|
||||
|
||||
global $Tainacan_Metadatas;
|
||||
$field_types = $Tainacan_Metadatas->fetch_field_types();
|
||||
|
||||
$class = ( $selected ) ? unserialize( base64_decode( $selected ) ) : '';
|
||||
|
||||
if(is_object( $class )){
|
||||
$selected = str_replace('Tainacan\Field_Types\\','', get_class( $class ) );
|
||||
}
|
||||
|
||||
$field_types = $Tainacan_Metadatas->fetch_field_types('NAME');
|
||||
?>
|
||||
<select name="tnc_prop_field_type">
|
||||
<select name="tnc_prop_field_type_object">
|
||||
<?php foreach ($field_types as $field_type): ?>
|
||||
<option value="<?php echo $field_type; ?>" <?php selected($field_type, $selected) ?>><?php echo $field_type; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php
|
||||
if( $selected ){
|
||||
$type = new $selected();
|
||||
echo $type->form();
|
||||
if( $class ){
|
||||
echo $class->form();
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
|
@ -378,15 +385,18 @@ class DevInterface {
|
|||
|
||||
$entity->set_mapped_property($prop, $value);
|
||||
|
||||
// if ($prop == 'field_type') {
|
||||
// $ft = new $value();
|
||||
// $ft->set_options = $_POST['field_type_'$value];
|
||||
// update_post_meta($post_id, 'field_type_object', $ft);
|
||||
// }
|
||||
|
||||
if ($entity->validate_prop($prop)) {
|
||||
|
||||
if ($prop == 'field_type_object') {
|
||||
$class = '\Tainacan\Field_Types\\'.$value;
|
||||
$ft = new $class();
|
||||
$ft->set_options( $_POST['field_type_'.strtolower( $value )] );
|
||||
update_post_meta($post_id, 'field_type_object', base64_encode(serialize($ft)) );
|
||||
update_post_meta($post_id, 'field_type', base64_encode(get_class( $ft )) );
|
||||
}
|
||||
// we cannot user repository->insert here, it would create an infinite loop
|
||||
if ($mapped['map'] == 'meta') {
|
||||
else if ($mapped['map'] == 'meta') {
|
||||
update_post_meta($post_id, $prop, $value);
|
||||
} elseif ($mapped['map'] == 'meta_multi') {
|
||||
|
||||
|
|
Loading…
Reference in New Issue