mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/site_users.git
synced 2026-03-10 10:17:41 -03:00
feat: Configuração de campos editáveis pelo próprio usuário
Adiciona seção na tela de configurações do módulo que permite ao administrador controlar quais campos do perfil cada usuário pode editar no próprio perfil, independentemente das permissões de papel. - site_users.settings.yml: novo grupo user_editable_fields (todos habilitados por padrão) - SiteUsersSettingsForm: fieldset com checkboxes por campo - site_users.module: site_users_check_profile_field_access() e site_users_check_photo_field_access() recebem field_name e consultam a config ao verificar 'edit own'; resultado inclui cache tag config:site_users.settings - translations/site_users.pt-br.po: novas strings traduzidas Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,22 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
*/
|
||||
class SiteUsersSettingsForm extends ConfigFormBase {
|
||||
|
||||
/**
|
||||
* Returns the list of fields controllable by the admin.
|
||||
*
|
||||
* @return array
|
||||
* Associative array of field_name => label.
|
||||
*/
|
||||
protected function getEditableFields(): array {
|
||||
return [
|
||||
'field_user_name' => $this->t('Full Name'),
|
||||
'field_user_phone' => $this->t('Phone'),
|
||||
'field_user_bio' => $this->t('Biography'),
|
||||
'field_user_social_links' => $this->t('Social Links'),
|
||||
'field_user_photos' => $this->t('Photos'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -55,6 +71,22 @@ class SiteUsersSettingsForm extends ConfigFormBase {
|
||||
'#maxlength' => 255,
|
||||
];
|
||||
|
||||
// Fieldset para campos editáveis pelo próprio usuário.
|
||||
$form['user_editable_fields'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $this->t('User-editable profile fields'),
|
||||
'#description' => $this->t('Select which fields users with the "Edit own user profile fields" or "Manage own user photos" permission can edit on their own profile.'),
|
||||
'#tree' => TRUE,
|
||||
];
|
||||
|
||||
foreach ($this->getEditableFields() as $field_name => $label) {
|
||||
$form['user_editable_fields'][$field_name] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $label,
|
||||
'#default_value' => $config->get('user_editable_fields.' . $field_name) ?? TRUE,
|
||||
];
|
||||
}
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
||||
@@ -62,10 +94,18 @@ class SiteUsersSettingsForm extends ConfigFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->config('site_users.settings')
|
||||
$config = $this->config('site_users.settings');
|
||||
|
||||
$config
|
||||
->set('photos.max_count', $form_state->getValue('photos_max_count'))
|
||||
->set('photos.ldap_attribute', $form_state->getValue('photos_ldap_attribute'))
|
||||
->save();
|
||||
->set('photos.ldap_attribute', $form_state->getValue('photos_ldap_attribute'));
|
||||
|
||||
$editable = $form_state->getValue('user_editable_fields');
|
||||
foreach (array_keys($this->getEditableFields()) as $field_name) {
|
||||
$config->set('user_editable_fields.' . $field_name, (bool) ($editable[$field_name] ?? FALSE));
|
||||
}
|
||||
|
||||
$config->save();
|
||||
|
||||
parent::submitForm($form, $form_state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user