Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

admin/configure_utilities/default_widgets.php (1 issue)

implicit conversion of array to boolean.

Best Practice Bug Minor
1
<?php
2
/**
3
 * Default widgets landing page.
4
 *
5
 * @package Elgg.Core
6
 * @subpackage Administration.DefaultWidgets
7
 */
8
9
elgg_push_context('default_widgets');
10
$widget_context = get_input('widget_context');
11
$list = elgg_trigger_plugin_hook('get_list', 'default_widgets', null, []);
12
13
// default to something if we can
14
if (!$widget_context && $list) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
15
	$widget_context = $list[0]['widget_context'];
16
}
17
18
$current_info = null;
19
$tabs = [];
20
foreach ($list as $info) {
21
	$url = "admin/configure_utilities/default_widgets?widget_context={$info['widget_context']}";
22
	$selected = false;
23
	if ($widget_context == $info['widget_context']) {
24
		$selected = true;
25
		$current_info = $info;
26
	}
27
28
	$tabs[] = [
29
		'title' => $info['name'],
30
		'url' => $url,
31
		'selected' => $selected
32
	];
33
}
34
35
$tabs_vars = [
36
	'tabs' => $tabs
37
];
38
39
echo elgg_view('navigation/tabs', $tabs_vars);
40
41
echo elgg_view('output/longtext', ['value' => elgg_echo('admin:default_widgets:instructions')]);
42
43
if (!$current_info) {
44
	$content = elgg_echo('admin:default_widgets:unknown_type');
45
} else {
46
	// default widgets are owned and saved to the site.
47
	elgg_set_page_owner_guid(1);
48
	elgg_push_context($current_info['widget_context']);
49
50
	$content = elgg_view_layout('widgets', [
51
		'num_columns' => $current_info['widget_columns'],
52
	]);
53
	elgg_pop_context();
54
}
55
elgg_pop_context();
56
57
echo $content;
58