1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package midcom.baseclasses |
4
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
5
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
6
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use midcom\workflow\dialog; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Base trait for components. Provides some common functionality that should be available |
13
|
|
|
* in all parts of the component's environment. |
14
|
|
|
* |
15
|
|
|
* @property midcom_services_i18n $_i18n A handle to the i18n service. |
16
|
|
|
* @property midcom_services_i18n_l10n $_l10n The components' L10n string database. |
17
|
|
|
* @property midcom_services_i18n_l10n $_l10n_midcom The global MidCOM string database. |
18
|
|
|
* @property midcom_helper_configuration $_config The current configuration. |
19
|
|
|
* @package midcom.baseclasses |
20
|
|
|
*/ |
21
|
|
|
trait midcom_baseclasses_components_base |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The name of the component, e.g. net.nehmer.static. Should be used whenever the |
25
|
|
|
* component's name is required instead of hardcoding it. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $_component = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Initialize $_component (unless already set) |
33
|
|
|
*/ |
34
|
470 |
|
public function __construct() |
35
|
|
|
{ |
36
|
470 |
|
if ($this->_component == '') { |
37
|
466 |
|
$this->_component = preg_replace('/^(.+?)_(.+?)_([^_]+).*/', '$1.$2.$3', get_class($this)); |
38
|
|
|
} |
39
|
470 |
|
} |
40
|
|
|
|
41
|
437 |
|
public function __get($field) |
42
|
|
|
{ |
43
|
437 |
|
switch ($field) { |
44
|
437 |
|
case '_i18n': |
45
|
54 |
|
return midcom::get()->i18n; |
46
|
432 |
|
case '_l10n': |
47
|
351 |
|
return midcom::get()->i18n->get_l10n($this->_component); |
48
|
426 |
|
case '_l10n_midcom': |
49
|
344 |
|
return midcom::get()->i18n->get_l10n('midcom'); |
50
|
425 |
|
case '_config': |
51
|
425 |
|
return midcom_baseclasses_components_configuration::get($this->_component, 'config'); |
52
|
|
|
default: |
53
|
|
|
debug_add('Component ' . $this->_component . ' tried to access nonexistent service "' . $field . '"', MIDCOM_LOG_ERROR); |
54
|
|
|
debug_print_function_stack('Called from here:'); |
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function __isset($field) |
60
|
|
|
{ |
61
|
|
|
return in_array($field, ['_i18n', '_l10n', '_l10n_midcom', '_config']); |
62
|
|
|
} |
63
|
|
|
|
64
|
33 |
|
public function set_active_leaf($leaf_id) |
65
|
|
|
{ |
66
|
33 |
|
midcom_baseclasses_components_configuration::set($this->_component, 'active_leaf', $leaf_id); |
67
|
33 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Convenience shortcut for adding CSS files |
71
|
|
|
*/ |
72
|
126 |
|
public function add_stylesheet(string $url, string $media = null) |
73
|
|
|
{ |
74
|
126 |
|
midcom::get()->head->add_stylesheet($url, $media); |
75
|
126 |
|
} |
76
|
|
|
|
77
|
185 |
|
public function get_workflow(string $identifier, array $options = []) : dialog |
78
|
|
|
{ |
79
|
185 |
|
$classname = '\\midcom\\workflow\\' . $identifier; |
80
|
185 |
|
return new $classname($options); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|