Caldera_Forms_Entry_Vue

Create entry viewer v2.

Defined (1)

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

/classes/entry/vue.php  
  1. class Caldera_Forms_Entry_Vue { 
  2.  
  3. /** 
  4. * Viewer config 
  5. * @since 1.5.0 
  6. * @var array 
  7. */ 
  8. protected $config; 
  9.  
  10. /** 
  11. * Form config 
  12. * @since 1.5.0 
  13. * @var array 
  14. */ 
  15. protected $form; 
  16.  
  17. /** 
  18. * Caldera_Forms_Entry_Vue constructor. 
  19. * @since 1.5.0 
  20. * @param array $form Form config 
  21. * @param array $config Optional. Viewer config default overrides 
  22. */ 
  23. public function __construct( array $form, array $config = array()) { 
  24. $this->form = $form; 
  25. $this->set_config( $config ); 
  26. $this->enqueue(); 
  27.  
  28. /** 
  29. * Display the entry viewer 
  30. * @since 1.5.0 
  31. * @return string 
  32. */ 
  33. public function display() { 
  34. $this->enqueue(); 
  35. ob_start(); 
  36. include CFCORE_PATH .'ui/viewer-two/viewer.php'; 
  37. return ob_start(); 
  38. /** 
  39. * Setup scripts/styles for entry viewer 
  40. * @since 1.5.0 
  41. */ 
  42. public function enqueue() { 
  43. Caldera_Forms_Render_Assets::maybe_register(); 
  44. Caldera_Forms_Render_Assets::enqueue_style( 'table' ); 
  45. Caldera_Forms_Render_Assets::enqueue_style( 'modals' ); 
  46. Caldera_Forms_Render_Assets::enqueue_style( 'entry-viewer-2' ); 
  47. Caldera_Forms_Render_Assets::enqueue_style( 'modals-theme' ); 
  48. Caldera_Forms_Render_Assets::enqueue_script( 'modals' ); 
  49. Caldera_Forms_Render_Assets::enqueue_script( 'entry-viewer-2' ); 
  50. wp_localize_script( Caldera_Forms_Render_Assets::make_slug( 'entry-viewer-2' ), 'CF_ENTRY_VIEWER_2_CONFIG', $this->config ); 
  51.  
  52.  
  53. /** 
  54. * Set config property with defaults and ovverides passed ot constructor 
  55. * @since 1.5.0 
  56. * @param array $config 
  57. */ 
  58. protected function set_config($config ) { 
  59. $this->config = wp_parse_args( $config, $this->config_defaults() ); 
  60. if( isset( $config[ 'token' ] ) ) { 
  61. $this->config[ 'api' ][ 'token' ] = $config[ 'token' ]; 
  62.  
  63. /** 
  64. * Filter configuration (passed to JavaScript) for Entry Viewer (v2) 
  65. * @since 1.5.0 
  66. * @param array $config Configuration to filter 
  67. * @param array $form Form config 
  68. */ 
  69. $this->config = apply_filters( 'caldera_forms_entry_viewer_2_config', $this->config, $this->form ); 
  70.  
  71.  
  72. /** 
  73. * The defaults for config 
  74. * @since 1.5.0 
  75. * @return array 
  76. */ 
  77. protected function config_defaults() { 
  78. $config = new Caldera_Forms_API_JsConfig( $this->form ); 
  79. $default = array_merge( $config->toArray(), array( 
  80. 'templates' => array( 
  81. 'entries' => 'caldera-forms-entries-tmpl',  
  82. 'entry' => 'caldera-forms-entry-tmpl' 
  83. ),  
  84. 'targets' => array( 
  85. 'entries' => 'caldera-forms-entries',  
  86. 'entry' => 'caldera-forms-entry' 
  87. ),  
  88. 'perPage' => absint( Caldera_Forms_Entry_Viewer::entries_per_page() ),  
  89. 'strings' => array( 
  90. 'no_entries' => esc_html__( 'No Entries To Display', 'caldera-forms' ),  
  91. 'not_allowed' => esc_html__( 'You are not allowed to view this.', 'caldera-forms' ) 
  92. ); 
  93. return $default;