This commit is contained in:
weryques 2017-12-07 13:49:45 -02:00
commit 364b30cff6
4 changed files with 43 additions and 2 deletions

View File

@ -4,6 +4,7 @@ namespace Tainacan\Field_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
use Tainacan\Helpers;
/**
* Class TainacanFieldType
*/
@ -23,4 +24,22 @@ class Date extends Field_Type {
public function render( $metadata ){
return '<tainacan-date name="'.$metadata->get_name().'"></tainacan-date>';
}
/**
* generate the fields for this field type
*/
public function form(){
$approx_date = ( $this->options['approximate_date'] ) ? $this->options['approximate_date'] : '';
?>
<tr>
<td>
<label><?php echo __('Approximate Date','tainacan'); ?></label><br/>
<small><?php echo __('Allow format approximate date','tainacan'); ?></small>
</td>
<td>
<?php Helpers\HtmlHelpers::radio_field( $approx_date, 'field_type_date[approximate_date]' ) ?>
</td>
</tr>
<?php
}
}

View File

@ -43,6 +43,7 @@ class Relationship extends Field_Type {
<tr>
<td>
<label><?php echo __('Metadata for search','tainacan'); ?></label><br/>
<small><?php echo __('Selected metadata to help in the search','tainacan'); ?></small>
</td>
<td>
<?php Helpers\HtmlHelpers::metadata_checkbox_list(
@ -59,7 +60,7 @@ class Relationship extends Field_Type {
<small><?php echo __('Allow/Block selected items in this relationship','tainacan'); ?></small>
</td>
<td>
<textarea name="field_type_relationship[repeated]"><?php echo ( isset( $this->options['repeated'] ) ) ? $this->options['repeated'] : 'yes'; ?></textarea>
<?php Helpers\HtmlHelpers::radio_field( ( isset( $this->options['repeated'] ) ) ? $this->options['repeated'] : 'yes', 'field_type_relationship[repeated]' ) ?>
</td>
</tr>
<?php if( isset( $this->options['collection_id'] ) ): ?>

View File

@ -23,4 +23,11 @@ class Textarea extends Field_Type {
public function render( $metadata ){
return '<tainacan-textarea name="'.$metadata->get_name().'"></tainacan-textarea>';
}
/**
* generate the fields for this field type
*/
public function form(){
}
}

View File

@ -56,7 +56,7 @@ use Tainacan\Entities;
$metadata = $Tainacan_Metadatas->fetch_by_collection( $collection, $args, 'OBJECT');
?>
<select name="<?php echo $name_field ?>">
<option value=""><?php echo __('Select','tainacan') ?></option>
<option value=""><?php echo __('Select an option','tainacan') ?>...</option>
<?php foreach ($metadata as $col): ?>
<option value="<?php echo $col->get_id(); ?>" <?php selected($col->get_id(), $selected) ?>><?php echo $col->get_name(); ?></option>
<?php endforeach; ?>
@ -88,5 +88,19 @@ use Tainacan\Entities;
<?php
}
/**
* generates the radio button with options
*
* @param string $selected The value to be selectred
* @param string $name_field (optional) the radio field name
* @param array $options (optional) Associative array, indexes are the radio values and the values are the labels. Default yes and no
*/
public static function radio_field( $selected, $name_field = 'radio_field', $options = [ 'yes' => 'Yes', 'no' => 'No' ]){
foreach ($options as $value => $option): ?>
<input type="radio" name="<?php echo $name_field ?>" value="<?php echo $value; ?>" <?php checked($value == $selected); ?> style="width: 15px;">
<?php echo $option; ?>
<br/>
<?php endforeach;
}
}