GravityView  2.1.1
The best, easiest way to display Gravity Forms entries on your website.
class-gv-renderer.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * The \GV\Renderer class.
11  *
12  * The base for all renderers.
13  */
14 class Renderer {
15  /**
16  * Initialization.
17  */
18  public function __construct() {
19  if ( ! has_action( 'gravityview/template/after', array( __CLASS__, 'maybe_print_notices' ) ) ) {
20  add_action( 'gravityview/template/after', array( __CLASS__, 'maybe_print_notices' ) );
21  }
22  }
23 
24  /**
25  * Print unconfigured notices to admins.
26  *
27  * @param \GV\Template_Context $gravityview The $gravityview template object.
28  *
29  * @return void
30  */
31  public static function maybe_print_notices( $gravityview = null ) {
32  if ( ! $gravityview instanceof \GV\Template_Context ) {
33  /** Call the legacy code. */
34  \GravityView_frontend::getInstance()->context_not_configured_warning( gravityview_get_view_id() );
35  return;
36  }
37 
38  switch ( true ) {
39  case ( $gravityview->request->is_edit_entry() ):
40  $tab = __( 'Edit Entry', 'gravityview' );
41  $context = 'edit';
42  break;
43  case ( $gravityview->request->is_entry( $gravityview->view->form ? $gravityview->view->form->ID : 0 ) ):
44  $tab = __( 'Single Entry', 'gravityview' );
45  $context = 'single';
46  break;
47  default:
48  $tab = __( 'Multiple Entries', 'gravityview' );
49  $context = 'directory';
50  break;
51  }
52 
53  $cls = $gravityview->template;
54  $slug = property_exists( $cls, '_configuration_slug' ) ? $cls::$_configuration_slug : $cls::$slug;
55  if ( $gravityview->fields->by_position( sprintf( '%s_%s-*', $context, $slug ) )->by_visible()->count() ) {
56  return;
57  }
58 
59  $title = sprintf( esc_html_x( 'The %s layout has not been configured.', 'Displayed when a View is not configured. %s is replaced by the tab label', 'gravityview' ), $tab );
60  $edit_link = admin_url( sprintf( 'post.php?post=%d&action=edit#%s-view', $gravityview->view->ID, $context ) );
61  $action_text = sprintf( esc_html__( 'Add fields to %s', 'gravityview' ), $tab );
62  $message = esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' );
63 
64  $image = sprintf( '<img alt="%s" src="%s" style="margin-top: 10px;" />', $tab, esc_url( plugins_url( sprintf( 'assets/images/tab-%s.png', $context ), GRAVITYVIEW_FILE ) ) );
65  $output = sprintf( '<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url( $edit_link ), $action_text, $message );
66 
67  echo \GVCommon::generate_notice( $output . $image, 'gv-error error', 'edit_gravityview', $gravityview->view->ID );
68  }
69 
70  /**
71  * Warn about legacy template being used.
72  *
73  * Generate a callback that shows which legacy template was at fault.
74  * Used in gravityview_before.
75  *
76  * @param \GV\View $view The view we're looking at.
77  * @param string $path The path of the offending template.
78  *
79  * @return \Callable A closure used in the filter.
80  */
81  public function legacy_template_warning( $view, $path ) {
82  return function() use ( $view, $path ) {
83  // Do not panic for now...
84  };
85  }
86 }
gravityview_get_view_id()
Get the current View ID being rendered.
Definition: class-api.php:1136
$image
Definition: post_image.php:98
legacy_template_warning( $view, $path)
Warn about legacy template being used.
If this file is called directly, abort.
If this file is called directly, abort.
static maybe_print_notices( $gravityview=null)
Print unconfigured notices to admins.
__construct()
Initialization.
const GRAVITYVIEW_FILE
Full path to the GravityView file "GRAVITYVIEW_FILE" "./gravityview.php".
Definition: gravityview.php:31
$title
static getInstance()
Get the one true instantiated self.