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