Problem/Motivation

I have a DAM metadata field mapped to the media name:

field_map:
  documentName: name

I'm using the acquiadam_asset_import submodule to import assets.

When a media is created by the import, the media name is always the file name from the DAM. That's because of this code: https://git.drupalcode.org/project/acquia_dam/-/blob/1.1.x/modules/acqui...

If I re-sync the metadata manually, the name gets corrected.

Steps to reproduce

Proposed resolution

Honor the field mapping during media creation via acquiadam_asset_import.

That would probably happen in AssetQueueService::filterAndFormatAsset()

https://git.drupalcode.org/project/acquia_dam/-/blob/1.1.x/modules/acqui...

Or maybe we don't even set the name? I think that would work for us since acquia_dam_media_presave would set the name. But what if the name isn't explicitly mapped? Is there some magic to set a default name?

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork acquia_dam-3580543

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

danflanagan8 created an issue. See original summary.

danflanagan8’s picture

A response to

Is there some magic to set a default name?

Maybe the Asset source plugin would need to be updated too? Such that the 'default_name' case of Asset::getMetadata considers the field_mapping configuration instead of using $asset['filename'];?

https://git.drupalcode.org/project/acquia_dam/-/blob/1.1.x/src/Plugin/me...

rajeshreeputra made their first commit to this issue’s fork.

rajeshreeputra’s picture

Status: Active » Needs review

Requesting review.

danflanagan8’s picture

Status: Needs review » Needs work

That fix looks reasonable. I applied the MR as a patch and confirmed that a newly imported asset has the expected name now. so that's good.

That said, I got a WSOD on the cron page:

The website encountered an unexpected error. Try again later.

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/docroot/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 433 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Render\FormattableMarkup::placeholderEscape() (Line: 211)
Drupal\Component\Render\FormattableMarkup::placeholderFormat() (Line: 195)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
strpos() (Line: 16)
Drupal\Core\Logger\LogMessageParser->parseMessagePlaceholders() (Line: 62)
Drupal\dblog\Logger\DbLog->log() (Line: 127)
Drupal\Core\Logger\LoggerChannel->log() (Line: 79)
Drupal\Core\Logger\LoggerChannel->info() (Line: 141)
Drupal\acquiadam_asset_import\Plugin\QueueWorker\AssetImporter->processItem() (Line: 208)
Drupal\Core\Cron->processQueue() (Line: 173)
Drupal\Core\Cron->processQueues() (Line: 100)
Drupal\Core\Cron->run() (Line: 175)

What was null? That code that creates the failing log looks like this:

    // Log the successful creation of the media item.
    $this->logger->info($this->t('DAM asset %file_name (asset ID: %asset_id) was created as a media item with ID: %media_id.', [
      '%file_name' => $data['file_name'],
      '%asset_id' => $data['asset_uuid'],
      '%media_id' => $media_entity->id(),
      'link' => $media_entity->toLink($this->t('View'))->toString(),
    ]));

After some debugging, I see that $data['file_name'] is the value that is somehow NULL. I also see a warning:

Warning: Undefined array key "documentName" in Drupal\acquiadam_asset_import\Services\AssetQueueService->filterAndFormatAsset() (line 351 of modules/contrib/acquia_dam/modules/acquiadam_asset_import/src/Services/AssetQueueService.php).

This is interesting because the patch "works" but it works for the wrong reason. It seems like the patch accidentally does what I suggested in comment #2. If we simply don't set the name in the queue worker, the correct default value gets applied.

I'm not exactly sure what the best thing to do is, but this is definitely NW.

danflanagan8’s picture

I dug a bit deeper and it looks like the $asset_data array in filterAndFormatAsset doesn't have any of the custom asset metadata.

Given that, I definitely suggest a less-is-more approach here. We simply shouldn't set the name when creating the media in the queue worker. We should just let all the other infrastructure in acquia_dam and core media deal with getting the name right.

danflanagan8’s picture

Status: Needs work » Needs review

I opened up a separate MR with my proposed fix. It's the less-is-more approach.

I tested this locally with good results. When I have a mapping for name, my imported media get the correct name. If I do not have a mapping for name, the file name ends up getting used.

rajeshreeputra’s picture

Thats reasonable. Rebased MR!279.

rajeshreeputra’s picture

Status: Needs review » Fixed

MR merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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