mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/structural_pages.git
synced 2026-05-04 13:10:41 -03:00
Adiciona field_menu_title e field_weight ao content_page
field_menu_title (string, 128 chars): - Título alternativo para exibição no menu de navegação - Quando preenchido, substitui o título da página no menu - Útil para abreviar títulos longos field_weight (integer, padrão 0): - Controla a ordenação de páginas com o mesmo pai - Valores menores aparecem primeiro; empate resolvido por título StructuralPagesMenuBlock: - Ordenação: field_weight ASC, título ASC (antes: só título) - Título no menu: field_menu_title se preenchido, senão label() Update 10014: cria os campos e atualiza o form display em instalações existentes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,9 +4,11 @@ status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.field.node.content_page.body
|
||||
- field.field.node.content_page.field_menu_title
|
||||
- field.field.node.content_page.field_parent_page
|
||||
- field.field.node.content_page.field_redirect_link
|
||||
- field.field.node.content_page.field_site_section
|
||||
- field.field.node.content_page.field_weight
|
||||
- node.type.content_page
|
||||
module:
|
||||
- dynamic_entity_reference
|
||||
@@ -81,6 +83,21 @@ content:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
field_menu_title:
|
||||
type: string_textfield
|
||||
weight: 1
|
||||
region: content
|
||||
settings:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
field_weight:
|
||||
type: number
|
||||
weight: 27
|
||||
region: content
|
||||
settings:
|
||||
placeholder: '0'
|
||||
third_party_settings: { }
|
||||
uid:
|
||||
type: entity_reference_autocomplete
|
||||
weight: 5
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
langcode: pt-br
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_menu_title
|
||||
- node.type.content_page
|
||||
entity_type: node
|
||||
field_name: field_menu_title
|
||||
bundle: content_page
|
||||
label: 'Título no menu'
|
||||
description: 'Título abreviado para o menu de navegação. Se vazio, usa o título da página.'
|
||||
required: false
|
||||
translatable: true
|
||||
default_value: {}
|
||||
default_value_callback: ''
|
||||
settings: {}
|
||||
field_type: string
|
||||
@@ -0,0 +1,22 @@
|
||||
langcode: pt-br
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_weight
|
||||
- node.type.content_page
|
||||
entity_type: node
|
||||
field_name: field_weight
|
||||
bundle: content_page
|
||||
label: 'Peso (ordenação)'
|
||||
description: 'Valores menores aparecem primeiro entre páginas com o mesmo pai. Padrão: 0.'
|
||||
required: false
|
||||
translatable: false
|
||||
default_value:
|
||||
- value: 0
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
min: ''
|
||||
max: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
field_type: integer
|
||||
17
config/install/field.storage.node.field_menu_title.yml
Normal file
17
config/install/field.storage.node.field_menu_title.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies: {}
|
||||
entity_type: node
|
||||
field_name: field_menu_title
|
||||
type: string
|
||||
settings:
|
||||
max_length: 128
|
||||
is_ascii: false
|
||||
case_sensitive: false
|
||||
module: core
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: {}
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
||||
16
config/install/field.storage.node.field_weight.yml
Normal file
16
config/install/field.storage.node.field_weight.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies: {}
|
||||
entity_type: node
|
||||
field_name: field_weight
|
||||
type: integer
|
||||
settings:
|
||||
unsigned: false
|
||||
size: normal
|
||||
module: core
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: false
|
||||
indexes: {}
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
||||
@@ -351,10 +351,14 @@ class StructuralPagesMenuBlock extends BlockBase implements ContainerFactoryPlug
|
||||
}
|
||||
}
|
||||
|
||||
$menu_title = ($node->hasField('field_menu_title') && !$node->get('field_menu_title')->isEmpty())
|
||||
? $node->get('field_menu_title')->value
|
||||
: $node->label();
|
||||
|
||||
$branch = [
|
||||
'entity' => $node,
|
||||
'id' => $node->id(),
|
||||
'title' => $node->label(),
|
||||
'title' => $menu_title,
|
||||
'url' => $url,
|
||||
'is_redirect' => $is_redirect,
|
||||
'depth' => $current_depth,
|
||||
@@ -425,6 +429,7 @@ class StructuralPagesMenuBlock extends BlockBase implements ContainerFactoryPlug
|
||||
->accessCheck(TRUE)
|
||||
->condition('type', 'content_page')
|
||||
->condition('status', 1)
|
||||
->sort('field_weight', 'ASC')
|
||||
->sort('title', 'ASC');
|
||||
|
||||
if ($parent_type === 'node') {
|
||||
|
||||
@@ -845,3 +845,81 @@ function structural_pages_requirements(string $phase): array {
|
||||
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adiciona field_menu_title e field_weight ao tipo content_page.
|
||||
*/
|
||||
function structural_pages_update_10014(): string {
|
||||
$etm = \Drupal::entityTypeManager();
|
||||
|
||||
// --- field_menu_title ---
|
||||
if (!\Drupal\field\Entity\FieldStorageConfig::loadByName('node', 'field_menu_title')) {
|
||||
\Drupal\field\Entity\FieldStorageConfig::create([
|
||||
'field_name' => 'field_menu_title',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'string',
|
||||
'settings' => ['max_length' => 128],
|
||||
'cardinality' => 1,
|
||||
'translatable' => TRUE,
|
||||
])->save();
|
||||
}
|
||||
if (!\Drupal\field\Entity\FieldConfig::loadByName('node', 'content_page', 'field_menu_title')) {
|
||||
\Drupal\field\Entity\FieldConfig::create([
|
||||
'field_name' => 'field_menu_title',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'content_page',
|
||||
'label' => 'Título no menu',
|
||||
'description' => 'Título abreviado para o menu de navegação. Se vazio, usa o título da página.',
|
||||
'required' => FALSE,
|
||||
'translatable' => TRUE,
|
||||
])->save();
|
||||
}
|
||||
|
||||
// --- field_weight ---
|
||||
if (!\Drupal\field\Entity\FieldStorageConfig::loadByName('node', 'field_weight')) {
|
||||
\Drupal\field\Entity\FieldStorageConfig::create([
|
||||
'field_name' => 'field_weight',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'integer',
|
||||
'cardinality' => 1,
|
||||
'translatable' => FALSE,
|
||||
])->save();
|
||||
}
|
||||
if (!\Drupal\field\Entity\FieldConfig::loadByName('node', 'content_page', 'field_weight')) {
|
||||
\Drupal\field\Entity\FieldConfig::create([
|
||||
'field_name' => 'field_weight',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'content_page',
|
||||
'label' => 'Peso (ordenação)',
|
||||
'description' => 'Valores menores aparecem primeiro entre páginas com o mesmo pai. Padrão: 0.',
|
||||
'required' => FALSE,
|
||||
'translatable' => FALSE,
|
||||
'default_value' => [['value' => 0]],
|
||||
])->save();
|
||||
}
|
||||
|
||||
// Adiciona os campos ao form display padrão.
|
||||
$form_display = $etm->getStorage('entity_form_display')
|
||||
->load('node.content_page.default');
|
||||
if ($form_display) {
|
||||
if (!$form_display->getComponent('field_menu_title')) {
|
||||
$form_display->setComponent('field_menu_title', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => 1,
|
||||
'region' => 'content',
|
||||
'settings' => ['size' => 60, 'placeholder' => ''],
|
||||
]);
|
||||
}
|
||||
if (!$form_display->getComponent('field_weight')) {
|
||||
$form_display->setComponent('field_weight', [
|
||||
'type' => 'number',
|
||||
'weight' => 27,
|
||||
'region' => 'content',
|
||||
'settings' => ['placeholder' => '0'],
|
||||
]);
|
||||
}
|
||||
$form_display->save();
|
||||
}
|
||||
|
||||
return 'Campos field_menu_title e field_weight adicionados ao content_page.';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user