AppsService.php
3 days ago
CollaborationCommentService.php
3 weeks ago
CollaborationService.php
3 weeks ago
CollectionItemService.php
3 weeks ago
CollectionService.php
3 weeks ago
EditorService.php
3 weeks ago
FontService.php
3 days ago
GlobalDataService.php
3 days ago
MediaService.php
3 weeks ago
PageService.php
3 days ago
PageSettingsService.php
3 weeks ago
UtilityPageService.php
3 days ago
GlobalDataService.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kirki\App\Services; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | use Kirki\App\Constants\CollaborationConnectionType; |
| 8 | use Kirki\App\Constants\CollaborationParent; |
| 9 | use Kirki\App\DTO\Collaboration\CreateCollaborationDTO; |
| 10 | use Kirki\App\Supports\Facades\GlobalData; |
| 11 | |
| 12 | class GlobalDataService |
| 13 | { |
| 14 | /** |
| 15 | * Save global styles |
| 16 | * |
| 17 | * @return array |
| 18 | */ |
| 19 | public function save_styles(array $global_styles, ?string $session_id = null) |
| 20 | { |
| 21 | foreach ($global_styles as $key => $style_block) { |
| 22 | if (empty($style_block['isGlobalStyle'])) { |
| 23 | $global_styles[$key] = array_merge($style_block, ['isGlobalStyle' => true]); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | if ($session_id) { |
| 28 | $create_collaboration_dto = CreateCollaborationDTO::from_array([ |
| 29 | 'session_id' => $session_id, |
| 30 | 'parent' => CollaborationParent::GLOBAL, |
| 31 | 'parent_id' => 0, |
| 32 | 'data' => [ |
| 33 | 'type' => CollaborationConnectionType::UPDATE_GLOBAL_STYLE, |
| 34 | 'payload' => ['styleBlock' => $global_styles], |
| 35 | ], |
| 36 | ]); |
| 37 | |
| 38 | (new CollaborationService())->save_action($create_collaboration_dto); |
| 39 | } |
| 40 | |
| 41 | GlobalData::update_style_blocks($global_styles); |
| 42 | |
| 43 | return $global_styles; |
| 44 | } |
| 45 | } |