PodsBuilderModuleSingle

The Pods - Custom Content Types and Fields PodsBuilderModuleSingle class.

Defined (1)

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

/components/Builder/modules/single/PodsBuilderModuleSingle.php  
  1. class PodsBuilderModuleSingle extends LayoutModule { 
  2.  
  3. var $_name = ''; 
  4. var $_var = 'pods-builder-single'; 
  5. var $_description = ''; 
  6. var $_editor_width = 500; 
  7. var $_can_remove_wrappers = true; 
  8.  
  9. /** 
  10. * Register the Module 
  11. */ 
  12. public function PodsBuilderModuleSingle () { 
  13. $this->_name = __( 'Pods - Single Item', 'pods' ); 
  14. $this->_description = __( 'Display a single Pod item', '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. 'template' => '',  
  29. 'template_custom' => '',  
  30. 'sidebar' => 'none' 
  31. ); 
  32.  
  33. return ITUtility::merge_defaults( $new_defaults, $defaults ); 
  34.  
  35. /** 
  36. * Output something before the table form 
  37. * @param object $form Form class 
  38. * @param bool $results 
  39. */ 
  40. function _before_table_edit ( $form, $results = true ) { 
  41. ?> 
  42. <p><?php echo $this->_description; ?></p> 
  43. <?php 
  44.  
  45. /** 
  46. * Output something at the start of the table form 
  47. * @param object $form Form class 
  48. * @param bool $results 
  49. */ 
  50. function _start_table_edit ( $form, $results = true ) { 
  51. $api = pods_api(); 
  52. $all_pods = $api->load_pods( array( 'names' => true ) ); 
  53.  
  54. $pod_types = array(); 
  55.  
  56. foreach ( $all_pods as $pod_name => $pod_label ) { 
  57. $pod_types[ $pod_name ] = $pod_label . ' (' . $pod_name . ')'; 
  58. ?> 
  59. <tr> 
  60. <td valign="top"> 
  61. <label for="pod_type"><?php _e( 'Pod', 'pods' ); ?></label> 
  62. </td> 
  63. <td> 
  64. <?php 
  65. if ( 0 < count( $all_pods ) ) 
  66. $form->add_drop_down( 'pod_type', $pod_types ); 
  67. else 
  68. echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; 
  69. ?> 
  70. </td> 
  71. </tr> 
  72. <tr> 
  73. <td valign="top"> 
  74. <label for="slug"><?php _e( 'Slug or ID', 'pods' ); ?></label> 
  75. </td> 
  76. <td> 
  77. <?php $form->add_text_box( 'slug' ); ?> 
  78. </td> 
  79. </tr> 
  80.  
  81. <?php 
  82. if ( class_exists( 'Pods_Templates' ) ) { 
  83. $all_templates = (array) $api->load_templates( array() ); 
  84.  
  85. $templates = array( 
  86. '' => '- ' . __( 'Custom Template', 'pods' ) . ' -' 
  87. ); 
  88.  
  89. foreach ( $all_templates as $template ) { 
  90. $templates[ $template[ 'name' ] ] = $template[ 'name' ]; 
  91. ?> 
  92. <tr> 
  93. <td valign="top"> 
  94. <label for="template"><?php _e( 'Template', 'pods' ); ?></label> 
  95. </td> 
  96. <td> 
  97. <?php 
  98. if ( 0 < count( $all_templates ) ) 
  99. $form->add_drop_down( 'template', $templates ); 
  100. else 
  101. echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; 
  102. ?> 
  103. </td> 
  104. </tr> 
  105. <?php 
  106. else { 
  107. ?> 
  108. <tr> 
  109. <td valign="top"> 
  110. <label for="template"><?php _e( 'Template', 'pods' ); ?></label> 
  111. </td> 
  112. <td> 
  113. <?php $form->add_text_box( 'template' ); ?> 
  114. </td> 
  115. </tr> 
  116. <?php 
  117. ?> 
  118.  
  119. <tr> 
  120. <td valign="top"> 
  121. <label for="template_custom"><?php _e( 'Custom Template', 'pods' ); ?></label> 
  122. </td> 
  123. <td> 
  124. <?php $form->add_text_area( 'template_custom', array( 'style' => 'width:90%; max-width:100%; min-height:100px;', 'rows' => '8' ) ); ?> 
  125. </td> 
  126. </tr> 
  127. <?php 
  128.  
  129. /** 
  130. * Module Output 
  131. */ 
  132. function _render ( $fields ) { 
  133. $args = array( 
  134. 'name' => trim( pods_var_raw( 'pod_type', $fields[ 'data' ], '' ) ),  
  135. 'slug' => trim( pods_var_raw( 'slug', $fields[ 'data' ], '' ) ),  
  136. 'template' => trim( pods_var_raw( 'template', $fields[ 'data' ], '' ) ) 
  137. ); 
  138.  
  139. $content = trim( pods_var_raw( 'template_custom', $fields[ 'data' ], '' ) ); 
  140.  
  141. if ( 0 < strlen( $args[ 'name' ] ) && 0 < strlen( $args[ 'slug' ] ) && ( 0 < strlen( $args[ 'template' ] ) || 0 < strlen( $content ) ) ) 
  142. echo pods_shortcode( $args, ( isset( $content ) ? $content : null ) ); 
  143.