From 9a6f4e29ba378ba8f791f45e96f2812e47d85dc4 Mon Sep 17 00:00:00 2001 From: Jonathan Gruber Date: Sun, 12 Jun 2016 20:05:30 +0200 Subject: [PATCH 1/2] Added WP editor as new form element --- core/helpers/mvc_form_helper.php | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/core/helpers/mvc_form_helper.php b/core/helpers/mvc_form_helper.php index 50a7a62..db2e51d 100644 --- a/core/helpers/mvc_form_helper.php +++ b/core/helpers/mvc_form_helper.php @@ -144,6 +144,45 @@ public function password_input($field_name, $options=array()) { $html .= $this->after_input($field_name, $options); return $html; } + + public function editor($field_name, array $options = []) { + $id = $this->input_id($field_name); + + $defaults = array( + 'id' => $id, + 'name' => $this->input_name($field_name), + 'label' => MvcInflector::titleize($field_name), + 'content' => empty($this->object->$field_name) ? '' : $this->object->$field_name, + 'rows' => 10, + 'editor_css' => '', + 'media_buttons' => true, + 'minimal' => false, + 'statusbar' => true, + 'quicktags' => true + ); + $options = array_merge($defaults, $options); + + ob_start(); + + if ($options['label']) + echo ''; + + wp_editor($options['content'], $id, [ + 'editor_class' => $options['required'], + 'media_buttons' => $options['media_buttons'], + 'textarea_name' => $options['name'], + 'textarea_rows' => $options['rows'], + 'teeny' => $options['minimal'], + 'tinymce' => [ + 'statusbar' => $options['statusbar'] + ], + 'editor_css' => $options['editor_css'], + 'quicktags' => $options['quicktags'], + 'wpautop' => false + ]); + + return ob_get_clean(); + } public function select($field_name, $options=array()) { $html = $this->before_input($field_name, $options); From 76d0d1c4192a72e26f449a0ad9758147d8a9a16f Mon Sep 17 00:00:00 2001 From: Jonathan Gruber Date: Sun, 12 Jun 2016 23:02:32 +0200 Subject: [PATCH 2/2] Switched to traditional array syntax --- core/helpers/mvc_form_helper.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/helpers/mvc_form_helper.php b/core/helpers/mvc_form_helper.php index db2e51d..476034f 100644 --- a/core/helpers/mvc_form_helper.php +++ b/core/helpers/mvc_form_helper.php @@ -145,7 +145,7 @@ public function password_input($field_name, $options=array()) { return $html; } - public function editor($field_name, array $options = []) { + public function editor($field_name, array $options = array()) { $id = $this->input_id($field_name); $defaults = array( @@ -164,22 +164,22 @@ public function editor($field_name, array $options = []) { ob_start(); - if ($options['label']) + if (!empty($options['label'])) echo ''; - wp_editor($options['content'], $id, [ + wp_editor($options['content'], $id, array( 'editor_class' => $options['required'], 'media_buttons' => $options['media_buttons'], 'textarea_name' => $options['name'], 'textarea_rows' => $options['rows'], 'teeny' => $options['minimal'], - 'tinymce' => [ + 'tinymce' => array( 'statusbar' => $options['statusbar'] - ], + ), 'editor_css' => $options['editor_css'], 'quicktags' => $options['quicktags'], 'wpautop' => false - ]); + )); return ob_get_clean(); }