1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\Gutenberg\Blocks; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract; |
6
|
|
|
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewShortcode; |
7
|
|
|
|
8
|
|
|
class SiteReviewBlock extends Block |
9
|
|
|
{ |
10
|
|
|
public function render(array $attributes): string |
11
|
|
|
{ |
12
|
|
|
if ('edit' === filter_input(INPUT_GET, 'context')) { |
13
|
|
|
if (empty(wp_count_posts(glsr()->post_type)->publish)) { |
14
|
|
|
return $this->buildEmptyBlock( |
15
|
|
|
_x('No reviews found.', 'admin-text', 'site-reviews') |
16
|
|
|
); |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
return parent::render($attributes); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function shortcode(): ShortcodeContract |
23
|
|
|
{ |
24
|
|
|
return glsr(SiteReviewShortcode::class); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function blockClassAttr(array $attributes): string |
28
|
|
|
{ |
29
|
|
|
$attr = []; |
30
|
|
|
if (!empty($attributes['styleRatingColor']) || !empty($attributes['styleRatingColorCustom'])) { |
31
|
|
|
$attr[] = 'has-custom-rating-color'; |
32
|
|
|
} |
33
|
|
|
return implode(' ', $attr); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function blockStyleAttr(array $attributes): string |
37
|
|
|
{ |
38
|
|
|
$attr = []; |
39
|
|
|
if (!empty($attributes['styleRatingColor'])) { |
40
|
|
|
$attr[] = "--glsr-review-star-bg: var(--wp--preset--color--{$attributes['styleRatingColor']});"; |
41
|
|
|
} elseif (!empty($attributes['styleRatingColorCustom'])) { |
42
|
|
|
$attr[] = "--glsr-review-star-bg: {$attributes['styleRatingColorCustom']};"; |
43
|
|
|
} |
44
|
|
|
if (!empty($attributes['styleStarSize'])) { |
45
|
|
|
$attr[] = "--glsr-review-star: {$attributes['styleStarSize']};"; |
46
|
|
|
} |
47
|
|
|
return implode('', $attr); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|