GFPDFControllerController_Form_Settings

Controller_Form_Settings Controls the individual form PDF settings pages.

Defined (1)

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

/src/controller/Controller_Form_Settings.php  
  1. class Controller_Form_Settings extends Helper_Abstract_Controller implements Helper_Interface_Actions, Helper_Interface_Filters { 
  2. /** 
  3. * Holds our Helper_Data object 
  4. * which we can autoload with any data needed 
  5. * @var \GFPDF\Helper\Helper_Data 
  6. * @since 4.0 
  7. */ 
  8. protected $data; 
  9.  
  10. /** 
  11. * Holds our Helper_Abstract_Options / Helper_Options_Fields object 
  12. * Makes it easy to access global PDF settings and individual form PDF settings 
  13. * @var \GFPDF\Helper\Helper_Options_Fields 
  14. * @since 4.0 
  15. */ 
  16. protected $options; 
  17.  
  18. /** 
  19. * Holds our Helper_Misc object 
  20. * Makes it easy to access common methods throughout the plugin 
  21. * @var \GFPDF\Helper\Helper_Misc 
  22. * @since 4.0 
  23. */ 
  24. protected $misc; 
  25.  
  26. /** 
  27. * Setup our class by injecting all our dependancies 
  28. * @param Helper_Abstract_Model|\GFPDF\Model\Model_Form_Settings $model Our Form Model the controller will manage 
  29. * @param Helper_Abstract_View|\GFPDF\View\View_Form_Settings $view Our Form View the controller will manage 
  30. * @param \GFPDF\Helper\Helper_Data $data Our plugin data store 
  31. * @param \GFPDF\Helper\Helper_Abstract_Options $options Our options class which allows us to access any settings 
  32. * @param \GFPDF\Helper\Helper_Misc $misc Our miscellaneous methods 
  33. * @since 4.0 
  34. */ 
  35. public function __construct( Helper_Abstract_Model $model, Helper_Abstract_View $view, Helper_Data $data, Helper_Abstract_Options $options, Helper_Misc $misc ) { 
  36.  
  37. /** Assign our internal variables */ 
  38. $this->data = $data; 
  39. $this->options = $options; 
  40. $this->misc = $misc; 
  41.  
  42. /** Load our model and view */ 
  43. $this->model = $model; 
  44. $this->model->setController( $this ); 
  45.  
  46. $this->view = $view; 
  47. $this->view->setController( $this ); 
  48.  
  49. /** 
  50. * Initialise our class defaults 
  51. * @since 4.0 
  52. * @return void 
  53. */ 
  54. public function init() { 
  55.  
  56. /** 
  57. * Tell Gravity Forms to add our form PDF settings pages 
  58. */ 
  59. $this->add_actions(); 
  60. $this->add_filters(); 
  61.  
  62. /** 
  63. * Apply any actions needed for the settings page 
  64. * @since 4.0 
  65. * @return void 
  66. */ 
  67. public function add_actions() { 
  68.  
  69. /** Trigger our save method */ 
  70. add_action( 'admin_init', [ $this, 'maybe_save_pdf_settings' ], 5 ); 
  71.  
  72. /** Tell Gravity Forms to add our form PDF settings pages */ 
  73. add_action( 'gform_form_settings_menu', [ $this->model, 'add_form_settings_menu' ] ); 
  74. add_action( 'gform_form_settings_page_' . $this->data->slug, [ $this, 'display_page' ] ); 
  75.  
  76. /** Add AJAX endpoints */ 
  77. add_action( 'wp_ajax_gfpdf_list_delete', [ $this->model, 'delete_gf_pdf_setting' ] ); 
  78. add_action( 'wp_ajax_gfpdf_list_duplicate', [ $this->model, 'duplicate_gf_pdf_setting' ] ); 
  79. add_action( 'wp_ajax_gfpdf_change_state', [ $this->model, 'change_state_pdf_setting' ] ); 
  80. add_action( 'wp_ajax_gfpdf_get_template_fields', [ $this->model, 'render_template_fields' ] ); 
  81.  
  82. /** 
  83. * Apply any filters needed for the settings page 
  84. * @since 4.0 
  85. * @return void 
  86. */ 
  87. public function add_filters() { 
  88.  
  89. /** Add custom field information if we have a template selected */ 
  90. add_filter( 'gfpdf_form_settings_custom_appearance', [ $this->model, 'register_custom_appearance_settings' ] ); 
  91. add_filter( 'gfpdf_form_settings', [ $this->model, 'register_template_group' ] ); 
  92.  
  93. /** Add Validation Errors */ 
  94. add_filter( 'gfpdf_form_settings', [ $this->model, 'validation_error' ] ); 
  95. add_filter( 'gfpdf_form_settings_appearance', [ $this->model, 'validation_error' ] ); 
  96.  
  97. /** Sanitize Results */ 
  98. add_filter( 'gfpdf_form_settings_sanitize', [ $this->options, 'sanitize_all_fields' ], 10, 4 ); 
  99. add_filter( 'gfpdf_form_settings_sanitize_text', [ $this->model, 'parse_filename_extension' ], 15, 2 ); 
  100. add_filter( 'gfpdf_form_settings_sanitize_text', [ $this->options, 'sanitize_trim_field' ], 15, 2 ); 
  101. add_filter( 'gfpdf_form_settings_sanitize_hidden', [ $this->model, 'decode_json' ], 10, 2 ); 
  102.  
  103. add_filter( 'gfpdf_skip_highlight_errors', [ $this->model, 'check_custom_size_error_highlighting' ], 10, 3 ); 
  104.  
  105. /** Store our TinyMCE Options */ 
  106. add_filter( 'tiny_mce_before_init', [ $this, 'store_tinymce_settings' ] ); 
  107.  
  108. /** 
  109. * Determine if we should be saving the PDF settings 
  110. * @return void 
  111. * @since 4.0 
  112. */ 
  113. public function maybe_save_pdf_settings() { 
  114. $form_id = ( isset( $_GET['id'] ) ) ? (int) $_GET['id'] : false; 
  115. $pdf_id = ( isset( $_GET['pid'] ) ) ? $_GET['pid'] : false; 
  116.  
  117. /** Load the add/edit page */ 
  118. if ( $pdf_id !== false && rgpost( 'gfpdf_save_pdf' ) ) { 
  119. $this->model->process_submission( $form_id, $pdf_id ); 
  120.  
  121. /** 
  122. * Processes / Setup the form settings page. 
  123. * @since 4.0 
  124. * @return void 
  125. */ 
  126. public function display_page() { 
  127.  
  128. /** Determine whether to load the add/edit page, or the list view */ 
  129. $form_id = ( isset( $_GET['id'] ) ) ? (int) $_GET['id'] : false; 
  130. $pdf_id = ( isset( $_GET['pid'] ) ) ? $_GET['pid'] : false; 
  131.  
  132. /** Load the add/edit page */ 
  133. if ( $pdf_id !== false ) { 
  134. $this->model->show_edit_view( $form_id, $pdf_id ); 
  135.  
  136. return null; 
  137.  
  138. /** process list view */ 
  139. $this->model->process_list_view( $form_id ); 
  140.  
  141. /** 
  142. * Store our TinyMCE init settings for use in our AJAX wp_editor calls 
  143. * @param array $settings The current TinyMCE Settings 
  144. * @return array Original Settings 
  145. * @since 4.0 
  146. */ 
  147. public function store_tinymce_settings( $settings ) { 
  148.  
  149. if ( empty( $this->data->tiny_mce_editor_settings ) ) { 
  150. $this->data->tiny_mce_editor_settings = $settings; 
  151.  
  152. return $settings;