Elgg  Version 4.3
save.php
Go to the documentation of this file.
1 <?php
10 if (!elgg_is_logged_in()) {
11  return;
12 }
13 
14 elgg_require_js('elgg/comments');
15 
16 $entity = elgg_extract('entity', $vars);
17 /* @var ElggEntity $entity */
18 
19 $comment = elgg_extract('comment', $vars);
20 /* @var ElggComment $comment */
21 
22 $inline = (bool) elgg_extract('inline', $vars, false);
23 
24 if ($entity) {
25  echo elgg_view('input/hidden', [
26  'name' => 'entity_guid',
27  'value' => $entity->guid,
28  ]);
29 }
30 
32 $footer = '';
33 if ($comment && $comment->canEdit()) {
34  echo elgg_view('input/hidden', [
35  'name' => 'comment_guid',
36  'value' => $comment->guid,
37  ]);
38  $comment_label = elgg_echo("generic_comments:edit");
39  $footer .= elgg_view('input/submit', ['value' => elgg_echo('save')]);
40  $comment_text = $comment->description;
41 } else {
42  $comment_label = elgg_echo("generic_comments:add");
43  $footer .= elgg_view('input/submit', ['value' => elgg_echo('comment')]);
44 }
45 
46 if ($inline) {
47  $form = elgg_view('input/text', [
48  'name' => 'generic_comment',
49  'value' => $comment_text,
50  'required' => true,
51  ]);
52 
53  $form .= $footer;
54  echo elgg_format_element('div', [
55  'class' => 'elgg-level',
56  ], $form);
57 } else {
59  '#type' => 'longtext',
60  '#label' => $comment_label,
61  'name' => 'generic_comment',
62  'value' => $comment_text,
63  'required' => true,
64  'editor_type' => 'simple',
65  ]);
66 
67  if ($comment) {
68  $footer .= elgg_view('input/button', [
69  'value' => elgg_echo('cancel'),
70  'class' => 'elgg-button-cancel mlm',
71  'href' => $entity ? $entity->getURL() : '#',
72  ]);
73  }
74 
76 }
$comment_text
Definition: save.php:8
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Definition: sessions.php:43
elgg_view_field(array $params=[])
Renders a form field, usually with a wrapper element, a label, help text, etc.
Definition: views.php:1143
if(!$entity) if(!$entity->canComment()) $comment
Definition: save.php:42
$inline
Definition: save.php:22
$footer
Definition: save.php:88
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
elgg_set_form_footer($footer= '')
Sets form footer and defers its rendering until the form view and extensions have been rendered...
Definition: views.php:1077
if(!$widget instanceof ElggWidget) $form
Definition: settings.php:13
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:135
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
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
$entity
Definition: save.php:16
$vars['type']
Plugin user settings.
Definition: save.php:8
elgg echo
Translates a string.
Definition: deprecated.js:530
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179