mirror of
https://gitlab.unicamp.br/infimecc_drupal11_modules/structural_pages.git
synced 2026-03-09 18:07:42 -03:00
Initial commit: Site Structure module for Drupal
Drupal module that provides hierarchical site structure management with support for sections, categories, and content items. Includes path aliases with tokens, breadcrumb integration, and admin interface. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
320
src/Breadcrumb/SectionBreadcrumbBuilder.php
Normal file
320
src/Breadcrumb/SectionBreadcrumbBuilder.php
Normal file
@@ -0,0 +1,320 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\site_structure\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Breadcrumb\Breadcrumb;
|
||||
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* Provides a breadcrumb builder for section_page and content_page content types.
|
||||
*/
|
||||
class SectionBreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected EntityTypeManagerInterface $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Content types that this builder applies to.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected array $applicableBundles = ['section_page', 'content_page'];
|
||||
|
||||
/**
|
||||
* Constructs a SectionBreadcrumbBuilder object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applies(RouteMatchInterface $route_match): bool {
|
||||
$node = $route_match->getParameter('node');
|
||||
|
||||
if ($node instanceof NodeInterface) {
|
||||
return in_array($node->bundle(), $this->applicableBundles, TRUE);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(RouteMatchInterface $route_match): Breadcrumb {
|
||||
$breadcrumb = new Breadcrumb();
|
||||
$breadcrumb->addCacheContexts(['route']);
|
||||
|
||||
$node = $route_match->getParameter('node');
|
||||
|
||||
if (!$node instanceof NodeInterface) {
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
$breadcrumb->addCacheableDependency($node);
|
||||
|
||||
// Add "Home" as first item.
|
||||
$breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
|
||||
|
||||
// Determine the context type for content_page.
|
||||
$context = $this->getParentContext($node);
|
||||
|
||||
if ($context) {
|
||||
switch ($context['type']) {
|
||||
case 'user':
|
||||
// User context: Home > User Name > ... > Current Page.
|
||||
$this->addUserBreadcrumb($breadcrumb, $context['entity']);
|
||||
break;
|
||||
|
||||
case 'group':
|
||||
// Group context: Home > Group Name > ... > Current Page.
|
||||
$this->addGroupBreadcrumb($breadcrumb, $context['entity']);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Node or taxonomy context: use site section.
|
||||
if ($node->hasField('field_site_section') && !$node->get('field_site_section')->isEmpty()) {
|
||||
$term_id = $node->get('field_site_section')->target_id;
|
||||
$this->addTaxonomyBreadcrumbs($breadcrumb, $term_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// No parent context, check for site section directly.
|
||||
if ($node->hasField('field_site_section') && !$node->get('field_site_section')->isEmpty()) {
|
||||
$term_id = $node->get('field_site_section')->target_id;
|
||||
$this->addTaxonomyBreadcrumbs($breadcrumb, $term_id);
|
||||
}
|
||||
}
|
||||
|
||||
// For content_page, add node parent hierarchy.
|
||||
if ($node->bundle() === 'content_page') {
|
||||
$this->addParentBreadcrumbs($breadcrumb, $node);
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the root parent context for a content_page.
|
||||
*
|
||||
* Traverses up the parent chain to find the root context (user, group, or taxonomy).
|
||||
*
|
||||
* @param \Drupal\node\NodeInterface $node
|
||||
* The content_page node.
|
||||
*
|
||||
* @return array|null
|
||||
* An array with 'type' and 'entity' keys, or NULL if no context.
|
||||
*/
|
||||
protected function getParentContext(NodeInterface $node): ?array {
|
||||
if ($node->bundle() !== 'content_page') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$visited = [];
|
||||
$current = $node;
|
||||
|
||||
while ($current instanceof NodeInterface &&
|
||||
$current->hasField('field_parent_page') &&
|
||||
!$current->get('field_parent_page')->isEmpty()) {
|
||||
|
||||
$parent_field = $current->get('field_parent_page')->first();
|
||||
if (!$parent_field) {
|
||||
break;
|
||||
}
|
||||
|
||||
$parent_entity_type = $parent_field->target_type ?? NULL;
|
||||
$parent_id = $parent_field->target_id ?? NULL;
|
||||
|
||||
if (!$parent_entity_type || !$parent_id) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Avoid infinite loops.
|
||||
$visit_key = $parent_entity_type . ':' . $parent_id;
|
||||
if (isset($visited[$visit_key])) {
|
||||
break;
|
||||
}
|
||||
$visited[$visit_key] = TRUE;
|
||||
|
||||
$parent = $this->entityTypeManager
|
||||
->getStorage($parent_entity_type)
|
||||
->load($parent_id);
|
||||
|
||||
if (!$parent) {
|
||||
break;
|
||||
}
|
||||
|
||||
// If parent is user or group, that's our context.
|
||||
if (in_array($parent_entity_type, ['user', 'group'])) {
|
||||
return [
|
||||
'type' => $parent_entity_type,
|
||||
'entity' => $parent,
|
||||
];
|
||||
}
|
||||
|
||||
// If parent is taxonomy_term, that's our context (handled via site_section).
|
||||
if ($parent_entity_type === 'taxonomy_term') {
|
||||
return [
|
||||
'type' => 'taxonomy_term',
|
||||
'entity' => $parent,
|
||||
];
|
||||
}
|
||||
|
||||
// If parent is a node, continue traversing.
|
||||
if ($parent instanceof NodeInterface) {
|
||||
$current = $parent;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds user breadcrumb.
|
||||
*
|
||||
* @param \Drupal\Core\Breadcrumb\Breadcrumb $breadcrumb
|
||||
* The breadcrumb object.
|
||||
* @param \Drupal\Core\Entity\EntityInterface $user
|
||||
* The user entity.
|
||||
*/
|
||||
protected function addUserBreadcrumb(Breadcrumb $breadcrumb, EntityInterface $user): void {
|
||||
$breadcrumb->addCacheableDependency($user);
|
||||
$breadcrumb->addLink($user->toLink());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds group breadcrumb.
|
||||
*
|
||||
* @param \Drupal\Core\Breadcrumb\Breadcrumb $breadcrumb
|
||||
* The breadcrumb object.
|
||||
* @param \Drupal\Core\Entity\EntityInterface $group
|
||||
* The group entity.
|
||||
*/
|
||||
protected function addGroupBreadcrumb(Breadcrumb $breadcrumb, EntityInterface $group): void {
|
||||
$breadcrumb->addCacheableDependency($group);
|
||||
$breadcrumb->addLink($group->toLink());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds breadcrumbs based on taxonomy hierarchy.
|
||||
*
|
||||
* @param \Drupal\Core\Breadcrumb\Breadcrumb $breadcrumb
|
||||
* The breadcrumb object.
|
||||
* @param int|string $term_id
|
||||
* The taxonomy term ID.
|
||||
*/
|
||||
protected function addTaxonomyBreadcrumbs(Breadcrumb $breadcrumb, int|string $term_id): void {
|
||||
$term_storage = $this->entityTypeManager->getStorage('taxonomy_term');
|
||||
$ancestors = $term_storage->loadAllParents($term_id);
|
||||
$ancestors = array_reverse($ancestors);
|
||||
|
||||
foreach ($ancestors as $ancestor) {
|
||||
$breadcrumb->addCacheableDependency($ancestor);
|
||||
$breadcrumb->addLink($ancestor->toLink());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds breadcrumbs based on content_page parent hierarchy.
|
||||
*
|
||||
* Only adds node parents to the breadcrumb, not user/group/taxonomy
|
||||
* which are handled separately.
|
||||
*
|
||||
* @param \Drupal\Core\Breadcrumb\Breadcrumb $breadcrumb
|
||||
* The breadcrumb object.
|
||||
* @param \Drupal\node\NodeInterface $node
|
||||
* The current node.
|
||||
*/
|
||||
protected function addParentBreadcrumbs(Breadcrumb $breadcrumb, NodeInterface $node): void {
|
||||
$parents = $this->getNodeParents($node);
|
||||
$parents = array_reverse($parents);
|
||||
|
||||
foreach ($parents as $parent) {
|
||||
$breadcrumb->addCacheableDependency($parent);
|
||||
$breadcrumb->addLink($parent->toLink());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all node parents of a content_page.
|
||||
*
|
||||
* Stops when encountering a non-node parent (user, group, taxonomy_term).
|
||||
*
|
||||
* @param \Drupal\node\NodeInterface $node
|
||||
* The node.
|
||||
*
|
||||
* @return \Drupal\node\NodeInterface[]
|
||||
* Array of parent nodes, from closest to farthest.
|
||||
*/
|
||||
protected function getNodeParents(NodeInterface $node): array {
|
||||
$parents = [];
|
||||
$visited = [];
|
||||
$current = $node;
|
||||
|
||||
while ($current instanceof NodeInterface &&
|
||||
$current->hasField('field_parent_page') &&
|
||||
!$current->get('field_parent_page')->isEmpty()) {
|
||||
|
||||
$parent_field = $current->get('field_parent_page')->first();
|
||||
if (!$parent_field) {
|
||||
break;
|
||||
}
|
||||
|
||||
$parent_entity_type = $parent_field->target_type ?? NULL;
|
||||
$parent_id = $parent_field->target_id ?? NULL;
|
||||
|
||||
if (!$parent_entity_type || !$parent_id) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Only continue if parent is a node.
|
||||
if ($parent_entity_type !== 'node') {
|
||||
break;
|
||||
}
|
||||
|
||||
// Avoid infinite loops.
|
||||
if (isset($visited[$parent_id])) {
|
||||
break;
|
||||
}
|
||||
$visited[$parent_id] = TRUE;
|
||||
|
||||
$parent = $this->entityTypeManager
|
||||
->getStorage('node')
|
||||
->load($parent_id);
|
||||
|
||||
if (!$parent instanceof NodeInterface) {
|
||||
break;
|
||||
}
|
||||
|
||||
$parents[] = $parent;
|
||||
$current = $parent;
|
||||
}
|
||||
|
||||
return $parents;
|
||||
}
|
||||
|
||||
}
|
||||
319
src/Form/SiteStructureSettingsForm.php
Normal file
319
src/Form/SiteStructureSettingsForm.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\site_structure\Form;
|
||||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Configuration form for Site Structure module.
|
||||
*/
|
||||
class SiteStructureSettingsForm extends ConfigFormBase {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected EntityTypeManagerInterface $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity type bundle info service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
||||
*/
|
||||
protected EntityTypeBundleInfoInterface $entityTypeBundleInfo;
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected ModuleHandlerInterface $moduleHandler;
|
||||
|
||||
/**
|
||||
* Entity types that can be used as parents.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected array $supportedEntityTypes = [
|
||||
'node' => 'Content Types (node)',
|
||||
'taxonomy_term' => 'Taxonomy Vocabularies (taxonomy_term)',
|
||||
'user' => 'Users (user)',
|
||||
'group' => 'Groups (group)',
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructs a SiteStructureSettingsForm object.
|
||||
*
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The factory for configuration objects.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
|
||||
* The entity type bundle info service.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigFactoryInterface $config_factory,
|
||||
EntityTypeManagerInterface $entity_type_manager,
|
||||
EntityTypeBundleInfoInterface $entity_type_bundle_info,
|
||||
ModuleHandlerInterface $module_handler,
|
||||
) {
|
||||
parent::__construct($config_factory);
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityTypeBundleInfo = $entity_type_bundle_info;
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container): static {
|
||||
return new static(
|
||||
$container->get('config.factory'),
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('entity_type.bundle.info'),
|
||||
$container->get('module_handler'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId(): string {
|
||||
return 'site_structure_settings_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEditableConfigNames(): array {
|
||||
return ['site_structure.settings'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state): array {
|
||||
$config = $this->config('site_structure.settings');
|
||||
$allowed_targets = $config->get('allowed_parent_targets') ?? [];
|
||||
|
||||
// Build a keyed array for easier lookup.
|
||||
$enabled_targets = [];
|
||||
foreach ($allowed_targets as $target) {
|
||||
$key = $target['entity_type'] . ':' . $target['bundle'];
|
||||
$enabled_targets[$key] = TRUE;
|
||||
// Handle wildcard bundles.
|
||||
if ($target['bundle'] === '*') {
|
||||
$enabled_targets[$target['entity_type'] . ':*'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
$form['description'] = [
|
||||
'#type' => 'markup',
|
||||
'#markup' => '<p>' . $this->t('Select which entity types and bundles can be used as parent for Content Page nodes. This allows creating hierarchical structures where content pages can be children of different entity types.') . '</p>',
|
||||
];
|
||||
|
||||
$form['context_info'] = [
|
||||
'#type' => 'markup',
|
||||
'#markup' => '<p>' . $this->t('<strong>Context behavior:</strong><br>
|
||||
- <em>Node/Taxonomy</em>: Content pages inherit the site section from the parent.<br>
|
||||
- <em>User</em>: Content pages are associated with the user profile page.<br>
|
||||
- <em>Group</em>: Content pages are associated with the group.') . '</p>',
|
||||
];
|
||||
|
||||
$form['allowed_parent_targets'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $this->t('Allowed Parent Targets'),
|
||||
'#tree' => TRUE,
|
||||
];
|
||||
|
||||
foreach ($this->supportedEntityTypes as $entity_type => $label) {
|
||||
// Check if entity type exists.
|
||||
if (!$this->entityTypeManager->hasDefinition($entity_type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Special handling for 'group' - check if module is enabled.
|
||||
if ($entity_type === 'group' && !$this->moduleHandler->moduleExists('group')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$form['allowed_parent_targets'][$entity_type] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t($label),
|
||||
'#open' => TRUE,
|
||||
];
|
||||
|
||||
// User entity type typically has only one bundle.
|
||||
if ($entity_type === 'user') {
|
||||
$key = 'user:user';
|
||||
$form['allowed_parent_targets'][$entity_type]['user'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('User accounts'),
|
||||
'#description' => $this->t('Allow content pages to be children of user profiles.'),
|
||||
'#default_value' => isset($enabled_targets[$key]),
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type);
|
||||
|
||||
// For groups, add an "all types" option.
|
||||
if ($entity_type === 'group') {
|
||||
$key = 'group:*';
|
||||
$form['allowed_parent_targets'][$entity_type]['_all'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('All group types'),
|
||||
'#description' => $this->t('Allow all current and future group types as parents.'),
|
||||
'#default_value' => isset($enabled_targets[$key]),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($bundles as $bundle_id => $bundle_info) {
|
||||
$key = $entity_type . ':' . $bundle_id;
|
||||
$form['allowed_parent_targets'][$entity_type][$bundle_id] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $bundle_info['label'],
|
||||
'#default_value' => isset($enabled_targets[$key]),
|
||||
];
|
||||
|
||||
// If "all group types" is selected, disable individual checkboxes.
|
||||
if ($entity_type === 'group') {
|
||||
$form['allowed_parent_targets'][$entity_type][$bundle_id]['#states'] = [
|
||||
'disabled' => [
|
||||
':input[name="allowed_parent_targets[group][_all]"]' => ['checked' => TRUE],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state): void {
|
||||
$targets = [];
|
||||
$values = $form_state->getValue('allowed_parent_targets');
|
||||
|
||||
foreach ($this->supportedEntityTypes as $entity_type => $label) {
|
||||
if (empty($values[$entity_type])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle "all group types" wildcard.
|
||||
if ($entity_type === 'group' && !empty($values[$entity_type]['_all'])) {
|
||||
$targets[] = [
|
||||
'entity_type' => 'group',
|
||||
'bundle' => '*',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($values[$entity_type] as $bundle => $enabled) {
|
||||
// Skip the special "_all" key for groups if not enabled.
|
||||
if ($bundle === '_all') {
|
||||
continue;
|
||||
}
|
||||
if ($enabled) {
|
||||
$targets[] = [
|
||||
'entity_type' => $entity_type,
|
||||
'bundle' => $bundle,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->config('site_structure.settings')
|
||||
->set('allowed_parent_targets', $targets)
|
||||
->save();
|
||||
|
||||
// Update field configuration to reflect new targets.
|
||||
$this->updateFieldConfiguration($targets);
|
||||
|
||||
parent::submitForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the field_parent_page configuration with new targets.
|
||||
*
|
||||
* @param array $targets
|
||||
* The allowed targets.
|
||||
*/
|
||||
protected function updateFieldConfiguration(array $targets): void {
|
||||
$field_config = $this->entityTypeManager
|
||||
->getStorage('field_config')
|
||||
->load('node.content_page.field_parent_page');
|
||||
|
||||
if (!$field_config) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = $field_config->getSettings();
|
||||
|
||||
// Build the entity type settings for dynamic_entity_reference.
|
||||
$entity_type_ids = [];
|
||||
$entity_type_settings = [];
|
||||
|
||||
foreach ($targets as $target) {
|
||||
$entity_type = $target['entity_type'];
|
||||
$bundle = $target['bundle'];
|
||||
|
||||
if (!in_array($entity_type, $entity_type_ids)) {
|
||||
$entity_type_ids[] = $entity_type;
|
||||
}
|
||||
|
||||
if (!isset($entity_type_settings[$entity_type])) {
|
||||
$sort_field = match($entity_type) {
|
||||
'taxonomy_term' => 'name',
|
||||
'user' => 'name',
|
||||
'group' => 'label',
|
||||
default => 'title',
|
||||
};
|
||||
|
||||
$entity_type_settings[$entity_type] = [
|
||||
'handler' => 'default:' . $entity_type,
|
||||
'handler_settings' => [
|
||||
'target_bundles' => [],
|
||||
'sort' => [
|
||||
'field' => $sort_field,
|
||||
'direction' => 'asc',
|
||||
],
|
||||
'auto_create' => FALSE,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Handle wildcard bundles.
|
||||
if ($bundle === '*') {
|
||||
$entity_type_settings[$entity_type]['handler_settings']['target_bundles'] = NULL;
|
||||
}
|
||||
elseif ($entity_type_settings[$entity_type]['handler_settings']['target_bundles'] !== NULL) {
|
||||
$entity_type_settings[$entity_type]['handler_settings']['target_bundles'][$bundle] = $bundle;
|
||||
}
|
||||
}
|
||||
|
||||
$settings['entity_type_ids'] = $entity_type_ids;
|
||||
foreach ($entity_type_settings as $entity_type => $type_settings) {
|
||||
$settings[$entity_type] = $type_settings;
|
||||
}
|
||||
|
||||
$field_config->setSettings($settings);
|
||||
$field_config->save();
|
||||
|
||||
$this->messenger()->addStatus($this->t('Field configuration updated successfully.'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user