Elgg  Version master
access.php
Go to the documentation of this file.
1 <?php
19 // bail if set to a unusable value
20 if (isset($vars['options_values'])) {
21  if (!is_array($vars['options_values']) || empty($vars['options_values'])) {
22  return;
23  }
24 }
25 
26 $vars['class'] = elgg_extract_class($vars, 'elgg-input-access');
27 
28 // this will be passed to plugin hooks ['access:collections:write', 'user'] and ['default', 'access']
29 $params = [];
30 
31 $keys = [
32  'entity' => null,
33  'entity_type' => null,
34  'entity_subtype' => null,
35  'container_guid' => null,
36  'purpose' => 'read',
37 ];
38 foreach ($keys as $key => $default_value) {
40  unset($vars[$key]);
41 }
42 
43 /* @var ElggEntity $entity */
44 $entity = $params['entity'];
45 
46 if ($entity) {
47  $params['value'] = $entity->access_id;
48  $params['entity_type'] = $entity->type;
49  $params['entity_subtype'] = $entity->getSubtype();
50  $params['container_guid'] = $entity->container_guid;
51 }
52 
54 if (!$params['container_guid'] && $container) {
55  $params['container_guid'] = $container->guid;
56 }
57 
58 // don't call elgg_get_default_access() unless we need it
60 if (!isset($vars['value']) || $vars['value'] == ACCESS_DEFAULT) {
61  if ($entity) {
62  $vars['value'] = $entity->access_id;
63  } else if (empty($vars['options_values']) || !is_array($vars['options_values'])) {
64  $vars['value'] = elgg_get_default_access(null, $params);
65 
66  // if default value is not present in the options we should not add it
67  $add_missing_value = false;
68  } else {
69  $options_values_ids = array_keys(elgg_extract('options_values', $vars));
70  $vars['value'] = $options_values_ids[0];
71  }
72 }
73 
74 $params['value'] = elgg_extract('value', $vars);
75 
76 // don't call elgg_get_write_access_array() unless we need it
77 if (!isset($vars['options_values'])) {
78  $vars['options_values'] = elgg_get_write_access_array(0, false, $params);
79 }
80 
81 if (!isset($vars['disabled'])) {
82  $vars['disabled'] = false;
83 }
84 
85 // if access is set to a value not present in the available options, add the option
86 if ($add_missing_value && !isset($vars['options_values'][$vars['value']])) {
87  $vars['options_values'][$vars['value']] = elgg_get_readable_access_level($vars['value']);
88 }
89 
90 echo elgg_view('input/select', $vars);
elgg_get_default_access(\ElggUser $user=null, array $input_params=[])
Gets the default access permission.
Definition: access.php:56
foreach($keys as $key=> $default_value) $entity
Definition: access.php:44
const ACCESS_DEFAULT
Controls access levels on entities, metadata, and annotations.
Definition: constants.php:9
$keys
Definition: access.php:31
elgg_get_write_access_array(int $user_guid=0, bool $flush=false, array $input_params=[])
Returns an array of access permissions that the user is allowed to save content with.
Definition: access.php:129
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:254
$params
Definition: access.php:29
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
if(isset($vars['options_values'])) $vars['class']
Elgg access level input Displays a dropdown input field.
Definition: access.php:26
if($entity) $container
Definition: access.php:53
if(!$params['container_guid']&&$container) $add_missing_value
Definition: access.php:59
$default_value
Definition: checkbox.php:13
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
elgg_get_readable_access_level(int $entity_access_id)
Return the name of an ACCESS_* constant or an access collection, but only if the logged in user has w...
Definition: access.php:196
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
elgg_extract_class(array $array, array|string $existing=[], string $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:277