PodsField_Slug

The Pods - Custom Content Types and Fields PodsField Slug class.

Defined (1)

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

/classes/fields/slug.php  
  1. class PodsField_Slug extends PodsField { 
  2.  
  3. /** 
  4. * Field Type Identifier 
  5. * @var string 
  6. * @since 2.0 
  7. */ 
  8. public static $type = 'slug'; 
  9.  
  10. /** 
  11. * Field Type Label 
  12. * @var string 
  13. * @since 2.0 
  14. */ 
  15. public static $label = 'Permalink (url-friendly)'; 
  16.  
  17. /** 
  18. * Field Type Preparation 
  19. * @var string 
  20. * @since 2.0 
  21. */ 
  22. public static $prepare = '%s'; 
  23.  
  24. /** 
  25. * Pod Types supported on (true for all, false for none, or give array of specific types supported) 
  26. * @var array|bool 
  27. * @since 2.1 
  28. */ 
  29. public static $pod_types = array( 'pod', 'table' ); 
  30.  
  31. /** 
  32. * Do things like register/enqueue scripts and stylesheets 
  33. * @since 2.0 
  34. */ 
  35. public function __construct () { 
  36.  
  37.  
  38. /** 
  39. * Define the current field's schema for DB table storage 
  40. * @param array $options 
  41. * @return array 
  42. * @since 2.0 
  43. */ 
  44. public function schema ( $options = null ) { 
  45. $schema = 'VARCHAR(200)'; 
  46.  
  47. return $schema; 
  48.  
  49. /** 
  50. * Change the way the value of the field is displayed with Pods::get 
  51. * @param mixed $value 
  52. * @param string $name 
  53. * @param array $options 
  54. * @param array $pod 
  55. * @param int $id 
  56. * @return mixed|null 
  57. * @since 2.0 
  58. */ 
  59. public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  60. return $value; 
  61.  
  62. /** 
  63. * Customize output of the form field 
  64. * @param string $name 
  65. * @param mixed $value 
  66. * @param array $options 
  67. * @param array $pod 
  68. * @param int $id 
  69. * @since 2.0 
  70. */ 
  71. public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  72. $options = (array) $options; 
  73. $form_field_type = PodsForm::$field_type; 
  74.  
  75. if ( is_array( $value ) ) 
  76. $value = implode( '-', $value ); 
  77.  
  78. $field_type = 'slug'; 
  79.  
  80. if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) { 
  81. if ( pods_var( 'read_only', $options, false ) ) { 
  82. $options[ 'readonly' ] = true; 
  83.  
  84. $field_type = 'text'; 
  85. else 
  86. return; 
  87. elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) { 
  88. $options[ 'readonly' ] = true; 
  89.  
  90. $field_type = 'text'; 
  91.  
  92. pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) ); 
  93.  
  94. /** 
  95. * Build regex necessary for JS validation 
  96. * @param mixed $value 
  97. * @param string $name 
  98. * @param array $options 
  99. * @param string $pod 
  100. * @param int $id 
  101. * @return bool 
  102. * @since 2.0 
  103. */ 
  104. public function regex ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  105. return false; 
  106.  
  107. /** 
  108. * Validate a value before it's saved 
  109. * @param mixed $value 
  110. * @param string $name 
  111. * @param array $options 
  112. * @param array $fields 
  113. * @param array $pod 
  114. * @param int $id 
  115. * @param null $params 
  116. * @return bool 
  117. * @since 2.0 
  118. */ 
  119. public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) { 
  120. return true; 
  121.  
  122. /** 
  123. * Change the value or perform actions after validation but before saving to the DB 
  124. * @param mixed $value 
  125. * @param int $id 
  126. * @param string $name 
  127. * @param array $options 
  128. * @param array $fields 
  129. * @param array $pod 
  130. * @param object $params 
  131. * @return mixed|string 
  132. * @since 2.0 
  133. */ 
  134. public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  135. $index = pods_var( 'pod_index', pods_var( 'options', $pod, $pod, null, true ), 'id', null, true ); 
  136.  
  137. if ( empty( $value ) && isset( $fields[ $index ] ) ) 
  138. $value = $fields[ $index ][ 'value' ]; 
  139.  
  140. $value = pods_unique_slug( $value, $name, $pod, 0, $params->id, null, false ); 
  141.  
  142. return $value; 
  143.  
  144. /** 
  145. * Customize the Pods UI manage table column output 
  146. * @param int $id 
  147. * @param mixed $value 
  148. * @param string $name 
  149. * @param array $options 
  150. * @param array $fields 
  151. * @param array $pod 
  152. * @return mixed|void 
  153. * @since 2.0 
  154. */ 
  155. public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { 
  156. return $this->display( $value, $name, $options, $pod, $id );