Unhandled match case after D10 upgrade

Created on 9 October 2023, 9 months ago
Updated 22 October 2023, 8 months ago

Just when I thought everything was running great I found that after upgrading to D10, my computed field was missing completely. I also saw that my patch had been removed from composer.json

        "patches": {
            "drupal/core": {
                "computed base fields to work in Views": "https://git.drupalcode.org/project/drupal/-/merge_requests/4224.diff"
            }
        },

It wasn't any trouble adding the field back to the content type, then it showed back up in my view. But once I tried opening the book page with the computed field shown from the view, I got a blank page and this error:

UnhandledMatchError: Unhandled match case '...' in Drupal\computed_field\Entity\ComputedField->isDisplayConfigurable() (line 296 of /var/www/vhosts/mysite.com/website/web/modules/contrib/computed_field/src/Entity/ComputedField.php).

I know I named the field correctly, and my custom module to run it hasn't changed. If I remove it from the view, the error is gone. This exact setup was working on a test D10 site before, so I can't figure what changed.

Line #296 of /var/www/vhosts/mysite.com/website/web/modules/contrib/computed_field/src/Entity/ComputedField.php is:

  /**
   * {@inheritdoc}
   */
  public function isDisplayConfigurable($context) {
    return match ($context) {
      'view' => TRUE,
      'form' => FALSE,
    };
  }

What display variable is it looking for?

πŸ’¬ Support request
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States wxman

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

