Problem/Motivation

Domain path logic is done in node form submission. Therefore, it does not act on contents created by other ways, such as via REST or programmatically.

Steps to reproduce

In a installation with the domain_path and domain_path_pathauto modules enabled and some pathauto pattern set, create a new content programmatically. The domain path alias is not created.

Proposed resolution

Move domain path logic to entity API based events, as pathauto does.

Remaining tasks

TBD.

User interface changes

None.

API changes

TBD.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

manuel.adan created an issue. See original summary.

quadrexdev’s picture

Assigned: Unassigned » quadrexdev

I think it makes sense and should be implemented. I'll work on it.

_tarik_’s picture

Hi quadrexdev
This module is used in one of my projects with JSON:API and has problems mentioned in the task description.
I plan to start work on this in the next few days. Would you mind assigning this issue to me?
I plan to do these steps to fix the problem:

  1. Create a field item and field widget objects for the domain path.
  2. Add code for altering base field info for entities that support domain path. I think it will be the same solution as we already have in the path auto module.
  3. Update the domain path auto module to make its fields available on the entity API level.
_tarik_’s picture

Hi, I have pushed part of the required changes that provide the ability to use domain path fields on the entity API level.
However, changes for the domain_pathauto aren't finished. We need to cover new code by tests and refactor it.
But that is the start of work on this issue.

mably’s picture

Assigned: quadrexdev » Unassigned

Created the related MR for better visibility of the work that has been done.

Looks like a significant change.

mably’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Active » Needs work
mably’s picture

Status: Needs work » Needs review

  • mably committed 7d852aea on 2.x
    feat: #3247423 Move domain path logic from node submit handler to entity...
mably’s picture

Status: Needs review » Fixed

Fixed in 2.x.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mably committed 6a8e5b27 on 2.x
    fix: #3247423 Move domain path logic from node submit handler to entity...
idebr’s picture

My local environment already had a number of base field overrides that tripped up field logic for 'path', for example:

core.base_field_override.node.page.path.yml

uuid: 01008d71-ae6a-431f-8137-5196c1da432e
langcode: en
status: true
dependencies:
  config:
    - node.type.page
  module:
    - path
id: node.page.path
field_name: path
entity_type: node
bundle: page
label: 'URL alias'
description: ''
required: false
translatable: false
default_value: {  }
default_value_callback: ''
settings: {  }
field_type: path

I'm not sure what triggers the creation of such base field override. However, the result was the domain_path widget was never applied and the node edit form triggered several warnings:

Warning: Undefined array key "domain_id" in Drupal\domain_path\DomainPathHelper->alterEntityForm() (line 71 of modules/contrib/domain_path/src/DomainPathHelper.php).
Warning: Trying to access array offset on null in Drupal\domain_path\DomainPathHelper->alterEntityForm() (line 71 of modules/contrib/domain_path/src/DomainPathHelper.php).
mably’s picture

Hi @idebr, could you give a try to this issue's MR?

#3564844: Switch to using the default core path_alias table instead of the custom domain_path one

I was required to add a weight of 10 to the domain_path module to have its hooks processed after those of the path module.

idebr’s picture

domain_path_entity_base_field_info correctly fires after the path module, but the base field override from #14 still take precedence. For bundles without base overrides, the code works correctly.

The relevant code from \Drupal\Core\Entity\EntityFieldManager::buildBundleFieldDefinitions that overrides the base field definition is here: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

Perhaps a more fool-proof approach is to add a property to the PathItem similar to pathauto? https://git.drupalcode.org/project/pathauto/-/blob/8.x-1.x/src/PathautoI...

Or rename the base field to 'domain_path' to prevent the clash altogether

mably’s picture

This field override is not new. How come you are getting hit now?

Can't you get rid of that override in #14?

mably’s picture

Looks like we should use the hook_entity_base_field_info_alter() hook.

mably’s picture

@idebr, could you give a try to MR 62 and tell me if it fixes your problem?

EDIT:

In fact, it doesn't work. Looks like we will have to use a custom field name like domain_path.

mably’s picture

MR 62 has been updated to use a new dedicated field name (domain_path). All tests are green.

Could you give it a try @idebr?

mably changed the visibility of the branch 3247423-move-domain-path-2.x to hidden.

mably changed the visibility of the branch 3247423-move-domain-path to hidden.

mably changed the visibility of the branch 3247423-widget-bug-fix to hidden.

  • mably committed 74c8bfb7 on 2.x
    feat: #3247423 Move domain path logic from node submit handler to entity...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.