The JSON:API Cross Bundle module provide a NULL bundle value, which crashes jsonapi_schema

Error: Call to a member function label() on null in Drupal\jsonapi_schema\Controller\JsonApiSchemaController->getSchemaTitle() (line 310 of modules/contrib/jsonapi_schema/src/Controller/JsonApiSchemaController.php).

CommentFileSizeAuthor
#3 3091633-3.patch1.35 KBmglaman
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

mglaman created an issue. See original summary.

mglaman’s picture

This adjustment fixed the crash:

    $entity_type = $this->entityTypeManager->getDefinition($resource_type->getEntityTypeId());
    $entity_type_label = $schema_type === 'collection' ? $entity_type->getPluralLabel() : $entity_type->getSingularLabel();
    if ($resource_type->getBundle() !== NULL && $bundle_type = $entity_type->getBundleEntityType()) {
      $bundle = $this->entityTypeManager->getStorage($bundle_type)->load($resource_type->getBundle());
      return $this->t(rtrim('@bundle_label @entity_type_label'), [
        '@bundle_label' => Unicode::ucfirst($bundle->label()),
        '@entity_type_label' => $entity_type_label,
      ]);
    }

    return $this->t(rtrim('@entity_type_label'), [
      '@entity_type_label' => Unicode::ucfirst($entity_type_label),
    ]);
  }
mglaman’s picture

Status: Active » Needs review
StatusFileSize
new1.35 KB

Here is a patch. I know the plan is to use an array of resource types for cross bundle over a union, but this way it won't crash and returns some data.

Status: Needs review » Needs work

The last submitted patch, 3: 3091633-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bradjones1’s picture

Specifically this NW in the sense that the paths for these routes are broken (missing a slash after the jsonapi prefix) and the schema generation throws an exception for much the same reason as the title, e.g. there is no bundle. E.g., The "entity:profile:" plugin does not exist.

anybody’s picture

FYI: This is still one of the patches required for commerce_api so would be GREAT to finish
#3116465: Document recommended patches

anybody’s picture

Update: This is now the last patch required to make commerce_api fully work: #3116465: Document recommended patches

Still NW as of #5, but close to the finish line.

m.stenta’s picture

Issue tags: +Needs tests

We have automated testing now (#3257911: Add basic test coverage), so this will needs tests too.