Elgg  Version 4.3
widgets.php
Go to the documentation of this file.
1 <?php
12 $num_columns = elgg_extract('num_columns', $vars, 3);
13 $show_add_widgets = elgg_extract('show_add_widgets', $vars, true);
14 $show_access = elgg_extract('show_access', $vars, true);
15 $owner_guid = elgg_extract('owner_guid', $vars);
16 
18 if ($owner_guid) {
20 } else {
22 }
23 
24 if (!$owner) {
25  return;
26 }
27 
28 elgg_require_js('elgg/widgets');
29 
30 // Underlying views and functions assume that the page owner is the owner of the widgets
31 if ($owner->guid != $page_owner->guid) {
33 }
34 
36 
38 
39 $result = '';
40 $no_widgets = elgg_extract('no_widgets', $vars);
41 if (empty($widgets) && !empty($no_widgets)) {
42  if ($no_widgets instanceof \Closure) {
43  echo $no_widgets();
44  } else {
46  }
47 }
48 
50  $result .= elgg_view('page/layouts/widgets/add_button', $vars);
51 }
52 
53 // push context after the add_button as add button uses current context
54 elgg_push_context('widgets');
55 
56 if ($widgets) {
58  'context' => $context,
59  'container' => $owner,
60  ]);
61 }
62 
63 // move hidden columns widgets to last visible column
64 if (!isset($widgets[$num_columns])) {
65  $widgets[$num_columns] = [];
66 }
67 
68 foreach ($widgets as $index => $column_widgets) {
69  if ($index <= $num_columns) {
70  continue;
71  }
72 
73  // append widgets to last column and retain order
74  foreach ($column_widgets as $column_widget) {
75  $widgets[$num_columns][] = $column_widget;
76  }
77  unset($widgets[$index]);
78 }
79 
80 $grid = '';
81 for ($column_index = 1; $column_index <= $num_columns; $column_index++) {
82  $column_widgets = (array) elgg_extract($column_index, $widgets, []);
83 
84  $widgets_content = '';
85  foreach ($column_widgets as $widget) {
86  if (!array_key_exists($widget->handler, $widget_types)) {
87  continue;
88  }
89 
90  $widgets_content .= elgg_view_entity($widget, [
91  'show_access' => $show_access,
92  'register_rss_link' => false,
93  ]);
94  }
95 
96  $grid .= elgg_format_element('div', [
97  'id' => "elgg-widget-col-{$column_index}",
98  'class' => [
99  'elgg-widgets',
100  ],
101 
102  ], $widgets_content);
103 }
104 
105 $result .= elgg_format_element('div', [
106  'class' => 'elgg-widgets-grid',
107 ], $grid);
108 
110 
111 echo elgg_format_element('div', [
112  'class' => [
113  'elgg-layout-widgets',
114  "elgg-layout-widgets-{$context}",
115  ],
116  'data-page-owner-guid' => $owner->guid,
117 ], $result);
118 
119 // Restore original page owner
120 if ($owner->guid != $page_owner->guid) {
122 }
$widget_types
Definition: add_panel.php:28
$owner
Definition: upload.php:7
elgg_push_context($context)
Push a context onto the top of the stack.
Definition: context.php:52
$no_widgets
Definition: widgets.php:40
$num_columns
Elgg widgets layout.
Definition: widgets.php:12
elgg_get_widget_types($context="")
Get the widget types for a context.
Definition: widgets.php:127
elgg_get_context()
Get the current context.
Definition: context.php:41
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:34
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: context.php:62
elgg_get_widgets($owner_guid, $context)
Elgg widgets library.
Definition: widgets.php:20
elgg_can_edit_widget_layout($context, $user_guid=0)
Can the user edit the widget layout.
Definition: widgets.php:50
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:135
elgg_view_entity(\ElggEntity $entity, array $vars=[])
Returns a string of a rendered entity.
Definition: views.php:518
$page_owner
Definition: widgets.php:17
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
$result
Definition: widgets.php:39
if($owner->guid!=$page_owner->guid) $context
Definition: widgets.php:35
if($widgets) if(!isset($widgets[$num_columns])) foreach($widgets as $index=> $column_widgets) $grid
Definition: widgets.php:80
if($guid===false) $widget
Definition: add.php:30
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
$widgets
Definition: widgets.php:37
$owner_guid
Definition: widgets.php:15
elgg echo
Translates a string.
Definition: deprecated.js:530
$vars['head']
Definition: html.php:24
$show_access
Definition: widgets.php:14
$index
Definition: gallery.php:40
$show_add_widgets
Definition: widgets.php:13
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69