index.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Blocks; |
| 4 | |
| 5 | use Kubio\Core\Blocks\BlockBase; |
| 6 | use Kubio\Core\Registry; |
| 7 | |
| 8 | class SearchForm extends BlockBase { |
| 9 | |
| 10 | const OUTER = 'outer'; |
| 11 | const FORM = 'form'; |
| 12 | const INPUT = 'input'; |
| 13 | const BUTTON = 'button'; |
| 14 | const ICON = 'icon'; |
| 15 | const BUTTONTEXT = 'buttonText'; |
| 16 | |
| 17 | public function computed() { |
| 18 | $computedProps = array( |
| 19 | 'showInput' => true, |
| 20 | 'showButton' => 'inputAndButton' === $this->getProp( 'layout' ), |
| 21 | 'showButtonIcon' => 'icon' === $this->getProp( 'buttonType' ), |
| 22 | 'showButtonText' => 'text' === $this->getProp( 'buttonType' ), |
| 23 | 'iconButton' => $this->getAttribute( 'iconName' ), |
| 24 | ); |
| 25 | |
| 26 | return $computedProps; |
| 27 | } |
| 28 | public function mapPropsToElements() { |
| 29 | $inputPlaceholder = kubio_wpml_get_translated_string( $this->getAttribute( 'placeholderText' ) ); |
| 30 | $buttonText = kubio_wpml_get_translated_string( $this->getProp( 'buttonText' ) ); |
| 31 | $button = array( 'className' => array( 'search-button' ) ); |
| 32 | $iconButton = $this->getAttribute( 'iconName' ); |
| 33 | |
| 34 | return array( |
| 35 | self::FORM => array( |
| 36 | 'className' => array( 'd-flex', 'search-form' ), |
| 37 | 'action' => esc_url( home_url() ), |
| 38 | 'role' => 'search', |
| 39 | 'method' => 'GET', |
| 40 | ), |
| 41 | self::BUTTON => $button, |
| 42 | self::INPUT => array( |
| 43 | 'className' => array( 'search-input' ), |
| 44 | 'placeholder' => esc_attr( $inputPlaceholder ), |
| 45 | 'value' => esc_attr( get_search_query() ), |
| 46 | 'name' => 's', |
| 47 | ), |
| 48 | self::ICON => array( |
| 49 | 'name' => $iconButton, |
| 50 | ), |
| 51 | self::BUTTONTEXT => array( |
| 52 | 'innerHTML' => wp_kses_post( $buttonText ), |
| 53 | ), |
| 54 | ); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | |
| 59 | Registry::registerBlock( |
| 60 | __DIR__, |
| 61 | SearchForm::class |
| 62 | ); |
| 63 |