mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/structural_pages.git
synced 2026-03-11 02:47:42 -03:00
Make site section vocabulary configurable and simplify settings form
Add a vocabulary selector to the settings form so the site section vocabulary is no longer hardcoded. Remove node bundle checkboxes (section_page/content_page are always included), keep user and group as configurable parent targets. All hardcoded 'site_sections' references in PHP replaced with dynamic config reads via helper. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ use Drupal\taxonomy\Entity\Term;
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function structural_pages_install(): void {
|
||||
// Create default terms for site_sections vocabulary.
|
||||
// Create default terms for the configured vocabulary.
|
||||
_structural_pages_create_default_terms();
|
||||
|
||||
// Display success message.
|
||||
@@ -21,10 +21,10 @@ function structural_pages_install(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates default terms for the site_sections vocabulary.
|
||||
* Creates default terms for the configured site section vocabulary.
|
||||
*/
|
||||
function _structural_pages_create_default_terms(): void {
|
||||
$vocabulary = 'site_sections';
|
||||
$vocabulary = _structural_pages_get_vocabulary();
|
||||
|
||||
// Check if terms already exist (avoid duplication on reinstall).
|
||||
$existing = \Drupal::entityQuery('taxonomy_term')
|
||||
@@ -210,10 +210,11 @@ function structural_pages_uninstall(): void {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove terms from site_sections vocabulary.
|
||||
// Remove terms from the configured vocabulary.
|
||||
$vocabulary = _structural_pages_get_vocabulary();
|
||||
$tids = \Drupal::entityQuery('taxonomy_term')
|
||||
->accessCheck(FALSE)
|
||||
->condition('vid', 'site_sections')
|
||||
->condition('vid', $vocabulary)
|
||||
->execute();
|
||||
if ($tids) {
|
||||
$terms = $entity_type_manager->getStorage('taxonomy_term')->loadMultiple($tids);
|
||||
@@ -227,7 +228,7 @@ function structural_pages_uninstall(): void {
|
||||
// Pathauto patterns.
|
||||
'pathauto.pattern.section_page',
|
||||
'pathauto.pattern.content_page',
|
||||
'pathauto.pattern.site_sections_term',
|
||||
'pathauto.pattern.' . $vocabulary . '_term',
|
||||
// Entity displays.
|
||||
'core.entity_form_display.node.section_page.default',
|
||||
'core.entity_view_display.node.section_page.default',
|
||||
@@ -246,7 +247,7 @@ function structural_pages_uninstall(): void {
|
||||
'node.type.section_page',
|
||||
'node.type.content_page',
|
||||
// Vocabulary.
|
||||
'taxonomy.vocabulary.site_sections',
|
||||
'taxonomy.vocabulary.' . $vocabulary,
|
||||
];
|
||||
|
||||
$config_factory = \Drupal::configFactory();
|
||||
@@ -290,15 +291,16 @@ function structural_pages_update_10003(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix content translation config and update site_sections term translations.
|
||||
* Fix content translation config and update term translations.
|
||||
*/
|
||||
function structural_pages_update_10004(): void {
|
||||
// Ensure content translation is properly configured for the vocabulary.
|
||||
_structural_pages_ensure_content_translation();
|
||||
|
||||
$vocabulary = _structural_pages_get_vocabulary();
|
||||
$terms = \Drupal::entityTypeManager()
|
||||
->getStorage('taxonomy_term')
|
||||
->loadByProperties(['vid' => 'site_sections']);
|
||||
->loadByProperties(['vid' => $vocabulary]);
|
||||
|
||||
if ($terms) {
|
||||
_structural_pages_add_term_translations($terms);
|
||||
@@ -306,14 +308,15 @@ function structural_pages_update_10004(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures content translation settings exist for site_sections vocabulary.
|
||||
* Ensures content translation settings exist for the configured vocabulary.
|
||||
*/
|
||||
function _structural_pages_ensure_content_translation(): void {
|
||||
if (!\Drupal::moduleHandler()->moduleExists('content_translation')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$config = \Drupal\language\Entity\ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', 'site_sections');
|
||||
$vocabulary = _structural_pages_get_vocabulary();
|
||||
$config = \Drupal\language\Entity\ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary);
|
||||
$config->setDefaultLangcode('site_default');
|
||||
$config->setLanguageAlterable(TRUE);
|
||||
$config->setThirdPartySetting('content_translation', 'enabled', TRUE);
|
||||
@@ -327,19 +330,20 @@ function structural_pages_requirements(string $phase): array {
|
||||
$requirements = [];
|
||||
|
||||
if ($phase === 'runtime') {
|
||||
// Check if site_sections vocabulary has terms.
|
||||
// Check if the configured vocabulary has terms.
|
||||
$vocabulary = _structural_pages_get_vocabulary();
|
||||
$term_count = \Drupal::entityQuery('taxonomy_term')
|
||||
->accessCheck(FALSE)
|
||||
->condition('vid', 'site_sections')
|
||||
->condition('vid', $vocabulary)
|
||||
->count()
|
||||
->execute();
|
||||
|
||||
if ($term_count === 0) {
|
||||
$requirements['structural_pages_terms'] = [
|
||||
'title' => t('Structural Pages'),
|
||||
'value' => t('No terms in site_sections vocabulary'),
|
||||
'description' => t('The Structural Pages module requires terms in the "Site Sections" vocabulary. <a href=":url">Add terms</a>.', [
|
||||
':url' => '/admin/structure/taxonomy/manage/site_sections/add',
|
||||
'value' => t('No terms in @vocabulary vocabulary', ['@vocabulary' => $vocabulary]),
|
||||
'description' => t('The Structural Pages module requires terms in the site section vocabulary. <a href=":url">Add terms</a>.', [
|
||||
':url' => '/admin/structure/taxonomy/manage/' . $vocabulary . '/add',
|
||||
]),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user