Elgg /
Elgg
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Edit profile form |
||
| 4 | * |
||
| 5 | * @tip Use 'profile:fields','profile' hook to modify profile fields configuration. |
||
| 6 | * Profile fields are configuration as an array of $shortname => $input_type pairs, |
||
| 7 | * where $shortname is the metadata name used to store the value, and the $input_type is |
||
| 8 | * an input view used to render the field input element. |
||
| 9 | * |
||
| 10 | * @uses vars['entity'] |
||
| 11 | */ |
||
| 12 | $entity = elgg_extract('entity', $vars); |
||
| 13 | /* @var ElggUser $entity */ |
||
| 14 | |||
| 15 | echo elgg_view_field([ |
||
| 16 | '#type' => 'text', |
||
| 17 | 'name' => 'name', |
||
| 18 | 'value' => $entity->name, |
||
| 19 | '#label' => elgg_echo('user:name:label'), |
||
| 20 | 'maxlength' => 50, // hard coded in /actions/profile/edit |
||
| 21 | ]); |
||
| 22 | |||
| 23 | $sticky_values = elgg_get_sticky_values('profile:edit'); |
||
| 24 | |||
| 25 | $profile_fields = elgg_get_config('profile_fields'); |
||
| 26 | if (is_array($profile_fields) && count($profile_fields) > 0) { |
||
| 27 | foreach ($profile_fields as $shortname => $valtype) { |
||
| 28 | $annotations = $entity->getAnnotations([ |
||
| 29 | 'annotation_names' => "profile:$shortname", |
||
| 30 | 'limit' => false, |
||
| 31 | ]); |
||
| 32 | $access_id = ACCESS_DEFAULT; |
||
| 33 | if ($annotations) { |
||
|
0 ignored issues
–
show
|
|||
| 34 | $value = ''; |
||
| 35 | foreach ($annotations as $annotation) { |
||
| 36 | if (!empty($value)) { |
||
| 37 | $value .= ', '; |
||
| 38 | } |
||
| 39 | $value .= $annotation->value; |
||
| 40 | $access_id = $annotation->access_id; |
||
| 41 | } |
||
| 42 | } else { |
||
| 43 | $value = ''; |
||
| 44 | } |
||
| 45 | |||
| 46 | // sticky form values take precedence over saved ones |
||
| 47 | if (isset($sticky_values[$shortname])) { |
||
| 48 | $value = $sticky_values[$shortname]; |
||
| 49 | } |
||
| 50 | if (isset($sticky_values['accesslevel'][$shortname])) { |
||
| 51 | $access_id = $sticky_values['accesslevel'][$shortname]; |
||
| 52 | } |
||
| 53 | |||
| 54 | $id = "profile-$shortname"; |
||
| 55 | $input = elgg_view("input/$valtype", [ |
||
| 56 | 'name' => $shortname, |
||
| 57 | 'value' => $value, |
||
| 58 | 'id' => $id, |
||
| 59 | ]); |
||
| 60 | $access_input = elgg_view('input/access', [ |
||
| 61 | 'name' => "accesslevel[$shortname]", |
||
| 62 | 'value' => $access_id, |
||
| 63 | ]); |
||
| 64 | |||
| 65 | echo elgg_view('elements/forms/field', [ |
||
| 66 | 'input' => elgg_format_element('div', [ |
||
| 67 | 'class' => 'elgg-field-input', |
||
| 68 | ], $input . $access_input), |
||
| 69 | 'label' => elgg_view('elements/forms/label', [ |
||
| 70 | 'label' => elgg_echo("profile:$shortname"), |
||
| 71 | 'id' => $id, |
||
| 72 | ]) |
||
| 73 | ]); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | elgg_clear_sticky_form('profile:edit'); |
||
| 78 | |||
| 79 | echo elgg_view('input/hidden', ['name' => 'guid', 'value' => $entity->guid]); |
||
| 80 | |||
| 81 | $footer = elgg_view_field([ |
||
| 82 | '#type' => 'submit', |
||
| 83 | 'value' => elgg_echo('save'), |
||
| 84 | '#class' => 'elgg-foot', |
||
| 85 | ]); |
||
| 86 | elgg_set_form_footer($footer); |
||
| 87 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.