77
88namespace Cloudinary \UI \Component ;
99
10+ use Cloudinary \Settings \Setting ;
1011use Cloudinary \Utils ;
1112use function Cloudinary \get_plugin_instance ;
1213
@@ -33,7 +34,7 @@ class Crops extends Select {
3334 *
3435 * @var string
3536 */
36- protected $ blueprint = 'wrap|label|title|/title |prefix/|/label|input/|/wrap ' ;
37+ protected $ blueprint = 'wrap|hr/| label|title/ |prefix/|/label|info_box/ |input/|/wrap ' ;
3738
3839 /**
3940 * Enqueue scripts this component may use.
@@ -42,6 +43,51 @@ public function enqueue_scripts() {
4243 wp_enqueue_media ();
4344 }
4445
46+ /**
47+ * Filter the hr structure.
48+ *
49+ * @param array $struct The array structure.
50+ *
51+ * @return array
52+ */
53+ protected function hr ( $ struct ) {
54+
55+ if ( 'image_settings ' === $ this ->setting ->get_parent ()->get_slug () ) {
56+ $ struct ['element ' ] = 'hr ' ;
57+ $ struct ['render ' ] = true ;
58+ }
59+
60+ return $ struct ;
61+ }
62+
63+ /**
64+ * Filter the info box structure.
65+ *
66+ * @param array $struct The array structure.
67+ *
68+ * @return array
69+ */
70+ protected function info_box ( $ struct ) {
71+ $ panel_toggle = new Setting ( 'info_box_crop_gravity ' );
72+ $ panel_toggle ->set_param ( 'title ' , __ ( 'What is Crop and Gravity control? ' , 'cloudinary ' ) );
73+ $ panel_toggle ->set_param (
74+ 'text ' ,
75+ sprintf (
76+ // translators: %1$s: link to Crop doc, %2$s: link to Gravity doc.
77+ __ ( 'This feature allows you to fine tune the behaviour of the %1$s and %2$s per registered crop size of the delivered images. ' , 'cloudinary ' ),
78+ '<a href="https://cloudinary.com/documentation/resizing_and_cropping#resize_and_crop_modes" target="_blank"> ' . __ ( 'Crop ' , 'cloudinary ' ) . '</a> ' ,
79+ '<a href="https://cloudinary.com/documentation/resizing_and_cropping#control_gravity" target="_blank"> ' . __ ( 'Gravity ' , 'cloudinary ' ) . '</a> '
80+ )
81+ );
82+ $ panel_toggle ->set_param ( 'icon ' , get_plugin_instance ()->dir_url . 'css/images/crop.svg ' );
83+ $ title_toggle = new Info_Box ( $ panel_toggle );
84+
85+ $ struct ['element ' ] = 'div ' ;
86+ $ struct ['content ' ] = $ title_toggle ->render ();
87+
88+ return $ struct ;
89+ }
90+
4591 /**
4692 * Filter the select input parts structure.
4793 *
@@ -169,9 +215,14 @@ protected function make_input( $name, $value ) {
169215 'crop-size-inputs ' ,
170216 );
171217
218+ $ label = $ this ->get_part ( 'label ' );
219+ $ label ['attributes ' ]['for ' ] = $ name ;
220+ $ label ['content ' ] = __ ( 'Disable ' , 'cloudinary ' );
221+
172222 $ check = $ this ->get_part ( 'input ' );
173223 $ check ['attributes ' ]['type ' ] = 'checkbox ' ;
174224 $ check ['attributes ' ]['name ' ] = $ name ;
225+ $ check ['attributes ' ]['id ' ] = $ name ;
175226 $ check ['attributes ' ]['value ' ] = '-- ' ;
176227 $ check ['attributes ' ]['class ' ][] = 'disable-toggle ' ;
177228 $ check ['attributes ' ]['title ' ] = __ ( 'Disable gravity and crops ' , 'cloudinary ' );
@@ -186,6 +237,7 @@ protected function make_input( $name, $value ) {
186237 $ input ['attributes ' ]['class ' ][] = 'regular-text ' ;
187238
188239 $ wrapper ['children ' ]['input ' ] = $ input ;
240+ $ wrapper ['children ' ]['label ' ] = $ label ;
189241 $ wrapper ['children ' ]['check ' ] = $ check ;
190242
191243 return $ wrapper ;
0 commit comments