Inicializa módulo base ldap_groups_sync

Cria super-módulo com infraestrutura compartilhada de regras de acesso
para os módulos de sincronização LDAP de grupos.

- GroupAccessRulesService: serviço parametrizável por config name
- AccessRulesFormBase: listagem/remoção de regras (classe abstrata)
- AccessRuleFormBase: formulário modal de criação/edição (classe abstrata)
- Sub-módulos ldap_departments_sync e ldap_research_groups_sync refatorados
  para estender as classes base com subclasses mínimas
- Traduções pt-br centralizadas em ldap_groups_sync.pt-br.po

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 09:55:54 -03:00
commit 346b897e25
104 changed files with 11315 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
<?php
namespace Drupal\ldap_departments_sync\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller para títulos traduzíveis.
*/
class LocalModulesController extends ControllerBase {
/**
* Retorna título traduzível para a página Local Modules.
*
* @return string
* Título traduzido.
*/
public function getTitle() {
return $this->t('Local Modules');
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Drupal\ldap_departments_sync\Form;
use Drupal\ldap_groups_sync\Form\AccessRuleFormBase;
/**
* Modal form for creating or editing a single access rule (Departments Sync).
*/
class AccessRuleForm extends AccessRuleFormBase {
/**
* {@inheritdoc}
*/
protected function getConfigName(): string {
return 'ldap_departments_sync.settings';
}
/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'ldap_departments_sync_access_rule_form';
}
/**
* {@inheritdoc}
*/
protected function getAccessRulesRoute(): string {
return 'ldap_departments_sync.access_rules';
}
/**
* {@inheritdoc}
*/
protected function getDefaultGroupTypeId(): string {
return 'departments';
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Drupal\ldap_departments_sync\Form;
use Drupal\ldap_groups_sync\Form\AccessRulesFormBase;
/**
* Lists and manages access rules for the LDAP Departments Sync module.
*/
class AccessRulesForm extends AccessRulesFormBase {
/**
* {@inheritdoc}
*/
protected function getConfigName(): string {
return 'ldap_departments_sync.settings';
}
/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'ldap_departments_sync_access_rules_form';
}
/**
* {@inheritdoc}
*/
protected function getAccessRuleFormRoute(): string {
return 'ldap_departments_sync.access_rule_form';
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,105 @@
<?php
namespace Drupal\ldap_departments_sync\Plugin\EntityReferenceSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the 'department' entity_reference selection.
*
* @EntityReferenceSelection(
* id = "ldap_departments_sync",
* label = @Translation("Department selection"),
* entity_types = {"group"},
* group = "ldap_departments_sync",
* weight = 1
* )
*/
class DepartmentSelection extends DefaultSelection {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'filter_by_type' => FALSE,
'allowed_types' => [],
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
// Força departments como bundle padrão
$form['target_bundles']['#default_value'] = ['departments' => 'departments'];
$configuration = $this->getConfiguration();
$form['filter_by_type'] = [
'#type' => 'checkbox',
'#title' => $this->t('Filter by department type'),
'#description' => $this->t('Only show departments of specific types (field_dept_type).'),
'#default_value' => $configuration['filter_by_type'],
'#weight' => 10,
];
$form['allowed_types'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Allowed department types'),
'#options' => [
'academico' => $this->t('Acadêmico'),
'administrativo' => $this->t('Administrativo'),
],
'#default_value' => $configuration['allowed_types'],
'#weight' => 11,
'#states' => [
'visible' => [
':input[name="settings[handler_settings][filter_by_type]"]' => ['checked' => TRUE],
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);
// Remove valores vazios de allowed_types
$allowed_types = $form_state->getValue(['settings', 'handler_settings', 'allowed_types']);
if (is_array($allowed_types)) {
$allowed_types = array_filter($allowed_types);
$form_state->setValue(['settings', 'handler_settings', 'allowed_types'], $allowed_types);
}
}
/**
* {@inheritdoc}
*/
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
$configuration = $this->getConfiguration();
// Força apenas departments
$query->condition('type', 'departments');
// Filtra por tipo de departamento se configurado
if (!empty($configuration['filter_by_type']) && !empty($configuration['allowed_types'])) {
$allowed_types = array_filter($configuration['allowed_types']);
if (!empty($allowed_types)) {
$query->condition('field_dept_type', array_keys($allowed_types), 'IN');
}
}
return $query;
}
}