Elgg  Version 4.3
dependencies.php
Go to the documentation of this file.
1 <?php
9 $plugin = elgg_extract('plugin', $vars, false);
10 
11 // elgg-plugin dependencies
12 $deps = $plugin->getDependencies();
13 if (!empty($deps)) {
14  $deps_info = '<table class="elgg-table">';
15  $deps_info .= '<thead><tr><th>' . elgg_echo('item:object:plugin') . '</th><th>' . elgg_echo('ElggPlugin:Dependencies:MustBeActive') . '</th><th>' . elgg_echo('ElggPlugin:Dependencies:Position') . '</th></tr></thead>';
16  $deps_info .= '<tbody>';
17 
18  foreach ($deps as $plugin_id => $plugin_dep) {
19  $plugin_dep_info = elgg_format_element('td', [], $plugin_id);
20  $dep_issue = false;
21 
22  $must_be_active = elgg_extract('must_be_active', $plugin_dep, true);
23  $must_be_active_options = [];
24  if ($must_be_active && !elgg_is_active_plugin($plugin_id)) {
25  $must_be_active_options['class'] = ['elgg-loud'];
26  $dep_issue = true;
27  }
28 
29  $plugin_dep_info .= elgg_format_element('td', $must_be_active_options, $must_be_active ? elgg_echo('option:yes') : elgg_echo('option:no'));
30 
31  $position = elgg_extract('position', $plugin_dep);
32  $position_options = [];
33 
34  $dependent_plugin = elgg_get_plugin_from_id($plugin_id);
35  if (!empty($position) && !empty($dependent_plugin)) {
36  if ($position == 'after' && ($plugin->getPriority() < $dependent_plugin->getPriority())) {
37  $position_options['class'] = ['elgg-loud'];
38  $dep_issue = true;
39  } elseif ($position == 'before' && ($plugin->getPriority() > $dependent_plugin->getPriority())) {
40  $position_options['class'] = ['elgg-loud'];
41  $dep_issue = true;
42  }
43  }
44 
45  $plugin_dep_info .= elgg_format_element('td', $position_options, $position);
46 
47  $deps_options = [];
48  if ($dep_issue) {
49  $deps_options['class'] = ['elgg-state', 'elgg-state-error'];
50  }
51 
52  $deps_info .= elgg_format_element('tr', $deps_options, $plugin_dep_info);
53  }
54 
55  $deps_info .= '</tbody></table>';
56 
57  echo $deps_info;
58 }
59 
60 try {
61  $plugin->assertDependencies();
62 } catch (Exception $e) {
63  echo elgg_view_message('error', $e->getMessage());
64 }
elgg_get_plugin_from_id(string $plugin_id)
Elgg plugins library Contains functions for managing plugins.
Definition: plugins.php:15
$plugin
Definition: dependencies.php:9
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
$position
Definition: move.php:7
$plugin_id
Remove all user and plugin settings from the give plugin ID.
Definition: remove.php:8
elgg_view_message($type, $body, array $vars=[])
Wrapper function for the message display pattern.
Definition: views.php:965
elgg_is_active_plugin(string $plugin_id)
Returns if a plugin is active for a current site.
Definition: plugins.php:43
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:135
$deps
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg echo
Translates a string.
Definition: deprecated.js:530
$vars['head']
Definition: html.php:24