I am getting the following error when trying to synchronise remote entities:

 [error]  Error: Call to a member function getPublicName() on null in Drupal\entity_share_client\Service\JsonapiHelper->handlePhysicalFiles() (line 342 of /home/www-data/dev.nat/web/modules/contrib/entity_share/modules/entity_share_client/src/Service/JsonapiHelper.php) #0 /home/www-data/dev.nat/web/modules/contrib/entity_share/modules/entity_share_client/src/Service/JsonapiHelper.php(499): Drupal\entity_share_client\Service\JsonapiHelper->handlePhysicalFiles(Object(Drupal\file_entity\Entity\FileEntity), Array)

The error occurs here:

  /**
   * {@inheritdoc}
   */
  public function handlePhysicalFiles(ContentEntityInterface $entity, array &$data) {
    if ($entity instanceof FileInterface) {
      $resource_type = $this->resourceTypeRepository->get(
        'file',      // entity_type_id
        'file'       // bundle
      );
      $uri_public_name = $resource_type->getPublicName('uri');

The error is caused by the hardcoded values for entity_type_id and bundle. In my case the entity type is `file` and bundle `image`. As there was no entity of type `file` and bundle `file`, the $resource_type was NULL and an error would occur.

This patch removes the hardcoded values for entity_type_id & bundle and obtains them from the entity instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

msti created an issue. See original summary.

msti’s picture

msti’s picture

Status: Active » Needs review
Grimreaper’s picture

Hi @msti,

Thanks for the bug report and the patch.

Are you using the file_entity module on your websites?

msti’s picture

Hi Grimreaper
Yes we are kind of stuck with the the file_entity module

Grimreaper’s picture

Assigned: Unassigned » Grimreaper

Thanks @msti for the reply.

Yes, as you said "stuck", the file_entity module is deprecated so if there won't be any support in the entity share module dedicated to that.

But as it is a small change still compatible with standard file entity in Core, no problem. I am currently testing with the tests in the patch from #3072238-4: Tests: file field (entity reference).

If it is ok I will merge your patch.

  • msti authored 48b3888 on 8.x-2.x
    Issue #3088307 by msti, Grimreaper: Compatibility with file_entity...
Grimreaper’s picture

Title: Properly identify file entities » Compatibility with file_entity module
Assigned: Grimreaper » Unassigned
Category: Bug report » Feature request
Status: Needs review » Fixed

Tests green!

Patch merged!

Thanks for your contribution!

Status: Fixed » Closed (fixed)

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