Provide UI for pattern conditions

Created on 22 July 2021, about 4 years ago
Updated 9 February 2023, over 2 years ago

Problem/Motivation

Pathauto pattern uses Condition plugins, but doesn't provide user interface for their management (except for the basic ones controlled from the pattern form).

Proposed resolution

Provide UI for condition management.

Remaining tasks

  • Move condition UI to a sub-module.
  • Write tests?
  • Document API changes? Do we need a change record?

User interface changes

  • Separate UI is added for management of additional conditions on a pattern.
  • "Conditions" operation is added to the list on the pattern listing page.
  • Local tasks are added for easier switching between the pattern edit form and condition list.

API changes

Methods added:

  • \Drupal\pathauto\PathautoPatternInterface::getLockedSelectionConditionPluginIds()

Behavior changed:

  • \Drupal\pathauto\Entity\PathautoPattern::addSelectionCondition() doesn't override UUID of the condition if it already exists.

Data model changes

No.

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡΅πŸ‡ΉPortugal dmitriy.trt

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ͺπŸ‡ΈSpain dtamajon

    Hi, I'm interested in that feature but trying to figure out how to add custom conditions from a custom module, as I need to add conditions based on my custom fields.

    Do I have to follow some base class as in Rules module?

  • πŸ‡΅πŸ‡ΉPortugal joao.ramos.costa

    Hi @dtamajon you can create a class that extends ConditionPluginBase.
    Have a look https://drupalsun.com/2021/04/29/condition-plugins-visibility-drupal-8-9 . Cheers

  • πŸ‡ͺπŸ‡ΈSpain dtamajon

    Thank you!

  • πŸ‡ͺπŸ‡ΈSpain dtamajon

    I tried to add conditions successfully (custom ones and default ones) but on saving a node the alias is generated without calling any 'evaluate' function from any Condition.

    Am I missing something?

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels
  • Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update almost 2 years ago
    Not currently mergeable.
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    I had to fix a couple things to make it work on Drupal 10, but apart from that this feature seems to be working! @Berdir, could you comment on whether or not this feature should live in a submodule? That way we know how to move this forward. Since this feature has lived in this MR for two years already and it seems to be working great, I'm considering creating a new project for the submodule so that people can start using it.

  • πŸ‡³πŸ‡±Netherlands uberengineer

    Re-rolled patch 13 for Drupal 10

  • πŸ‡³πŸ‡±Netherlands uberengineer

    Patch #20 does not apply due to whitespace #21 applies

  • First commit to issue fork.
  • Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Not currently mergeable.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    27 pass, 4 fail
  • Pipeline finished with Failed
    over 1 year ago
    Total: 309s
    #117693
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    27 pass, 4 fail
  • Pipeline finished with Failed
    over 1 year ago
    Total: 335s
    #117701
  • πŸ‡¦πŸ‡ΊAustralia max.valetov

    Adds a D10 session check and set for subrequest to patch 21

  • πŸ‡¦πŸ‡ΊAustralia max.valetov

    Fixes patch formatting issue for patch 23

  • πŸ‡¦πŸ‡ΊAustralia max.valetov

    Fix 'non-scalar value' error - patches 21-24

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    This is fantastic! Thanks for working on this. I may have time to contribute as well.

    One change I think this needs is to disable the default, hard-coded conditions UI that pathauto already provides for specifying language and content type. I think that if this sub-module is used, then all conditions should be managed by it.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Please, let's keep all work in the merge request. The last three patch files are especially problematic because they don't include an interdiff.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    [double post]

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    27 pass, 4 fail
  • Pipeline finished with Failed
    over 1 year ago
    Total: 329s
    #154599
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    27 pass, 4 fail
  • Pipeline finished with Failed
    over 1 year ago
    Total: 317s
    #154608
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    27 pass, 4 fail
  • Pipeline finished with Failed
    over 1 year ago
    Total: 297s
    #154676
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    27 pass, 4 fail
  • Pipeline finished with Failed
    over 1 year ago
    Total: 302s
    #154680
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    While this is working well, it exposes a problem with the PathautoWidget that sort of makes it useless with any conditions that rely on pulling data from the entity.

    The form widget disables Pathauto if there isn't a matching pattern for the entity. The problem is that a pattern may not match an entity until the entity has been saved and has data.

    Until now, the only conditions a pathauto pattern could have were entity bundle and language, both of which are known even before an entity is saved, so this wasn't a problem.

    But now, with this, any type of condition can be added. For example, the Term Condition β†’ module provides a condition plugin that evaluates if an entity has a specific term associated with it.

    So, as a result, if you have a pattern with a "Page" content type condition and TermCondition for some taxonomy term "Term A", when you go to create a new Page node, the Pathauto checkbox won't be there and it won't be activated. If you save the node with a "Term A" reference, the pattern won't be activated. If you edit the node and save it again, it will be activated and the alias will be generated.

    To be clear, the conditions UI that this patch provides is working as expected, it just exposes some additional challenges with Pathauto.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    48 pass
  • Pipeline finished with Success
    over 1 year ago
    Total: 301s
    #156599
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    There seems to be an issue since the changes that were done in the past months: when updating an existing condition, it's being duplicated instead of the existing one being updated.

  • Pipeline finished with Canceled
    9 months ago
    Total: 73s
    #380496
  • Pipeline finished with Success
    9 months ago
    Total: 185s
    #380497
  • πŸ‡¬πŸ‡§United Kingdom siliconandincense

    Hi folks!

    Sorry for the beginner question but I don't have a huge amount of experience when it comes to anything more complicated than pulling in a patch.

    With the release of the pre-crimbo commits do I need to manually roll a patch myself from the HEAD of this branch to get this feature D11 ready, or is there another way to do it?

    Thanks for your patience!

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    You should click the "plain diff" link next to the merge request link (top of the issue on this page). It generates a git patch file. You should copy the contents of that into a plain text file in your project and include it with composer patches. Looks like it's already D11 compatible.

    The thing holding up this issue is the lack of tests.

Production build 0.71.5 2024