PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / tribe-common / src / Tribe / Tooltip / View.php
pods / tribe-common / src / Tribe / Tooltip Last commit date
View.php 2 weeks ago
View.php
139 lines
1 <?php
2
3 namespace Tribe\Tooltip;
4
5 /**
6 * Class View
7 *
8 * @since 4.9.8
9 */
10 class View extends \Tribe__Template {
11
12 /**
13 * Where in the themes we will look for templates
14 *
15 * @since 4.10.2
16 *
17 * @var string
18 */
19 public $template_namespace = 'tooltips';
20
21 /**
22 * View constructor.
23 *
24 * @since 4.9.8
25 */
26 public function __construct() {
27 $this->set_template_origin( \Tribe__Main::instance() );
28 $this->set_template_folder( 'src/views/tooltip' );
29
30 // Configures this templating class to extract variables
31 $this->set_template_context_extract( true );
32
33 // Uses the public folders
34 $this->set_template_folder_lookup( true );
35 }
36
37 /**
38 * Public wrapper for build method
39 *
40 * @since 4.9.8
41 *
42 * @param array|string $message Array of messages or single message as string.
43 * @param array $args {
44 * List of arguments to override tooltip template.
45 *
46 * @var array $context Any additional context data you need to expose to this file (optional).
47 * @var string $classes Additional classes for the icon span (optional).
48 * @var string $direction Direction the tooltip should be from the trigger (down).
49 * @var string $icon dashicon classname to use, without the `dashicon-` (info).
50 * @var string $wrap_classes Classes for the tooltip wrapper (optional).
51 * }
52 * @return string A string of html for the tooltip.
53 */
54 public function render_tooltip( $message, $args = [] ) {
55 if ( empty( $message ) ) {
56 return;
57 }
58
59 /** @var \Tribe__Assets $assets */
60 $assets = tribe( 'assets' );
61 $assets->enqueue_group( 'tribe-tooltip' );
62
63 $html = $this->build_tooltip( $message, $args );
64
65 return $html;
66 }
67
68 /**
69 * Factory method for tooltip HTML
70 *
71 * @since 4.9.8
72 *
73 * @param array|string $message array of messages or single message as string.
74 * @param array $args {
75 * List of arguments to override tooltip template.
76 *
77 * @var array $context Any additional context data you need to expose to this file (optional).
78 * @var string $classes Additional classes for the icon span (optional).
79 * @var string $direction Direction the tooltip should be from the trigger (down).
80 * @var string $icon dashicon classname to use, without the `dashicon-` (info).
81 * @var string $wrap_classes Classes for the tooltip wrapper (optional).
82 * }
83 * @return string A string of html for the tooltip.
84 */
85 private function build_tooltip( $message, $original_args ) {
86 $default_args = [
87 'classes' => '',
88 'context' => '',
89 'direction' => 'down',
90 'icon' => 'info',
91 'wrap_classes' => '',
92 ];
93
94 $args = wp_parse_args( $original_args, $default_args );
95
96 // Check for message to be passed.
97 if ( empty( $message ) ) {
98 return '';
99 }
100
101 // Setup message as an array of messages
102 $messages = (array) $message;
103
104 $args['messages'] = $messages;
105
106 ob_start();
107
108 /**
109 * Allow us to filter the tooltip template
110 *
111 * @since 4.9.8
112 *
113 * @param string $template The tooltip template name.
114 * @param array $args Extra arguments, defaults include icon, classes, direction, and context.
115 */
116 $template_name = apply_filters( 'tribe_tooltip_template', 'tooltip', $args );
117
118 $template = $this->template( $template_name, $args, false );
119
120 if ( ! empty( $template ) ) {
121 echo $template;
122 }
123
124 $html = ob_get_clean();
125
126 /**
127 * Allow us to filter the tooltip output
128 *
129 * @since 4.9.8
130 *
131 * @param string $html The tooltip HTML.
132 * @param array $messages An array of message strings.
133 * @param array $args Extra arguments, defaults include icon, classes, direction, and context.
134 */
135 return apply_filters( 'tribe_tooltip_html', $html, $messages, $args );
136 }
137
138 }
139