feat: Sincroniza foto LDAP para field_user_photos no login

Implementa hook_ldap_user_edit_user_alter() para capturar a foto do
atributo LDAP configurado e adicioná-la como primeira entrada em
field_user_photos, sem queries adicionais ao servidor.

Inclui LdapPhotoSyncService com detecção de tipo via exif_imagetype,
deduplicação por MD5 e reutilização de media entity existente.
Adiciona checkbox para ativar/desativar o sync no formulário de settings,
com visibilidade condicional do campo de atributo via #states.

Corrige acesso a mídias publicadas para usuários autenticados via
hook_media_access(), resolvendo "Acesso restrito" no widget e na
visualização do perfil.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 15:23:20 -03:00
parent 5cacb97f12
commit 6266b42e0e
5 changed files with 210 additions and 1 deletions

View File

@@ -98,12 +98,24 @@ class SiteUsersSettingsForm extends ConfigFormBase {
'#required' => TRUE,
];
$form['photos']['photos_ldap_sync_enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable LDAP photo synchronization'),
'#description' => $this->t('When enabled, the user photo from LDAP is automatically added as the first profile photo on each login.'),
'#default_value' => $config->get('photos.ldap_sync_enabled') ?? FALSE,
];
$form['photos']['photos_ldap_attribute'] = [
'#type' => 'textfield',
'#title' => $this->t('LDAP photo attribute'),
'#description' => $this->t('If LDAP is enabled, enter the name of the attribute that contains the user photo (e.g., thumbnailPhoto, jpegPhoto).'),
'#description' => $this->t('Name of the LDAP attribute that contains the user photo (e.g., thumbnailPhoto, jpegPhoto).'),
'#default_value' => $config->get('photos.ldap_attribute') ?? 'jpegPhoto',
'#maxlength' => 255,
'#states' => [
'visible' => [
':input[name="photos_ldap_sync_enabled"]' => ['checked' => TRUE],
],
],
];
// Fieldset para campos editáveis pelo próprio usuário.
@@ -144,6 +156,7 @@ class SiteUsersSettingsForm extends ConfigFormBase {
$config
->set('photos.max_count', $form_state->getValue('photos_max_count'))
->set('photos.ldap_sync_enabled', (bool) $form_state->getValue('photos_ldap_sync_enabled'))
->set('photos.ldap_attribute', $form_state->getValue('photos_ldap_attribute'));
$definitions = \Drupal::service('entity_field.manager')