Elgg  Version 3.0
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 // Underlying views and functions assume that the page owner is the owner of the widgets
29 if ($owner->guid != $page_owner->guid) {
31 }
32 
34 
36 
37 $result = '';
38 $no_widgets = elgg_extract('no_widgets', $vars);
39 if (empty($widgets) && !empty($no_widgets)) {
40  if ($no_widgets instanceof \Closure) {
41  echo $no_widgets();
42  } else {
44  }
45 }
46 
48  $result .= elgg_view('page/layouts/widgets/add_button', $vars);
49 }
50 
51 // push context after the add_button as add button uses current context
52 elgg_push_context('widgets');
53 
54 if ($widgets) {
56  'context' => $context,
57  'container' => $owner,
58  ]);
59 }
60 
61 // move hidden columns widgets to last visible column
62 if (!isset($widgets[$num_columns])) {
63  $widgets[$num_columns] = [];
64 }
65 
66 foreach ($widgets as $index => $column_widgets) {
67  if ($index <= $num_columns) {
68  continue;
69  }
70 
71  // append widgets to last column and retain order
72  foreach ($column_widgets as $column_widget) {
73  $widgets[$num_columns][] = $column_widget;
74  }
75  unset($widgets[$index]);
76 }
77 
78 $grid = '';
79 for ($column_index = 1; $column_index <= $num_columns; $column_index++) {
80  $column_widgets = (array) elgg_extract($column_index, $widgets, []);
81 
82  $widgets_content = '';
83  foreach ($column_widgets as $widget) {
84  if (!array_key_exists($widget->handler, $widget_types)) {
85  continue;
86  }
87 
88  $widgets_content .= elgg_view_entity($widget, [
89  'show_access' => $show_access,
90  'register_rss_link' => false,
91  ]);
92  }
93 
94  $grid .= elgg_format_element('div', [
95  'id' => "elgg-widget-col-{$column_index}",
96  'class' => [
97  'elgg-widgets',
98  ],
99 
100  ], $widgets_content);
101 }
102 
103 $result .= elgg_format_element('div', [
104  'class' => 'elgg-widgets-grid',
105 ], $grid);
106 
108 
109 $result .= elgg_view('graphics/ajax_loader', ['id' => 'elgg-widget-loader']);
110 
111 echo elgg_format_element('div', [
112  'class' => 'elgg-layout-widgets',
113  'data-page-owner-guid' => $owner->guid,
114 ], $result);
115 
116 ?>
117 <script>
118 require(['elgg/widgets'], function (widgets) {
119  widgets.init();
120 });
121 </script>
122 <?php
123 
124 // Restore original page owner
125 if ($owner->guid != $page_owner->guid) {
127 }
$widget_types
Definition: add_panel.php:28
$no_widgets
Definition: widgets.php:38
$result
Definition: widgets.php:37
$num_columns
Elgg widgets layout.
Definition: widgets.php:12
elgg_get_widget_types($context="")
Get the widget types for a context.
Definition: widgets.php:130
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:81
elgg_get_widgets($owner_guid, $context)
Get widgets for a particular context.
Definition: widgets.php:23
$owner
Definition: crop.php:7
elgg_can_edit_widget_layout($context, $user_guid=0)
Can the user edit the widget layout.
Definition: widgets.php:53
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:168
elgg_view_entity(\ElggEntity $entity, array $vars=[])
Returns a string of a rendered entity.
Definition: views.php:842
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: pageowner.php:222
elgg echo
Translates a string.
Definition: languages.js:43
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
$page_owner
Definition: widgets.php:17
elgg_get_context()
Get the current context.
Definition: pageowner.php:201
if(!$owner) if($owner->guid!=$page_owner->guid) $context
Definition: widgets.php:33
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:65
if($widgets) if(!isset($widgets[$num_columns])) foreach($widgets as $index=> $column_widgets) $grid
Definition: widgets.php:78
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:1131
$widgets
Definition: widgets.php:35
elgg_push_context($context)
Push a context onto the top of the stack.
Definition: pageowner.php:212
$owner_guid
Definition: widgets.php:15
$vars['type']
Definition: save.php:11
$show_access
Definition: widgets.php:14
$index
Definition: gallery.php:47
$show_add_widgets
Definition: widgets.php:13
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87