| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Editors\BlockEditor\Blocks; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Editors\BlockEditor\Block; |
| 6 |
|
| 7 |
use function cli\err; |
| 8 |
|
| 9 |
class Reactions extends Block { |
| 10 |
|
| 11 |
protected $editor_scripts = [ |
| 12 |
'betterdocs-reactions' |
| 13 |
]; |
| 14 |
|
| 15 |
protected $editor_styles = [ |
| 16 |
'betterdocs-reactions' |
| 17 |
]; |
| 18 |
|
| 19 |
protected $frontend_scripts = [ |
| 20 |
'betterdocs-reactions' |
| 21 |
]; |
| 22 |
protected $frontend_styles = [ |
| 23 |
'betterdocs-reactions' |
| 24 |
]; |
| 25 |
|
| 26 |
public function get_name() { |
| 27 |
return 'reactions'; |
| 28 |
} |
| 29 |
|
| 30 |
public function get_default_attributes() { |
| 31 |
return [ |
| 32 |
'blockId' => 'layout-1', |
| 33 |
'reaction_text' => __( 'What are your feelings', 'betterdocs' ), |
| 34 |
'reaction_text_tag' => 'h4', |
| 35 |
'layout' => 'layout-1', |
| 36 |
'show_happy_icon' => true, |
| 37 |
'happy_icon_url' => '', |
| 38 |
'show_neutral_icon' => true, |
| 39 |
'neutral_icon_url' => '', |
| 40 |
'show_sad_icon' => true, |
| 41 |
'sad_icon_url' => '' |
| 42 |
]; |
| 43 |
} |
| 44 |
|
| 45 |
public function render( $attributes, $content ) { |
| 46 |
$layout = $attributes['layout']; |
| 47 |
if ( $layout == 'layout-1' ) { |
| 48 |
$this->views( 'widgets/reactions' ); |
| 49 |
} elseif ( $layout == 'layout-2' ) { |
| 50 |
$this->views( 'widgets/reactions-2' ); |
| 51 |
} else { |
| 52 |
$this->views( 'widgets/reactions-3' ); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
public function view_params() { |
| 57 |
$wrapper_class = [ |
| 58 |
'class' => [] |
| 59 |
]; |
| 60 |
|
| 61 |
$default_params = [ |
| 62 |
'reactions_text' => $this->attributes['reaction_text'], |
| 63 |
'text_tag' => $this->attributes['reaction_text_tag'], |
| 64 |
'wrapper_attr' => &$wrapper_class |
| 65 |
]; |
| 66 |
|
| 67 |
if ( $this->attributes['layout'] == 'layout-1' ) { |
| 68 |
$wrapper_class['class'][] = 'betterdocs-article-reactions'; |
| 69 |
$default_params['happy'] = $this->attributes['show_happy_icon']; |
| 70 |
$default_params['happy_icon'] = $this->attributes['happy_icon_url']; |
| 71 |
$default_params['normal'] = $this->attributes['show_neutral_icon']; |
| 72 |
$default_params['normal_icon'] = $this->attributes['neutral_icon_url']; |
| 73 |
$default_params['sad'] = $this->attributes['show_sad_icon']; |
| 74 |
$default_params['sad_icon'] = $this->attributes['sad_icon_url']; |
| 75 |
} |
| 76 |
|
| 77 |
if ( $this->attributes['layout'] == 'layout-2' ) { |
| 78 |
$default_params['happy'] = $this->attributes['show_happy_icon']; |
| 79 |
$default_params['happy_icon'] = $this->attributes['happy_icon_url']; |
| 80 |
$default_params['normal'] = $this->attributes['show_neutral_icon']; |
| 81 |
$default_params['normal_icon'] = $this->attributes['neutral_icon_url']; |
| 82 |
$default_params['sad'] = $this->attributes['show_sad_icon']; |
| 83 |
$default_params['sad_icon'] = $this->attributes['sad_icon_url']; |
| 84 |
} |
| 85 |
|
| 86 |
if ( $this->attributes['layout'] == 'layout-3' ) { |
| 87 |
$default_params['happy'] = $this->attributes['show_happy_icon']; |
| 88 |
$default_params['happy_icon'] = $this->attributes['happy_icon_url']; |
| 89 |
$default_params['normal'] = $this->attributes['show_neutral_icon']; |
| 90 |
$default_params['normal_icon'] = $this->attributes['neutral_icon_url']; |
| 91 |
$default_params['sad'] = $this->attributes['show_sad_icon']; |
| 92 |
$default_params['sad_icon'] = $this->attributes['sad_icon_url']; |
| 93 |
$wrapper_class['class'][] = 'betterdocs-article-reactions-blocks'; |
| 94 |
} |
| 95 |
|
| 96 |
return $default_params; |
| 97 |
} |
| 98 |
} |
| 99 |
|