PodsField_Code

Handles code field data and operations.

Defined (1)

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

/classes/fields/code.php  
  1. class PodsField_Code extends PodsField { 
  2.  
  3. /** 
  4. * Field Type Group 
  5. * @var string 
  6. * @since 2.0 
  7. */ 
  8. public static $group = 'Paragraph'; 
  9.  
  10. /** 
  11. * Field Type Identifier 
  12. * @var string 
  13. * @since 2.0 
  14. */ 
  15. public static $type = 'code'; 
  16.  
  17. /** 
  18. * Field Type Label 
  19. * @var string 
  20. * @since 2.0 
  21. */ 
  22. public static $label = 'Code (Syntax Highlighting)'; 
  23.  
  24. /** 
  25. * Field Type Preparation 
  26. * @var string 
  27. * @since 2.0 
  28. */ 
  29. public static $prepare = '%s'; 
  30.  
  31. /** 
  32. * Do things like register/enqueue scripts and stylesheets 
  33. * @since 2.0 
  34. */ 
  35. public function __construct () { 
  36.  
  37.  
  38. /** 
  39. * Add options and set defaults to 
  40. * @return array 
  41. * @since 2.0 
  42. */ 
  43. public function options () { 
  44. $options = array( 
  45. self::$type . '_repeatable' => array( 
  46. 'label' => __( 'Repeatable Field', 'pods' ),  
  47. 'default' => 0,  
  48. 'type' => 'boolean',  
  49. 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),  
  50. 'boolean_yes_label' => '',  
  51. 'dependency' => true,  
  52. 'developer_mode' => true 
  53. ),  
  54. 'output_options' => array( 
  55. 'label' => __( 'Output Options', 'pods' ),  
  56. 'group' => array( 
  57. self::$type . '_allow_shortcode' => array( 
  58. 'label' => __( 'Allow Shortcodes?', 'pods' ),  
  59. 'default' => 0,  
  60. 'type' => 'boolean',  
  61. 'dependency' => true 
  62. ),  
  63. self::$type . '_max_length' => array( 
  64. 'label' => __( 'Maximum Length', 'pods' ),  
  65. 'default' => 0,  
  66. 'type' => 'number',  
  67. 'help' => __( 'Set to -1 for no limit', 'pods' ) 
  68. )/**,  
  69. self::$type . '_size' => array( 
  70. 'label' => __( 'Field Size', 'pods' ),  
  71. 'default' => 'medium',  
  72. 'type' => 'pick',  
  73. 'data' => array( 
  74. 'small' => __( 'Small', 'pods' ),  
  75. 'medium' => __( 'Medium', 'pods' ),  
  76. 'large' => __( 'Large', 'pods' ) 
  77. )*/ 
  78. ); 
  79.  
  80. return $options; 
  81.  
  82. /** 
  83. * Define the current field's schema for DB table storage 
  84. * @param array $options 
  85. * @return array 
  86. * @since 2.0 
  87. */ 
  88. public function schema ( $options = null ) { 
  89. $length = (int) pods_v( self::$type . '_max_length', $options, 0 ); 
  90.  
  91. $schema = 'LONGTEXT'; 
  92.  
  93. if ( 0 < $length ) { 
  94. $schema = 'VARCHAR(' . $length . ')'; 
  95.  
  96. return $schema; 
  97.  
  98. /** 
  99. * Change the way the value of the field is displayed with Pods::get 
  100. * @param mixed $value 
  101. * @param string $name 
  102. * @param array $options 
  103. * @param array $fields 
  104. * @param array $pod 
  105. * @param int $id 
  106. * @since 2.0 
  107. */ 
  108. public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  109. if ( 1 == pods_v( self::$type . '_allow_shortcode', $options, 0 ) ) 
  110. $value = do_shortcode( $value ); 
  111.  
  112. return $value; 
  113.  
  114. /** 
  115. * Customize output of the form field 
  116. * @param string $name 
  117. * @param mixed $value 
  118. * @param array $options 
  119. * @param array $pod 
  120. * @param int $id 
  121. * @since 2.0 
  122. */ 
  123. public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  124. $options = (array) $options; 
  125. $form_field_type = PodsForm::$field_type; 
  126.  
  127. if ( is_array( $value ) ) 
  128. $value = implode( "\n", $value ); 
  129.  
  130. $field_type = 'codemirror'; 
  131.  
  132. do_action( 'pods_form_ui_field_code_' . $field_type, $name, $value, $options, $pod, $id ); 
  133. do_action( 'pods_form_ui_field_code', $field_type, $name, $value, $options, $pod, $id ); 
  134.  
  135. pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) ); 
  136.  
  137. /** 
  138. * Change the value or perform actions after validation but before saving to the DB 
  139. * @param mixed $value 
  140. * @param int $id 
  141. * @param string $name 
  142. * @param array $options 
  143. * @param array $fields 
  144. * @param array $pod 
  145. * @param object $params 
  146. * @since 2.0 
  147. */ 
  148. public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  149. $length = (int) pods_var( self::$type . '_max_length', $options, 0 ); 
  150.  
  151. if ( 0 < $length && $length < pods_mb_strlen( $value ) ) { 
  152. $value = pods_mb_substr( $value, 0, $length ); 
  153.  
  154. return $value;