Elgg  Version 7.1
RegisterFields.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Forms;
4 
11 
19  public static function addEntityGUID(\Elgg\Event $event): ?array {
20  $entity = $event->getEntityParam();
21  if (!$entity instanceof \ElggEntity) {
22  return null;
23  }
24 
25  $fields = $event->getValue();
26 
27  $fields[] = [
28  '#type' => 'hidden',
29  'name' => 'guid',
30  'value' => $entity->guid,
31  ];
32 
33  return $fields;
34  }
35 
43  public static function addEntityToAccessInput(\Elgg\Event $event): ?array {
44  $entity = $event->getEntityParam();
45  if (!$entity instanceof \ElggEntity) {
46  return null;
47  }
48 
49  $fields = $event->getValue();
50  foreach ($fields as $index => $field) {
51  if (elgg_extract('#type', $field) !== 'access') {
52  continue;
53  }
54 
55  $fields[$index]['entity'] = $entity;
56  }
57 
58  return $fields;
59  }
60 
68  public static function addContainerInput(\Elgg\Event $event): ?array {
69  $entity_type = $event->getParam('entity_type');
70  $entity_subtype = $event->getParam('entity_subtype');
71  if (empty($entity_type) || empty($entity_subtype)) {
72  return null;
73  }
74 
75  $fields = $event->getValue();
76  $fields[] = [
77  '#type' => 'container_guid',
78  'name' => 'container_guid',
79  'entity_type' => $entity_type,
80  'entity_subtype' => $entity_subtype,
81  ];
82 
83  return $fields;
84  }
85 }
$fields
Save the configuration of the security.txt contents.
Definition: security_txt.php:6
$entity
Definition: reset.php:8
Models an event passed to event handlers.
Definition: Event.php:11
Add fields to an entity form.
static addEntityToAccessInput(\Elgg\Event $event)
Add the entity to input/access fields.
static addContainerInput(\Elgg\Event $event)
Add a container input to the form fields.
static addEntityGUID(\Elgg\Event $event)
Add a hidden input to the fields when an entity is provided.
$index
Definition: gallery.php:40
if(elgg_extract('input_type', $vars)) if(elgg_extract('required', $vars)) if(elgg_extract('disabled', $vars)) $field
Definition: field.php:42
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:246
$entity_subtype
Definition: edit.php:15
$entity_type
Generic entity edit/add form.
Definition: edit.php:14