-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding field type for terms or categories - a kind of related type
- Loading branch information
Jakob Koehler
committed
Mar 6, 2012
1 parent
929c146
commit e5f50c9
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
// initialisation | ||
global $mf_domain; | ||
|
||
// class with static properties encapsulating functions for the field type | ||
|
||
class term_field extends mf_custom_fields { | ||
|
||
public $allow_multiple = TRUE; | ||
public $has_properties = TRUE; | ||
|
||
public function _update_description(){ | ||
global $mf_domain; | ||
$this->description = __("This field allows to do relations with taxonomie terms",$mf_domain); | ||
} | ||
|
||
public function _options(){ | ||
global $mf_domain; | ||
|
||
// Get the taxonomie as dropdownoption | ||
$select = array(); | ||
$zahl = 0; | ||
$tax = get_taxonomies(); | ||
foreach($tax as $k => $v){ | ||
$select[$zahl++] = $v; | ||
} | ||
|
||
$data = array( | ||
'option' => array( | ||
'term' => array( | ||
'type' => 'select', | ||
'id' => 'term', | ||
'label' => __('related taxonomie: ',$mf_domain), | ||
'name' => 'mf_field[option][term]', | ||
'default' => '', | ||
'options' => $select, | ||
'add_empty' => false, | ||
'description' => '', | ||
'value' => '', | ||
'div_class' => '', | ||
'class' => '' | ||
), | ||
) | ||
); | ||
return $data; | ||
|
||
} | ||
|
||
|
||
public function display_field( $field, $group_index = 1, $field_index = 1 ) { | ||
global $mf_domain; | ||
|
||
// If is not required this field be added a None value | ||
$notype = ""; | ||
if( !$field['required_field'] ) { | ||
$notype = ( !empty($field['options']['notype']) ) ? $field['options']['notype'] : __( "-- None --" , $mf_domain ); | ||
} | ||
|
||
$output = ''; | ||
|
||
// Get the taxonomie as dropdownoption | ||
$select = array(); | ||
$zahl = 0; | ||
$tax = get_taxonomies(); | ||
foreach($tax as $k => $v){ | ||
$select[$zahl++] = $v; | ||
} | ||
|
||
$option_from_term_array = $field['options']['term']; | ||
$options = get_terms($select[$option_from_term_array]); | ||
|
||
$output = '<div class="mf-dropdown-box">'; | ||
|
||
$value = $field['input_value']; | ||
|
||
$output .= sprintf('<select class="dropdown_mf" id="%s" name="%s" >',$field['input_id'],$field['input_name']); | ||
|
||
if( $notype != "" ) { | ||
$output .= "<option value=''>$notype</option>"; | ||
} | ||
|
||
foreach($options as $option) { | ||
|
||
$check = ($option->slug == $value) ? 'selected="selected"' : ''; | ||
$output .= sprintf('<option value="%s" %s >%s</option>', | ||
esc_attr($option->slug), | ||
$check, | ||
esc_attr($option->name) | ||
); | ||
} | ||
$output .= '</select>'; | ||
$output .= '</div>'; | ||
|
||
return $output; | ||
} | ||
} |