| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Hooks\Handlers\BlockEditors; |
| 4 |
|
| 5 |
use FluentCart\App\Hooks\Handlers\ShortCodes\CustomerProfileHandler; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class CustomerProfileBlockEditor extends BlockEditor |
| 11 |
{ |
| 12 |
protected static string $editorName = 'customer-profile'; |
| 13 |
|
| 14 |
public function getScripts(): array |
| 15 |
{ |
| 16 |
return [ |
| 17 |
[ |
| 18 |
'source' => 'admin/BlockEditor/CustomerProfile/CustomerProfileBlockEditor.jsx', |
| 19 |
'dependencies' => ['wp-blocks', 'wp-components'] |
| 20 |
] |
| 21 |
]; |
| 22 |
} |
| 23 |
|
| 24 |
public function getStyles(): array |
| 25 |
{ |
| 26 |
return ['admin/BlockEditor/CustomerProfile/style/customer-profile-block-editor.scss']; |
| 27 |
} |
| 28 |
|
| 29 |
public function localizeData(): array |
| 30 |
{ |
| 31 |
return [ |
| 32 |
$this->getLocalizationKey() => [ |
| 33 |
'slug' => $this->slugPrefix, |
| 34 |
'name' => static::getEditorName(), |
| 35 |
'title' => __('Customer Dashboard', 'fluent-cart'), |
| 36 |
] |
| 37 |
]; |
| 38 |
} |
| 39 |
|
| 40 |
public function render(array $shortCodeAttribute, $block = null): string |
| 41 |
{ |
| 42 |
$defaultsTitles = [ |
| 43 |
'purchaseHistory' => __('Purchase History', 'fluent-cart'), |
| 44 |
'subscriptions' => __('Subscriptions', 'fluent-cart'), |
| 45 |
'licenses' => __('Licenses', 'fluent-cart'), |
| 46 |
'downloads' => __('Downloads', 'fluent-cart') |
| 47 |
]; |
| 48 |
|
| 49 |
$sectionTitles = Arr::get($shortCodeAttribute, 'sectionTitles', $defaultsTitles); |
| 50 |
$jsonTitles = wp_json_encode($sectionTitles); |
| 51 |
$colors = Arr::get($shortCodeAttribute, 'colors', []); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
$colorStrings = []; |
| 56 |
// Iterate over each color group (e.g., generalColors) |
| 57 |
foreach ($colors as $colorGroup) { |
| 58 |
// Iterate over each color within the color group |
| 59 |
foreach ($colorGroup as $key => $color) { |
| 60 |
$value = $color['value']; |
| 61 |
|
| 62 |
if (is_array($value)) { |
| 63 |
// Convert box values (like padding/margin) to CSS shorthand string |
| 64 |
$top = $value['top'] ?? '0'; |
| 65 |
$right = $value['right'] ?? '0'; |
| 66 |
$bottom = $value['bottom'] ?? '0'; |
| 67 |
$left = $value['left'] ?? '0'; |
| 68 |
$value = trim("$top $right $bottom $left"); |
| 69 |
} |
| 70 |
// Append each color key and its value to the $colorStrings array |
| 71 |
$colorStrings[] = $key . '=' . $value; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
$allColorStrings = implode(', ', $colorStrings); |
| 76 |
|
| 77 |
return "[" . CustomerProfileHandler::SHORT_CODE . |
| 78 |
" section_titles='{$jsonTitles}'" . |
| 79 |
" colors='{$allColorStrings}'" . |
| 80 |
" ]"; |
| 81 |
} |
| 82 |
} |
| 83 |
|