Comments & Activities

  • Issue created by @wxman
  • πŸ‡ΊπŸ‡ΈUnited States wxman
  • πŸ‡ΊπŸ‡ΈUnited States wxman
  • Status changed to Postponed: needs info 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    The docs for isDisplayConfigurable on D10 still say:

       * @param string $display_context
       *   The display context. Either 'view' or 'form'.
    

    Can you debug to see what value is getting passed in, and by who?

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @Joachim I tried to manually follow through the code but couldn't figure it out. I don't suppose you know a trick I can try?
    The other thing I can try is build a dummy site with nothing but Computed Field on it. Maybe that might show something.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Can you put a breakpoint in Drupal\computed_field\Entity\ComputedField->isDisplayConfigurable?

    Or failing that, a dsm(debug_backtrace())?

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @Joachim I'm working on setting up a debug on my regular site, but I've never had much luck making those work.

    I'm also still using:

            "patches": {
                "drupal/core": {
                    "computed base fields to work in Views": "https://git.drupalcode.org/project/drupal/-/merge_requests/4224.diff"
                }
            },

    I made a exact same setup on an empty D10 site with the same computed field, the exact same fields, the same custom module, patch, and nothing else. It's working perfectly. No errors. I'll keep working on trying to set up a debug on the regular site.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    If I just put a simple echo in the function:

      public function isDisplayConfigurable($context) {
    echo $context;
        return match ($context) {
          'view' => TRUE,
          'form' => FALSE,
        };
      }
    

    I got "viewviewviewviewviewview".

  • πŸ‡¬πŸ‡§United Kingdom joachim

    I have no idea. We need a backtrace to know what called it.

    > I got "viewviewviewviewviewview".

    If it's only ever called with 'view', then I don't understand how the match() fails.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @joachim To do a backtrace in D10 is it through the Devel, or the knit modules? I don't see it in that. I installed the Devel module but like I said, I never seen to find it showing the info I want. When I go to a book page it's just a white page with the php error at the top.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Just add 'dsm(debug_backtrace())' at the place where it crashses.

    > When I go to a book page it's just a white page with the php error at the top.

    Yes -- does it show a backtrace? If not, you need to configure the error level.

    What's knit BTW?

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @joachim I added it and got only this:

    ParseError: syntax error, unexpected identifier "view" in Composer\Autoload\{closure}() (line 298 of /var/www/host/website.com/newsite/web/modules/contrib/computed_field/src/Entity/ComputedField.php)

    If I comment out the function:

      public function isDisplayConfigurable($context) {
    	  dsm(debug_backtrace());
    /*	  
        return match ($context) {
         'view' => TRUE,
         'form' => FALSE,
        };
    */
      }
    

    I get a page of array's :

    array:34 [β–Ά]
    
    array:42 [β–Ά]
    
    array:39 [β–Ά]
    
    

    Each array is composed of a lot of sub arrays. Any idea what I'm looking for in there? I wish I could just leave the function commented out because it works fine like that.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    > ParseError: syntax error, unexpected identifier "view" in Composer\Autoload\{closure}() (line 298 of /var/www/host/website.com/newsite/web/modules/contrib/computed_field/src/Entity/ComputedField.php)

    You must have put it in the wrong place. It can't go inside the match{}.

    > Each array is composed of a lot of sub arrays. Any idea what I'm looking for in there?

    You need to read through the array. Each item is a step up the chain of calls that got us here. We need to know who called this with a crappy parameter.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @joachim >You need to read through the array. Each item is a step up the chain of calls that got us here. We need to know who called this with a crappy parameter.

    Can you give me a hint what to look for? There are A LOT of arrays!

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Ok so that call is ok:

        "args" => array:1 [β–Ό
          0 => "view"
        ]
    

    You need to check the final array before the crash.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @joachim I'm sorry for being inexperienced in this, but would that logically be at the bottom of the long list? There is around 300 of the arrays with more sub arrays.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    I found one that the 'view' is missing from the end

      0 => array:7 [β–Ό
        "file" => "/var/www/vhosts/theliterarytimes.com/newsite/web/modules/contrib/field_permissions/field_permissions.module"
        "line" => 36
        "function" => "isDisplayConfigurable"
        "class" => "Drupal\computed_field\Entity\ComputedField"
        "object" => Drupal\computed_field\Entity\ComputedField {#2240 β–Ό
          #entityTypeId: "computed_field"
          #enforceIsNew: null
          #typedData: null
          #cacheContexts: []
          #cacheTags: []
          #cacheMaxAge: -1
          #_serviceIds: []
          #_entityStorages: []
          #originalId: "node.book_page.computed_buy_amazon"
          #status: true
          #uuid: "794b4003-cd4a-4202-aca5-af1f2588ba57"
          -isUninstalling: false
          #langcode: "en"
          #third_party_settings: []
          #_core: []
          #trustedData: false
          #dependencies: array:2 [β–Ά]
          #isSyncing: false
          #id: "node.book_page.computed_buy_amazon"
          #field_name: "computed_buy_amazon"
          #field_type: null
          #entity_type: "node"
          #bundle: "book_page"
          #label: "Buy Amazon"
          #description: ""
          #settings: []
          #required: false
          #translatable: true
          #default_value: []
          #default_value_callback: ""
          #fieldStorage: null
          #itemDefinition: null
          #constraints: []
          #propertyConstraints: []
          #plugin_id: "buy_amazon_computedbuyamazon"
          #plugin_config: []
          #pluginCollection: Drupal\Core\Plugin\DefaultSingleLazyPluginCollection {#3238 β–Ό
            #pluginInstances: array:1 [ …1]
            #instanceIds: array:1 [ …1]
            #manager: Drupal\computed_field\ComputedFieldManager {#3243 …16}
            #configuration: []
            #instanceId: "buy_amazon_computedbuyamazon"
            #_serviceIds: []
            #_entityStorages: []
          }
        }
        "type" => "->"
        "args" => array:1 [β–Ό
          0 => "display"
        ]
      ]
    
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Ok so this is a bad value:

        "args" => array:1 [β–Ό
          0 => "display"
        ]
    

    And the bug looks like it's in field_permissions.module. The backtrace tells you the line. Look in there to see what the problem is.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @joachim I posted over in the Field Permissions issues. I can't find where this could be killing it, but it does look like something here doesn't like field permissions. Line #36 in field_permissions.module is:

    31  /**
    32   * Implements hook_entity_field_access().
    33   */
    34  function field_permissions_entity_field_access($operation, FieldDefinitionInterface $field_definition, $account, FieldItemListInterface $items = NULL) {
    35    $context = ($operation == 'view') ? 'display' : 'edit';
    36    if (!$field_definition->isDisplayConfigurable($context) || empty($items)) {
    37      return AccessResult::neutral();
    38    }
    39    $access_field = \Drupal::service('field_permissions.permissions_service')->getFieldAccess($operation, $items, $account, $field_definition);
    40  if (!$access_field) {
    41      return AccessResult::forbidden();
    42    }
    43    return AccessResult::neutral();
    44  }
    
  • πŸ‡¬πŸ‡§United Kingdom joachim

    This is the bug:

    35    $context = ($operation == 'view') ? 'display' : 'edit';
    36    if (!$field_definition->isDisplayConfigurable($context) || empty($items)) {
    

    Both these values assigned to $context are wrong! The docs say:

    > * The display context. Either 'view' or 'form'.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    Great. So this means it's a bug at Field Permissions?

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Yeah, because they only fixed half of it.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    Unfortunately that was the only issue that sounds like the problem. I posted there but I have no idea how fast they respond. I wish I could do without the module but I kind of need it.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    That issue IS the problem but it wasn't fixed properly.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @joachim I installed the DEV version of Field Permissions and Computed Field, and everything else, works with no errors.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Ok so is this issue fixed? Can you close it if that's the case?

  • Status changed to Fixed 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States wxman
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024