← All changes
|
includes/Frontend/Form/View/Theme/Fields/TitleField.php
+67
-32
2.0
→
V3.3.2
View file →
| @@ -3,39 +3,64 @@ | ||
| 3 | 3 | namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields; |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Core\Util\FieldValueHandler; |
| 6 | 6 | |
| 7 | -class TitleField { | |
| 8 | - public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) { | |
| 7 | +class TitleField | |
| 8 | +{ | |
| 9 | + public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) | |
| 10 | + { | |
| 9 | 11 | return self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value); |
| 10 | 12 | } |
| 11 | 13 | |
| 12 | - private static function titleGenerator($tag, $text, $cls, $preIcn, $sufIcn, $fk, $field, $form_atomic_Cls_map) { | |
| 14 | + private static function titleGenerator($tag, $text, $cls, $preIcn, $sufIcn, $fk, $field, $form_atomic_Cls_map) | |
| 15 | + { | |
| 13 | 16 | $text = FieldValueHandler::replaceSmartTagWithValue($text); |
| 14 | - $fieldHelpers = new FieldHelpers($field, $fk, $form_atomic_Cls_map); | |
| 17 | + $fieldHelpers = new ClassicFieldHelpers($field, $fk, $form_atomic_Cls_map); | |
| 15 | 18 | |
| 16 | - return <<<TITLEGENERATOR | |
| 17 | - <{$tag} class="{$fieldHelpers->getAtomicCls($cls)} {$fieldHelpers->getCustomClasses($cls)}"> | |
| 18 | - {$preIcn} | |
| 19 | - {$text} | |
| 20 | - {$sufIcn} | |
| 21 | - </{$tag}> | |
| 22 | -TITLEGENERATOR; | |
| 19 | + $allowedTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'div']; | |
| 20 | + $tag = is_string($tag) ? strtolower($tag) : ''; | |
| 21 | + if (!in_array($tag, $allowedTags, true)) { | |
| 22 | + $tag = 'h2'; | |
| 23 | + } | |
| 24 | + | |
| 25 | + // the title is a flex container, so loose text and inline tags would each become a flex | |
| 26 | + // item and lose the spaces between them; one span keeps the text a single flex item | |
| 27 | + return sprintf( | |
| 28 | + ' <%1$s class="%2$s %3$s"> | |
| 29 | + %4$s | |
| 30 | + <span class="%7$s">%5$s</span> | |
| 31 | + %6$s | |
| 32 | + </%1$s>', | |
| 33 | + $tag, | |
| 34 | + $fieldHelpers->getAtomicCls($cls), | |
| 35 | + $fieldHelpers->getCustomClasses($cls), | |
| 36 | + $preIcn, | |
| 37 | + $fieldHelpers->kses_post($text), | |
| 38 | + $sufIcn, | |
| 39 | + $fieldHelpers->getAtomicCls("{$cls}-txt") | |
| 40 | + ); | |
| 23 | 41 | } |
| 24 | 42 | |
| 25 | - private static function iconImg($field, $object, $element, $fieldHelpers, $alt, $fk) { | |
| 26 | - return <<<ICONIMG | |
| 27 | - <img | |
| 28 | - {$fieldHelpers->getCustomAttributes($element)} | |
| 29 | - class="{$fieldHelpers->getAtomicCls($element)} {$fieldHelpers->getCustomClasses($element)}" | |
| 30 | - src="{$field->$object}" | |
| 31 | - alt="{$alt}" | |
| 32 | - /> | |
| 33 | -ICONIMG; | |
| 43 | + private static function iconImg($field, $object, $element, $fieldHelpers, $alt, $fk) | |
| 44 | + { | |
| 45 | + return sprintf( | |
| 46 | + '<img | |
| 47 | + %1$s | |
| 48 | + class="%2$s %3$s" | |
| 49 | + src="%4$s" | |
| 50 | + alt="%5$s" | |
| 51 | + />', | |
| 52 | + $fieldHelpers->getCustomAttributes($element), | |
| 53 | + $fieldHelpers->getAtomicCls($element), | |
| 54 | + $fieldHelpers->getCustomClasses($element), | |
| 55 | + $fieldHelpers->esc_url($field->$object), | |
| 56 | + $fieldHelpers->esc_attr($alt) | |
| 57 | + ); | |
| 34 | 58 | } |
| 35 | 59 | |
| 36 | - private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) { | |
| 37 | - $fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 60 | + private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) | |
| 61 | + { | |
| 62 | + $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map); | |
| 38 | 63 | |
| 39 | 64 | $logo = $fieldHelpers->icon('logo', 'logo'); |
| 40 | 65 | $titleHide = ''; |
| 41 | 66 | $subtitleHide = ''; |
| @@ -68,20 +93,30 @@ | ||
| 68 | 93 | if (property_exists($field, 'subtitleHide') && !$field->subtitleHide) { |
| 69 | 94 | $subtitleHide = self::titleGenerator($field->subTitleTag, $field->subtitle, 'sub-titl', $subTitlPreIcn, $subTitlSufIcn, $rowID, $field, $form_atomic_Cls_map); |
| 70 | 95 | } |
| 71 | 96 | |
| 72 | - return <<<TITLEFIELD | |
| 73 | - <div class="{$fieldHelpers->getAtomicCls('fld-wrp')} {$fieldHelpers->getCustomClasses('fld-wrp')}" | |
| 74 | - {$fieldHelpers->getCustomAttributes('fld-wrp')} | |
| 97 | + return sprintf( | |
| 98 | + '<div | |
| 99 | + %1$s | |
| 100 | + class="%2$s %3$s" | |
| 75 | 101 | > |
| 76 | - {$logo} | |
| 102 | + %4$s | |
| 77 | 103 | <div |
| 78 | - class="{$fieldHelpers->getAtomicCls('titl-wrp')} {$fieldHelpers->getCustomClasses('titl-wrp')}" | |
| 79 | - {$fieldHelpers->getCustomAttributes('titl-wrp')} | |
| 104 | + %5$s | |
| 105 | + class="%6$s %7$s" | |
| 80 | 106 | > |
| 81 | - {$titleHide} | |
| 82 | - {$subtitleHide} | |
| 107 | + %8$s | |
| 108 | + %9$s | |
| 83 | 109 | </div> |
| 84 | - </div> | |
| 85 | -TITLEFIELD; | |
| 110 | + </div>', | |
| 111 | + $fieldHelpers->getCustomAttributes('fld-wrp'), | |
| 112 | + $fieldHelpers->getAtomicCls('fld-wrp'), | |
| 113 | + $fieldHelpers->getCustomClasses('fld-wrp'), | |
| 114 | + $logo, | |
| 115 | + $fieldHelpers->getCustomAttributes('titl-wrp'), | |
| 116 | + $fieldHelpers->getAtomicCls('titl-wrp'), | |
| 117 | + $fieldHelpers->getCustomClasses('titl-wrp'), | |
| 118 | + $titleHide, | |
| 119 | + $subtitleHide | |
| 120 | + ); | |
| 86 | 121 | } |
| 87 | 122 | } |