acf_qtranslate_acf_5_text

The Advanced Custom Fields: qTranslate acf qtranslate 5 text class.

Defined (1)

The class is defined in the following location(s).

/src/acf_5/fields/text.php  
  1. class acf_qtranslate_acf_5_text extends acf_field_text { 
  2.  
  3. /** 
  4. * The plugin instance. 
  5. * @var \acf_qtranslate_plugin 
  6. */ 
  7. protected $plugin; 
  8.  
  9.  
  10. /** 
  11. * __construct 
  12. * This function will setup the field type data 
  13. * @type function 
  14. * @date 5/03/2014 
  15. * @since 5.0.0 
  16. * @param n/a 
  17. * @return n/a 
  18. */ 
  19. function __construct($plugin) { 
  20. $this->plugin = $plugin; 
  21.  
  22. $this->name = 'qtranslate_text'; 
  23. $this->label = __("Text", 'acf'); 
  24. $this->category = __("qTranslate", 'acf'); 
  25. $this->defaults = array( 
  26. 'default_value' => '',  
  27. 'maxlength' => '',  
  28. 'placeholder' => '',  
  29. 'prepend' => '',  
  30. 'append' => '',  
  31. 'readonly' => 0,  
  32. 'disabled' => 0,  
  33. ); 
  34.  
  35. acf_field::__construct(); 
  36.  
  37. /** 
  38. * render_field() 
  39. * Create the HTML interface for your field 
  40. * @param $field - an array holding all the field's data 
  41. * @type action 
  42. * @since 3.6 
  43. * @date 23/01/13 
  44. */ 
  45. function render_field($field) { 
  46. global $q_config; 
  47. $languages = qtrans_getSortedLanguages(true); 
  48. $values = qtrans_split($field['value'], $quicktags = true); 
  49. $currentLanguage = $this->plugin->get_active_language(); 
  50.  
  51. // vars 
  52. $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); 
  53. $s = array( 'readonly', 'disabled' ); 
  54. $e = ''; 
  55.  
  56. // maxlength 
  57. if( $field['maxlength'] !== "" ) { 
  58. $o[] = 'maxlength'; 
  59.  
  60. // populate atts 
  61. $atts = array(); 
  62. foreach( $o as $k ) { 
  63. $atts[ $k ] = $field[ $k ]; 
  64.  
  65. // special atts 
  66. foreach( $s as $k ) { 
  67. if( $field[ $k ] ) { 
  68. $atts[ $k ] = $k; 
  69.  
  70. // render 
  71. $e .= '<div class="acf-input-wrap multi-language-field">'; 
  72.  
  73. foreach ($languages as $language) { 
  74. $class = ($language === $currentLanguage) ? 'wp-switch-editor current-language' : 'wp-switch-editor'; 
  75. $e .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; 
  76.  
  77. foreach ($languages as $language) { 
  78. $atts['class'] = $field['class']; 
  79. if ($language === $currentLanguage) { 
  80. $atts['class'] .= ' current-language'; 
  81. $atts['type'] = 'text'; 
  82. $atts['name'] = $field['name'] . "[$language]"; 
  83. $atts['value'] = $values[$language]; 
  84. $atts['data-language'] = $language; 
  85. $e .= '<input ' . acf_esc_attr( $atts ) . ' />'; 
  86.  
  87. $e .= '</div>'; 
  88.  
  89. // return 
  90. echo $e; 
  91.  
  92. /** 
  93. * render_field_settings() 
  94. * Create extra options for your field. This is rendered when editing a field. 
  95. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  96. * @param $field - an array holding all the field's data 
  97. * @type action 
  98. * @since 3.6 
  99. * @date 23/01/13 
  100. */ 
  101. function render_field_settings($field) { 
  102. // default_value 
  103. acf_render_field_setting( $field, array( 
  104. 'label' => __('Default Value', 'acf'),  
  105. 'instructions' => __('Appears when creating a new post', 'acf'),  
  106. 'type' => 'text',  
  107. 'name' => 'default_value',  
  108. )); 
  109.  
  110. // placeholder 
  111. acf_render_field_setting( $field, array( 
  112. 'label' => __('Placeholder Text', 'acf'),  
  113. 'instructions' => __('Appears within the input', 'acf'),  
  114. 'type' => 'text',  
  115. 'name' => 'placeholder',  
  116. )); 
  117.  
  118. // maxlength 
  119. acf_render_field_setting( $field, array( 
  120. 'label' => __('Character Limit', 'acf'),  
  121. 'instructions' => __('Leave blank for no limit', 'acf'),  
  122. 'type' => 'number',  
  123. 'name' => 'maxlength',  
  124. )); 
  125.  
  126. /** 
  127. * update_value() 
  128. * This filter is appied to the $value before it is updated in the db 
  129. * @type filter 
  130. * @since 3.6 
  131. * @date 23/01/13 
  132. * @param $value - the value which will be saved in the database 
  133. * @param $post_id - the $post_id of which the value will be saved 
  134. * @param $field - the field array holding all the field options 
  135. * @return $value - the modified value 
  136. */ 
  137. function update_value($value, $post_id, $field) { 
  138. return qtrans_join($value); 
  139.