PodsBuilderModuleField

The Pods - Custom Content Types and Fields PodsBuilderModuleField class.

Defined (1)

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

/components/Builder/modules/field/PodsBuilderModuleField.php  
  1. class PodsBuilderModuleField extends LayoutModule { 
  2.  
  3. var $_name = ''; 
  4. var $_var = 'pods-builder-field'; 
  5. var $_description = ''; 
  6. var $_editor_width = 500; 
  7. var $_can_remove_wrappers = true; 
  8.  
  9. /** 
  10. * Register the Module 
  11. */ 
  12. public function PodsBuilderModuleField () { 
  13. $this->_name = __( 'Pods - Field Value', 'pods' ); 
  14. $this->_description = __( "Display a single Pod item's field value", 'pods' ); 
  15. $this->module_path = dirname( __FILE__ ); 
  16.  
  17. $this->LayoutModule(); 
  18.  
  19. /** 
  20. * Set default variables 
  21. * @param $defaults 
  22. * @return mixed 
  23. */ 
  24. function _get_defaults ( $defaults ) { 
  25. $new_defaults = array( 
  26. 'pod_type' => '',  
  27. 'slug' => '',  
  28. 'field' => '',  
  29. 'sidebar' => 'none' 
  30. ); 
  31.  
  32. return ITUtility::merge_defaults( $new_defaults, $defaults ); 
  33.  
  34. /** 
  35. * Output something before the table form 
  36. * @param object $form Form class 
  37. * @param bool $results 
  38. */ 
  39. function _before_table_edit ( $form, $results = true ) { 
  40. ?> 
  41. <p><?php echo $this->_description; ?></p> 
  42. <?php 
  43.  
  44. /** 
  45. * Output something at the start of the table form 
  46. * @param object $form Form class 
  47. * @param bool $results 
  48. */ 
  49. function _start_table_edit ( $form, $results = true ) { 
  50. $api = pods_api(); 
  51. $all_pods = $api->load_pods( array( 'names' => true ) ); 
  52.  
  53. $pod_types = array(); 
  54.  
  55. foreach ( $all_pods as $pod_name => $pod_label ) { 
  56. $pod_types[ $pod_name ] = $pod_label . ' (' . $pod_name . ')'; 
  57. ?> 
  58. <tr> 
  59. <td valign="top"> 
  60. <label for="pod_type"><?php _e( 'Pod', 'pods' ); ?></label> 
  61. </td> 
  62. <td> 
  63. <?php 
  64. if ( 0 < count( $all_pods ) ) 
  65. $form->add_drop_down( 'pod_type', $pod_types ); 
  66. else 
  67. echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; 
  68. ?> 
  69. </td> 
  70. </tr> 
  71. <tr> 
  72. <td valign="top"> 
  73. <label for="slug"><?php _e( 'Slug or ID', 'pods' ); ?></label> 
  74. </td> 
  75. <td> 
  76. <?php $form->add_text_box( 'slug' ); ?> 
  77. </td> 
  78. </tr> 
  79. <tr> 
  80. <td valign="top"> 
  81. <label for="field"><?php _e( 'Field', 'pods' ); ?></label> 
  82. </td> 
  83. <td> 
  84. <?php $form->add_text_box( 'field' ); ?> 
  85. </td> 
  86. </tr> 
  87. <?php 
  88.  
  89. /** 
  90. * Module Output 
  91. */ 
  92. function _render ( $fields ) { 
  93. $args = array( 
  94. 'name' => trim( pods_var_raw( 'pod_type', $fields[ 'data' ], '' ) ),  
  95. 'slug' => trim( pods_var_raw( 'slug', $fields[ 'data' ], '' ) ),  
  96. 'field' => trim( pods_var_raw( 'field', $fields[ 'data' ], '' ) ) 
  97. ); 
  98.  
  99. if ( 0 < strlen( $args[ 'name' ] ) && 0 < strlen( $args[ 'slug' ] ) && 0 < strlen( $args[ 'field' ] ) ) 
  100. echo pods_shortcode( $args, ( isset( $content ) ? $content : null ) ); 
  101.