| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\MultiFormGoals\ProgressBar; |
| 4 |
|
| 5 |
use Give\MultiFormGoals\ProgressBar\Model as ProgressBar; |
| 6 |
|
| 7 |
class Block { |
| 8 |
|
| 9 |
/** |
| 10 |
* Registers Multi-Form Goals block |
| 11 |
* |
| 12 |
* @since 2.9.0 |
| 13 |
**/ |
| 14 |
public function addBlock() { |
| 15 |
register_block_type( |
| 16 |
'give/progress-bar', |
| 17 |
[ |
| 18 |
'render_callback' => [ $this, 'renderCallback' ], |
| 19 |
'attributes' => [ |
| 20 |
'ids' => [ |
| 21 |
'type' => 'array', |
| 22 |
'default' => [], |
| 23 |
], |
| 24 |
'categories' => [ |
| 25 |
'type' => 'array', |
| 26 |
'default' => [], |
| 27 |
], |
| 28 |
'tags' => [ |
| 29 |
'type' => 'array', |
| 30 |
'default' => [], |
| 31 |
], |
| 32 |
'goal' => [ |
| 33 |
'type' => 'string', |
| 34 |
'default' => '1000', |
| 35 |
], |
| 36 |
'enddate' => [ |
| 37 |
'type' => 'string', |
| 38 |
'default' => '', |
| 39 |
], |
| 40 |
'color' => [ |
| 41 |
'type' => 'string', |
| 42 |
'default' => '#28c77b', |
| 43 |
], |
| 44 |
], |
| 45 |
|
| 46 |
] |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Returns Progress Bar block markup |
| 52 |
* |
| 53 |
* @since 2.9.0 |
| 54 |
**/ |
| 55 |
public function renderCallback( $attributes ) { |
| 56 |
$progressBar = new ProgressBar( |
| 57 |
[ |
| 58 |
'ids' => $attributes['ids'], |
| 59 |
'tags' => $attributes['tags'], |
| 60 |
'categories' => $attributes['categories'], |
| 61 |
'goal' => $attributes['goal'], |
| 62 |
'enddate' => $attributes['enddate'], |
| 63 |
'color' => $attributes['color'], |
| 64 |
] |
| 65 |
); |
| 66 |
return $progressBar->getOutput(); |
| 67 |
} |
| 68 |
|
| 69 |
public function localizeAssets() { |
| 70 |
$defaultColorPalette = [ |
| 71 |
[ |
| 72 |
'name' => __( 'Red', 'give' ), |
| 73 |
'color' => '#dd3333', |
| 74 |
], |
| 75 |
[ |
| 76 |
'name' => __( 'Orange', 'give' ), |
| 77 |
'color' => '#dd9933', |
| 78 |
], |
| 79 |
[ |
| 80 |
'name' => __( 'Green', 'give' ), |
| 81 |
'color' => '#28C77B', |
| 82 |
], |
| 83 |
[ |
| 84 |
'name' => __( 'Blue', 'give' ), |
| 85 |
'color' => '#1e73be', |
| 86 |
], |
| 87 |
[ |
| 88 |
'name' => __( 'Purple', 'give' ), |
| 89 |
'color' => '#8224e3', |
| 90 |
], |
| 91 |
[ |
| 92 |
'name' => __( 'Grey', 'give' ), |
| 93 |
'color' => '#777777', |
| 94 |
], |
| 95 |
]; |
| 96 |
$editorColorPalette = get_theme_support( 'editor-color-palette' ); // Return value is in a nested array. |
| 97 |
wp_localize_script( |
| 98 |
'give-blocks-js', |
| 99 |
'giveProgressBarThemeSupport', |
| 100 |
[ |
| 101 |
'editorColorPalette' => $editorColorPalette ? array_shift( $editorColorPalette ) : $defaultColorPalette, |
| 102 |
] |
| 103 |
); |
| 104 |
} |
| 105 |
} |
| 106 |
|