mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/ldap_groups_sync.git
synced 2026-03-10 10:27:40 -03:00
Move submódulos para modules/ seguindo convenção Drupal
ldap_departments_sync/ e ldap_research_groups_sync/ movidos para modules/, padrão adotado por módulos contrib como Drupal Commerce. Nenhum arquivo PHP ou YAML alterado — o Drupal descobre módulos recursivamente pelo .info.yml independente do caminho. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Installs field_rg_department on the research_group group bundle.
|
||||
*
|
||||
* Usage (from Drupal root):
|
||||
* drush php-script modules/custom/ldap_research_groups_sync/scripts/install_field_rg_department.php
|
||||
*/
|
||||
|
||||
$module_path = \Drupal::service('extension.list.module')->getPath('ldap_research_groups_sync');
|
||||
$config_path = $module_path . '/config/optional';
|
||||
|
||||
$config_factory = \Drupal::configFactory();
|
||||
$yaml_parser = \Drupal::service('serialization.yaml');
|
||||
|
||||
$configs_to_install = [
|
||||
'field.storage.group.field_rg_department',
|
||||
'field.field.group.research_group.field_rg_department',
|
||||
'core.entity_form_display.group.research_group.default',
|
||||
'core.entity_view_display.group.research_group.default',
|
||||
];
|
||||
|
||||
$imported = 0;
|
||||
$skipped = 0;
|
||||
|
||||
foreach ($configs_to_install as $config_name) {
|
||||
$file = $config_path . '/' . $config_name . '.yml';
|
||||
|
||||
if (!file_exists($file)) {
|
||||
echo "ERROR: File not found: $file\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$existing = $config_factory->get($config_name);
|
||||
|
||||
// For display configs, always update (they already exist and need the new field).
|
||||
$is_display = str_starts_with($config_name, 'core.entity_');
|
||||
|
||||
if (!$existing->isNew() && !$is_display) {
|
||||
echo "SKIP: $config_name (already exists)\n";
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = $yaml_parser->decode(file_get_contents($file));
|
||||
$config_factory->getEditable($config_name)->setData($data)->save();
|
||||
|
||||
echo "OK: $config_name\n";
|
||||
$imported++;
|
||||
}
|
||||
|
||||
if ($imported > 0) {
|
||||
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
|
||||
\Drupal::service('entity_type.bundle.info')->clearCachedBundles();
|
||||
\Drupal::service('plugin.manager.field.widget')->clearCachedDefinitions();
|
||||
\Drupal::service('plugin.manager.field.formatter')->clearCachedDefinitions();
|
||||
\Drupal::service('config.factory')->clearStaticCache();
|
||||
|
||||
// Create the database table for the new field storage.
|
||||
$field_manager = \Drupal::service('entity_field.manager');
|
||||
$field_manager->clearCachedFieldDefinitions();
|
||||
$update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$storage_defs = $field_manager->getFieldStorageDefinitions('group');
|
||||
if (isset($storage_defs['field_rg_department'])) {
|
||||
$update_manager->installFieldStorageDefinition(
|
||||
'field_rg_department',
|
||||
'group',
|
||||
'ldap_research_groups_sync',
|
||||
$storage_defs['field_rg_department']
|
||||
);
|
||||
echo "Schema update applied (group__field_rg_department table created).\n";
|
||||
}
|
||||
else {
|
||||
echo "WARNING: field_rg_department storage definition not found — table not created.\n";
|
||||
}
|
||||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
echo "\nDone. Imported: $imported, Skipped: $skipped\n";
|
||||
echo "Run 'drush cr' to clear all caches.\n";
|
||||
}
|
||||
else {
|
||||
echo "\nNothing imported. Skipped: $skipped\n";
|
||||
}
|
||||
Reference in New Issue
Block a user