| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\GlobalClasses; |
| 4 |
|
| 5 |
use Elementor\Core\Files\CSS\Post as Post_CSS; |
| 6 |
use Elementor\Modules\AtomicWidgets\Styles\Styles_Renderer; |
| 7 |
use Elementor\Plugin; |
| 8 |
|
| 9 |
class Global_Classes_CSS_File extends Post_CSS { |
| 10 |
|
| 11 |
const FILE_PREFIX = 'global-classes-'; |
| 12 |
|
| 13 |
const META_KEY = '_elementor_css__global_classes'; |
| 14 |
|
| 15 |
public function __construct( $kit_id = null ) { |
| 16 |
$kit_id = $kit_id ?? Plugin::$instance->kits_manager->get_active_id(); |
| 17 |
|
| 18 |
parent::__construct( $kit_id ); |
| 19 |
} |
| 20 |
|
| 21 |
public function get_name() { |
| 22 |
return 'global-classes'; |
| 23 |
} |
| 24 |
|
| 25 |
protected function get_file_handle_id() { |
| 26 |
return 'elementor-global-classes-' . $this->get_post_id(); |
| 27 |
} |
| 28 |
|
| 29 |
protected function get_enqueue_dependencies() { |
| 30 |
return []; |
| 31 |
} |
| 32 |
|
| 33 |
protected function get_inline_dependency() { |
| 34 |
return ''; |
| 35 |
} |
| 36 |
|
| 37 |
protected function render( $context ) { |
| 38 |
$global_classes = Global_Classes_Repository::make() |
| 39 |
->context( $context ) |
| 40 |
->all(); |
| 41 |
|
| 42 |
if ( $global_classes->get_items()->is_empty() ) { |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
$sorted_items = $global_classes |
| 47 |
->get_order() |
| 48 |
->reverse() |
| 49 |
->map( |
| 50 |
fn( $id ) => $global_classes->get_items()->get( $id ) |
| 51 |
); |
| 52 |
|
| 53 |
$css = Styles_Renderer::make( |
| 54 |
Plugin::$instance->breakpoints->get_breakpoints_config() |
| 55 |
)->on_prop_transform( function( $key, $value ) { |
| 56 |
if ( 'font-family' !== $key ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
$this->add_font( $value ); |
| 61 |
} )->render( |
| 62 |
$sorted_items->map( function( $item ) { |
| 63 |
$item['cssName'] = $item['label']; |
| 64 |
|
| 65 |
return $item; |
| 66 |
} )->all() |
| 67 |
); |
| 68 |
|
| 69 |
$this->get_stylesheet()->add_raw_css( $css ); |
| 70 |
} |
| 71 |
|
| 72 |
protected function render_css() { |
| 73 |
$this->render( Global_Classes_Repository::CONTEXT_FRONTEND ); |
| 74 |
} |
| 75 |
} |
| 76 |
|