| 1 |
<?php |
| 2 |
/** |
| 3 |
* Facet Search widget. |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace King_Addons; |
| 9 |
|
| 10 |
use Elementor\Controls_Manager; |
| 11 |
use Elementor\Widget_Base; |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Search filter widget. |
| 19 |
*/ |
| 20 |
class Facet_Search extends Widget_Base |
| 21 |
{ |
| 22 |
/** |
| 23 |
* Widget slug. |
| 24 |
* |
| 25 |
* @return string |
| 26 |
*/ |
| 27 |
public function get_name(): string |
| 28 |
{ |
| 29 |
return 'king-addons-facet-search'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Widget title. |
| 34 |
* |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
public function get_title(): string |
| 38 |
{ |
| 39 |
return esc_html__('Facet Search', 'king-addons'); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Widget icon. |
| 44 |
* |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
public function get_icon(): string |
| 48 |
{ |
| 49 |
return 'eicon-search'; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Categories. |
| 54 |
* |
| 55 |
* @return array<int, string> |
| 56 |
*/ |
| 57 |
public function get_categories(): array |
| 58 |
{ |
| 59 |
return ['king-addons']; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Style dependencies. |
| 64 |
* |
| 65 |
* @return array<int, string> |
| 66 |
*/ |
| 67 |
public function get_style_depends(): array |
| 68 |
{ |
| 69 |
return [ |
| 70 |
KING_ADDONS_ASSETS_UNIQUE_KEY . '-facet-search-style', |
| 71 |
]; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Script dependencies. |
| 76 |
* |
| 77 |
* @return array<int, string> |
| 78 |
*/ |
| 79 |
public function get_script_depends(): array |
| 80 |
{ |
| 81 |
return [ |
| 82 |
KING_ADDONS_ASSETS_UNIQUE_KEY . '-facet-search-script', |
| 83 |
]; |
| 84 |
} |
| 85 |
|
| 86 |
public function get_custom_help_url() |
| 87 |
{ |
| 88 |
return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue'; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Register controls. |
| 93 |
* |
| 94 |
* @return void |
| 95 |
*/ |
| 96 |
public function register_controls(): void |
| 97 |
{ |
| 98 |
$this->start_controls_section( |
| 99 |
'kng_facet_search_section', |
| 100 |
[ |
| 101 |
'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Facet Search', 'king-addons'), |
| 102 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 103 |
] |
| 104 |
); |
| 105 |
|
| 106 |
$this->add_control( |
| 107 |
'kng_filters_query_id', |
| 108 |
[ |
| 109 |
'label' => esc_html__('Filter Query ID', 'king-addons'), |
| 110 |
'type' => Controls_Manager::TEXT, |
| 111 |
'placeholder' => esc_html__('shop_grid_1', 'king-addons'), |
| 112 |
] |
| 113 |
); |
| 114 |
|
| 115 |
$this->add_control( |
| 116 |
'kng_placeholder', |
| 117 |
[ |
| 118 |
'label' => esc_html__('Placeholder', 'king-addons'), |
| 119 |
'type' => Controls_Manager::TEXT, |
| 120 |
'default' => esc_html__('Search...', 'king-addons'), |
| 121 |
] |
| 122 |
); |
| 123 |
|
| 124 |
$this->end_controls_section(); |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Render widget output. |
| 129 |
* |
| 130 |
* @return void |
| 131 |
*/ |
| 132 |
public function render(): void |
| 133 |
{ |
| 134 |
$settings = $this->get_settings_for_display(); |
| 135 |
$query_id = sanitize_title($settings['kng_filters_query_id'] ?? ''); |
| 136 |
$placeholder = $settings['kng_placeholder'] ?? ''; |
| 137 |
|
| 138 |
if ('' === $query_id) { |
| 139 |
return; |
| 140 |
} |
| 141 |
|
| 142 |
?> |
| 143 |
<div class="king-addons-facet king-addons-facet--search"> |
| 144 |
<input |
| 145 |
type="search" |
| 146 |
class="king-addons-facet__input" |
| 147 |
data-ka-filter-type="search" |
| 148 |
data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>" |
| 149 |
placeholder="<?php echo esc_attr($placeholder); ?>" |
| 150 |
/> |
| 151 |
</div> |
| 152 |
<?php |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|