Corrige handler_settings e exclude_entity_types no field_parent_page (PHP 8)

Adiciona hook_update_10006 que re-sincroniza settings de field_parent_page a
partir do YAML de install, e hook_update_10007 que corrige exclude_entity_types
no storage para FALSE. Ambos evitam TypeError no PHP 8 no widget de referência
dinâmica. Atualiza também o YAML de install com a configuração correta.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-18 13:21:53 -03:00
parent 276fd028f2
commit 6ab880045a
2 changed files with 49 additions and 1 deletions

View File

@@ -8,7 +8,9 @@ id: node.field_parent_page
field_name: field_parent_page
entity_type: node
type: dynamic_entity_reference
settings: { }
settings:
exclude_entity_types: false
entity_type_ids: []
module: dynamic_entity_reference
locked: false
cardinality: 1

View File

@@ -323,6 +323,52 @@ function _structural_pages_ensure_content_translation(): void {
$config->save();
}
/**
* Corrige handler_settings nulo no field_parent_page (compatibilidade PHP 8).
*
* O widget DynamicEntityReferenceWidget faz $settings[$type]['handler_settings']
* + array, que lança TypeError quando handler_settings é null no PHP 8.
* Re-aplica as settings completas a partir do YAML de install do módulo.
*/
function structural_pages_update_10006(): string {
$config = \Drupal::configFactory()
->getEditable('field.field.node.content_page.field_parent_page');
if ($config->isNew()) {
return t('Campo field_parent_page não encontrado — nada a corrigir.');
}
// Re-aplica as settings completas a partir do YAML de install.
$module_path = \Drupal::service('extension.list.module')->getPath('structural_pages');
$yaml_file = $module_path . '/config/install/field.field.node.content_page.field_parent_page.yml';
if (!file_exists($yaml_file)) {
return t('Arquivo YAML de install não encontrado.');
}
$yaml_settings = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($yaml_file));
$config->set('settings', $yaml_settings['settings']);
$config->save(TRUE);
return t('Settings de field_parent_page re-sincronizadas a partir do YAML de install.');
}
/**
* Corrige exclude_entity_types no storage do field_parent_page (PHP 8 TypeError).
*
* defaultStorageSettings() retorna exclude_entity_types: TRUE, o que fazia
* getTargetTypes() retornar todos os entity types EXCETO node/taxonomy_term.
*/
function structural_pages_update_10007(): string {
$config = \Drupal::configFactory()
->getEditable('field.storage.node.field_parent_page');
if ($config->isNew()) {
return 'field.storage.node.field_parent_page não encontrado.';
}
$config->set('settings.exclude_entity_types', FALSE)->save(TRUE);
return 'exclude_entity_types corrigido para FALSE em field_parent_page storage.';
}
/**
* Implements hook_requirements().
*/