PodsField

The Pods - Custom Content Types and Fields PodsField class.

Defined (1)

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

/classes/PodsField.php  
  1. class PodsField { 
  2.  
  3. /** 
  4. * Whether this field is running under 1.x deprecated forms 
  5. * @var bool 
  6. * @since 2.0 
  7. */ 
  8. public static $deprecated = false; 
  9.  
  10. /** 
  11. * Field Type Identifier 
  12. * @var string 
  13. * @since 2.0 
  14. */ 
  15. public static $type = 'text'; 
  16.  
  17. /** 
  18. * Field Type Label 
  19. * @var string 
  20. * @since 2.0 
  21. */ 
  22. public static $label = 'Unknown'; 
  23.  
  24. /** 
  25. * Field Type Preparation 
  26. * @var string 
  27. * @since 2.0 
  28. */ 
  29. public static $prepare = '%s'; 
  30.  
  31. /** 
  32. * Pod Types supported on (true for all, false for none, or give array of specific types supported) 
  33. * @var array|bool 
  34. * @since 2.1 
  35. */ 
  36. public static $pod_types = true; 
  37.  
  38. /** 
  39. * API caching for fields that need it during validate/save 
  40. * @var \PodsAPI 
  41. * @since 2.3 
  42. */ 
  43. private static $api = false; 
  44.  
  45. /** 
  46. * Do things like register/enqueue scripts and stylesheets 
  47. * @return \PodsField 
  48. * @since 2.0 
  49. */ 
  50. public function __construct () { 
  51.  
  52.  
  53. /** 
  54. * Add options and set defaults for field type, shows in admin area 
  55. * @return array $options 
  56. * @since 2.0 
  57. * @see PodsField::ui_options 
  58. */ 
  59. public function options () { 
  60. $options = array( /** 
  61. 'option_name' => array( 
  62. 'label' => 'Option Label',  
  63. 'depends-on' => array( 'another_option' => 'specific-value' ),  
  64. 'default' => 'default-value',  
  65. 'type' => 'field_type',  
  66. 'data' => array( 
  67. 'value1' => 'Label 1',  
  68.   
  69. // Group your options together 
  70. 'Option Group' => array( 
  71. 'gvalue1' => 'Option Label 1',  
  72. 'gvalue2' => 'Option Label 2' 
  73. ),  
  74.   
  75. // below is only if the option_name above is the "{$fieldtype}_format_type" 
  76. 'value2' => array( 
  77. 'label' => 'Label 2',  
  78. 'regex' => '[a-zA-Z]' // Uses JS regex validation for the value saved if this option selected 
  79. ),  
  80.   
  81. // below is only for a boolean group 
  82. 'group' => array( 
  83. 'option_boolean1' => array( 
  84. 'label' => 'Option boolean 1?',  
  85. 'default' => 1,  
  86. 'type' => 'boolean' 
  87. ),  
  88. 'option_boolean2' => array( 
  89. 'label' => 'Option boolean 2?',  
  90. 'default' => 0,  
  91. 'type' => 'boolean' 
  92. ) */ 
  93. ); 
  94.  
  95. return $options; 
  96.  
  97. /** 
  98. * Options for the Admin area, defaults to $this->options() 
  99. * @return array $options 
  100. * @since 2.0 
  101. * @see PodsField::options 
  102. */ 
  103. public function ui_options () { 
  104. return $this->options(); 
  105.  
  106. /** 
  107. * Define the current field's schema for DB table storage 
  108. * @param array $options 
  109. * @return string 
  110. * @since 2.0 
  111. */ 
  112. public function schema ( $options = null ) { 
  113. $schema = 'VARCHAR(255)'; 
  114.  
  115. return $schema; 
  116.  
  117. /** 
  118. * Define the current field's preparation for sprintf 
  119. * @param array $options 
  120. * @return array 
  121. * @since 2.0 
  122. */ 
  123. public function prepare ( $options = null ) { 
  124. $format = self::$prepare; 
  125.  
  126. return $format; 
  127.  
  128. /** 
  129. * Change the value of the field 
  130. * @param mixed $value 
  131. * @param string $name 
  132. * @param array $options 
  133. * @param array $pod 
  134. * @param int $id 
  135. * @return mixed|null|string 
  136. * @since 2.3 
  137. */ 
  138. public function value ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  139. return $value; 
  140.  
  141. /** 
  142. * Change the way the value of the field is displayed with Pods::get 
  143. * @param mixed $value 
  144. * @param string $name 
  145. * @param array $options 
  146. * @param array $pod 
  147. * @param int $id 
  148. * @return mixed|null|string 
  149. * @since 2.0 
  150. */ 
  151. public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  152. return $value; 
  153.  
  154. /** 
  155. * Customize output of the form field 
  156. * @param string $name 
  157. * @param mixed $value 
  158. * @param array $options 
  159. * @param array $pod 
  160. * @param int $id 
  161. * @return void 
  162. * @since 2.0 
  163. */ 
  164. public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  165. $options = (array) $options; 
  166. $form_field_type = PodsForm::$field_type; 
  167.  
  168. if ( is_array( $value ) ) 
  169. $value = implode( ' ', $value ); 
  170.  
  171. pods_view( PODS_DIR . 'ui/fields/text.php', compact( array_keys( get_defined_vars() ) ) ); 
  172.  
  173. /** 
  174. * Get the data from the field 
  175. * @param string $name The name of the field 
  176. * @param string|array $value The value of the field 
  177. * @param array $options 
  178. * @param array $pod 
  179. * @param int $id 
  180. * @param boolean $in_form 
  181. * @return array Array of possible field data 
  182. * @since 2.0 
  183. */ 
  184. public function data ( $name, $value = null, $options = null, $pod = null, $id = null, $in_form = true ) { 
  185. return (array) $value; 
  186.  
  187. /** 
  188. * Build regex necessary for JS validation 
  189. * @param mixed $value 
  190. * @param string $name 
  191. * @param array $options 
  192. * @param string $pod 
  193. * @param int $id 
  194. * @return bool 
  195. * @since 2.0 
  196. */ 
  197. public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  198. return false; 
  199.  
  200. /** 
  201. * Validate a value before it's saved 
  202. * @param mixed $value 
  203. * @param string $name 
  204. * @param array $options 
  205. * @param array $fields 
  206. * @param array $pod 
  207. * @param int $id 
  208. * @param array $params 
  209. * @return bool 
  210. * @since 2.0 
  211. */ 
  212. public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { 
  213. return true; 
  214.  
  215. /** 
  216. * Change the value or perform actions after validation but before saving to the DB 
  217. * @param mixed $value 
  218. * @param int $id 
  219. * @param string $name 
  220. * @param array $options 
  221. * @param array $fields 
  222. * @param array $pod 
  223. * @param object $params 
  224. * @return mixed 
  225. * @since 2.0 
  226. */ 
  227. public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  228. return $value; 
  229.  
  230. /** 
  231. * Save the value to the DB 
  232. * @param mixed $value 
  233. * @param int $id 
  234. * @param string $name 
  235. * @param array $options 
  236. * @param array $fields 
  237. * @param array $pod 
  238. * @param object $params 
  239. * @return bool|void Whether the value was saved 
  240. * @since 2.3 
  241. */ 
  242. public function save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  243. return null; 
  244.  
  245. /** 
  246. * Perform actions after saving to the DB 
  247. * @param mixed $value 
  248. * @param int $id 
  249. * @param string $name 
  250. * @param array $options 
  251. * @param array $fields 
  252. * @param array $pod 
  253. * @param object $params 
  254. * @since void 
  255. * @since 2.0 
  256. */ 
  257. public function post_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  258.  
  259.  
  260. /** 
  261. * Perform actions before deleting from the DB 
  262. * @param int $id 
  263. * @param string $name 
  264. * @param null $options 
  265. * @param string $pod 
  266. * @since void 
  267. * @since 2.0 
  268. */ 
  269. public function pre_delete ( $id = null, $name = null, $options = null, $pod = null ) { 
  270.  
  271.  
  272. /** 
  273. * Delete the value from the DB 
  274. * @param int $id 
  275. * @param string $name 
  276. * @param array $options 
  277. * @param array $pod 
  278. * @since void 
  279. * @since 2.3 
  280. */ 
  281. public function delete ( $id = null, $name = null, $options = null, $pod = null ) { 
  282.  
  283.  
  284. /** 
  285. * Perform actions after deleting from the DB 
  286. * @param int $id 
  287. * @param string $name 
  288. * @param array $options 
  289. * @param array $pod 
  290. * @since void 
  291. * @since 2.0 
  292. */ 
  293. public function post_delete ( $id = null, $name = null, $options = null, $pod = null ) { 
  294.  
  295.  
  296. /** 
  297. * Customize the Pods UI manage table column output 
  298. * @param int $id 
  299. * @param mixed $value 
  300. * @param string $name 
  301. * @param array $options 
  302. * @param array $fields 
  303. * @param array $pod 
  304. * @since string Value to be shown in the UI 
  305. * @since 2.0 
  306. */ 
  307. public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { 
  308. return $value;