Comments

Berdir created an issue. See original summary.

juampynr’s picture

@Berdir, I am not sure at how to tackle this one. It seems that we would have to add a bunch of if statements at PatternEditForm and PathautoTestHelperTrait. It can get very complex to read. Do you have any tips?

juampynr’s picture

Status: Active » Needs review
StatusFileSize
new1.74 KB

Interesting, the first version of the patch looks simpler than what I thought. I will now work in tests and the update path while tests run here.

juampynr’s picture

StatusFileSize
new3.14 KB

Here is another patch with a database update. Should we add any tests @berdir? I am not sure that we need them.

berdir’s picture

Status: Needs review » Needs work

Yeah, that doesn't look too complicated. My suggestion in IRC was to use a helper function, but considering that this is so easy and only a single place actually needs to be dynamic, I'd say this is fine.

However, note that you missed one spot, a helper method in the tests, where we create entity bundle conditions dynamically.

  1. +++ b/pathauto.install
    @@ -216,3 +216,34 @@ function pathauto_update_8101() {
    +  // Load all patterns that apply to nodes.
    +  $pattern_ids = \Drupal::entityQuery('pathauto_pattern')->condition('type', 'canonical_entities:node')->execute();
    +  $pattern_entities = PathautoPattern::loadMultiple($pattern_ids);
    

    This is not something that we've done so far, but note that it is problematic to use the entity API in update functions.

    Imagine we'd add a new feature that runs in PathautoPattern::postSave() and it would require different or new configuration that we, in this update, don't have yet.

    Then someone might update directly from alpha1 to beta3 or whatever and will run this update with the latest code base.

    The way to avoid this is to use the config API directly and work on the raw config structure. Or, alternatively, you could also write a post update function, those are always run after all other update functions were run and after caches were cleared. There it's allowed to use entity API.

    That said, we still are in alpha, and I'd still say our upgrade path support is on a best effort basis and that we'd simply not support updating such an old version directly to whatever future version would introduce that change.

    But it's something to consider in future update functions.

  2. +++ b/pathauto.install
    @@ -216,3 +216,34 @@ function pathauto_update_8101() {
    +        // We found the entity bundle condition. Swap it by a node type one.
    

    "swap it to the node_type plugin". I'd say.

  3. +++ b/src/Form/PatternEditForm.php
    @@ -211,17 +211,19 @@ class PatternEditForm extends EntityForm {
    +        $plugin_id = $entity_type == 'node'
    +          ? 'node_type'
    +          : 'entity_bundle:' . $entity_type;
    

    I think ternary conditions like this are usually written on a single line.

juampynr’s picture

Status: Needs work » Needs review
StatusFileSize
new3.4 KB
new3.49 KB

Thanks for the feedback @berdir. Here is a new patch with your suggestions.

  • Berdir committed 728d569 on 8.x-1.x authored by juampynr
    Issue #2669758 by juampynr: Switch bundle condition for nodes to...
berdir’s picture

Status: Needs review » Fixed

Nice work. Tested the upgrade path manually, all looks good.

Status: Fixed » Closed (fixed)

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