index.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Blocks; |
| 4 | |
| 5 | use Kubio\Core\Blocks\BlockBase; |
| 6 | use Kubio\Core\Registry; |
| 7 | use Kubio\Core\Utils; |
| 8 | |
| 9 | class ContactFormBlock extends BlockBase { |
| 10 | |
| 11 | const FORM_CONTAINER = 'formContainer'; |
| 12 | const FORM_WRAPPER = 'formWrapper'; |
| 13 | const PLACEHOLDER = 'placeholder'; |
| 14 | |
| 15 | |
| 16 | public function computed() { |
| 17 | $shortcode = $this->getAttribute( 'shortcode' ); |
| 18 | return array( |
| 19 | 'disableStyleClasses' => $this->getAttribute( 'useShortcodeStyle', false ), |
| 20 | 'renderContainer' => ! ! $shortcode, |
| 21 | 'renderPlaceholder' => ! $shortcode, |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | public function getShortcodeAttributes() { |
| 26 | return array( |
| 27 | 'shortcode' => wp_kses_post( $this->getAttribute( 'shortcode' ) ), |
| 28 | 'use_shortcode_style' => $this->getAttribute( 'useShortcodeStyle' ) ? 1 : 0, |
| 29 | |
| 30 | 'decode_data' => 0, |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | public function mapPropsToElements() { |
| 36 | $shortcode = $this->getAttribute( 'shortcode' ); |
| 37 | $content = null; |
| 38 | $placeholder = null; |
| 39 | if ( $shortcode ) { |
| 40 | $content = kubio_contact_form_shortcode( $this->getShortcodeAttributes() ); |
| 41 | } else { |
| 42 | $placeholder = Utils::getEmptyShortcodePlaceholder(); |
| 43 | } |
| 44 | |
| 45 | $containerClasses = array(); |
| 46 | $useShortcodeStyle = $this->getAttribute( 'useShortcodeStyle', false ); |
| 47 | if ( $useShortcodeStyle ) { |
| 48 | $containerClasses[] = 'kubio-no-style'; |
| 49 | } else { |
| 50 | $containerClasses[] = 'kubio-use-style'; |
| 51 | } |
| 52 | return array( |
| 53 | self::FORM_CONTAINER => array( |
| 54 | 'innerHTML' => $content, |
| 55 | 'className' => $containerClasses, |
| 56 | 'useShortcodeStyle' => esc_attr( $useShortcodeStyle ), |
| 57 | |
| 58 | ), |
| 59 | self::FORM_WRAPPER => array( |
| 60 | 'useShortcodeStyle' => esc_attr( $useShortcodeStyle ), |
| 61 | ), |
| 62 | self::PLACEHOLDER => array( |
| 63 | 'innerHTML' => $placeholder, |
| 64 | ), |
| 65 | ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | Registry::registerBlock( |
| 70 | __DIR__, |
| 71 | ContactFormBlock::class |
| 72 | ); |
| 73 |