Elgg  Version 6.1
save.php
Go to the documentation of this file.
1 <?php
10 if (!elgg_is_logged_in()) {
11  return;
12 }
13 
14 elgg_import_esm('elgg/comments');
15 
16 /* @var \ElggEntity $entity */
17 $entity = elgg_extract('entity', $vars);
18 
19 /* @var \ElggComment $comment */
20 $comment = elgg_extract('comment', $vars);
21 
22 $inline = (bool) elgg_extract('inline', $vars, false);
23 
24 if ($entity instanceof \ElggEntity) {
25  echo elgg_view('input/hidden', [
26  'name' => 'entity_guid',
27  'value' => $entity->guid,
28  ]);
29 }
30 
32 $footer = '';
33 if ($comment instanceof \ElggComment && $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', ['text' => elgg_echo('save')]);
40  $comment_text = $comment->description;
41 } else {
42  $comment_label = elgg_echo('generic_comments:add');
43  $footer .= elgg_view('input/submit', ['text' => 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  echo elgg_format_element('div', ['class' => 'elgg-fieldset-horizontal'], $form . $footer);
54 } else {
55  echo elgg_view_field([
56  '#type' => 'longtext',
57  '#label' => $comment_label,
58  'name' => 'generic_comment',
59  'value' => $comment_text,
60  'required' => true,
61  'editor_type' => 'simple',
62  ]);
63 
64  if ($comment) {
65  $footer .= elgg_view('input/button', [
66  'text' => elgg_echo('cancel'),
67  'class' => 'elgg-button-cancel mlm',
68  'href' => $entity ? $entity->getURL() : '#',
69  ]);
70  }
71 
73 }
$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:1112
$inline
Definition: save.php:22
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
if(!$widget instanceof\ElggWidget) if(!$widget->canEdit()) $form
Definition: edit.php:19
$footer
Definition: save.php:89
canEdit(int $user_guid=0)
Can a user edit this entity?
Definition: ElggEntity.php:397
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:256
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
elgg_set_form_footer(string $footer= '')
Sets form footer and defers its rendering until the form view and extensions have been rendered...
Definition: views.php:1046
elgg_import_esm(string $name)
Helper functions for external files like css/js.
if(!$entity instanceof\ElggEntity) if(!$entity->canComment()) $comment
Definition: save.php:42
$entity
Definition: save.php:17
$vars['type']
Plugin user settings.
Definition: save.php:8
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145