| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Core\Base; |
| 4 |
|
| 5 |
use Elementor\Utils; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Base App |
| 13 |
* |
| 14 |
* Base app utility class that provides shared functionality of apps. |
| 15 |
* |
| 16 |
* @since 2.3.0 |
| 17 |
*/ |
| 18 |
abstract class App extends Module { |
| 19 |
|
| 20 |
/** |
| 21 |
* Print config. |
| 22 |
* |
| 23 |
* Used to print the app and its components settings as a JavaScript object. |
| 24 |
* |
| 25 |
* @param string $handle Optional |
| 26 |
* |
| 27 |
* @since 2.3.0 |
| 28 |
* @since 2.6.0 added the `$handle` parameter |
| 29 |
* @access protected |
| 30 |
*/ |
| 31 |
final protected function print_config( $handle = null ) { |
| 32 |
$name = $this->get_name(); |
| 33 |
|
| 34 |
$js_var = 'elementor' . str_replace( ' ', '', ucwords( str_replace( '-', ' ', $name ) ) ) . 'Config'; |
| 35 |
|
| 36 |
$config = $this->get_settings() + $this->get_components_config(); |
| 37 |
|
| 38 |
if ( ! $handle ) { |
| 39 |
$handle = 'elementor-' . $name; |
| 40 |
} |
| 41 |
|
| 42 |
Utils::print_js_config( $handle, $js_var, $config ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get components config. |
| 47 |
* |
| 48 |
* Retrieves the app components settings. |
| 49 |
* |
| 50 |
* @since 2.3.0 |
| 51 |
* @access private |
| 52 |
* |
| 53 |
* @return array |
| 54 |
*/ |
| 55 |
private function get_components_config() { |
| 56 |
$settings = []; |
| 57 |
|
| 58 |
foreach ( $this->get_components() as $id => $instance ) { |
| 59 |
$settings[ $id ] = $instance->get_settings(); |
| 60 |
} |
| 61 |
|
| 62 |
return $settings; |
| 63 |
} |
| 64 |
} |
| 65 |
|