How to fill a file field with a new media:document?

Created on 29 May 2024, 29 days ago
Updated 19 June 2024, 9 days ago

Problem/Motivation

My goal is to create a new content node (X) for each new media document (Y) that is created.

I've successfully added four actions to the event that's triggered when (Y) is uploaded.

(1) Create new content of type Doc (this will be X above)
(2) Fill text field of (X) with token: media:name
(3) Fill Media Document field of Doc with (Y)
(4) Publish (X).

Of these four actions, three work fine: 1,2 and 4.

But I've tried these tokens to fill in the media document field of (X) with (Y):
[media:original]
[media:field_media_document]

I don't get an error in the logs. I just get the created published content with the text field filled with the correct file name. But the media document field is empty.

Any suggestions?

Sorry to bother you. This is quite a nice module.

TIA.

πŸ’¬ Support request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bogdog400

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

Comments & Activities

  • Issue created by @bogdog400
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    What's the event you're starting your model with?

    Note, the media entity must have been saved before it can be added to a node.

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

    I'm starting with: Event: Insert content entity.

    I've attached two screenshots of the pages listing the event and the actions. Of the actions, it seems like (1),(2) and (4) work fine.

    So any suggestions for (3) would be most appreciated.

    TIA.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Why is the action Publish content item in step 4 needed? Your node is already set to published in step 1, so you don't have to publish again. And it could well be that this step overrides your changes from step 3.

    If you remove step 4, let's see what happens. If that doesn't work, we need to know what the token in step 3 is exactly. The screenshot doesn't show that completely.

    And last but not least: using the classic modeller is not recommended. And providing support for users who do is limited, since we can import models for support purposes. You should really consider using the bpmn_io modeller.

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

    Okay. Deleted (4) and it worked as before. So you're right that it wasn't necessary. But it wasn't the problem with (3).

    For the token in (3), I've tried several:

    [media:field_media_document:entity]
    [media:field_media_document]
    [media:field_media_document:entity:original]

    There are others that might work. Some, for instance, start with "file:". Do you recommend I try them?

    Thanks again for your help.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    So, the destination field is a file field, right? Or is it a media field?

    In any case, it's an entity reference and you may have to provide a value which is either the entity that should go into that reference or the entity id of that referenced entity. If none of that does help, then it needs to be debugged. You can either try to do that with xdebug or you could create a simplified model and export that for detailed review, so that we can reproduce the problem.

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

    The destination field is a media field of type document.

    (There's some potential for confusion here because I foolishly labeled the field "File" and also named the content type to be "document." Sigh. I'll rename those.)

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

    Here's some XML if it helps you. I'm going to experiment with XDebug.

    Thx....

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

    I also created a log action and filled it with many of the tokens. Here's the output. You'll note that the file tokens aren't replaced for some reason.

    This is a log: 
    file:fid : [file:fid] 
    file:original : [file:original] 
    file:original:path : [file:original:path] 
    media:field_media_document : /sites/default/files/2024-06/return-label-thermostat.pdf 
    media:field_media_document:entity:fid : 690 media:uuid : 45d2f6dc-0c09-41c2-8b2f-299f26911680 
    media:field_media_document:entity:url : http://XX.XX.XX.XX/sites/default/files/2024-06/return-label-thermostat.pdf
    
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    As I mentioned above, I can't help you with analysing models that are created by the classic modeller. If you want that level of support, you need to provide models from the bpmn_io modeller.

    From what you're describing, the tokens you're using are not available. Maybe the chapter about tokens in the ECA Guide can help you to find out, how to make tokens available for subsequent usage in a model.

    And if your destination field is about media and not about file, then you need to provide a media entity when setting the field value, not a file entity.

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

    Thanks very much for this.

    I'm thinking the main reason the file tokens are not replaced is because they're not filled with any value. I've uploaded a media entity (document), not a file.

    The question is which value is the one that should be stuck in a media entity reference in a node. I can't seem to make that stick.

    In case this is of any help, I'm attaching a version encoded with the bpmn_io modeler. This does not work very well. The first log actions are triggered, but not the last ones. Neither action for setting a value works. The text field and the media field are left empty. There's no error in the logs either.

    Please let me know if you want me to try anything. Any suggestions are appreciated.

    TIA.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Looking through the model, there are 2 things that come to mind:

    • In the action Set Token Name you're setting the value Fred to the token T1, and afterwards you create a new node into the same token T1. You should use different token names for the 2 different things.
    • In the action Set file field you set the value [media:name] to the entity reference field for the file. Here you should just use [media] as the value because you want to set the media entity as the reference value for that field, don't you?

    Note: when you're preparing a model for review then please reduce its dependencies to the absolute minimum that's need to demonstrate the issue. The model from #11 requires 2 modules (allowed_formats and insert_block) that are most certainly not important for this issue. This is important, because we can't always download all those dependencies as well, as it may either cause side effects or bring extra issues that are distracting us from a proper analysis. The best way to get to that is to spin up a fresh Drupal installation with no extra modules, unless required to show the problem, and build the model there with the bare minimum.

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

    Thanks very much for your help.

    Here's what I learned today:

    1) Yes, the right token to use is the plain "[media]" token. That loads correctly -- when I use the old classic modeler.

    2) The bpmn_io model still doesn't work. I'm enclosing a cleaner version without that extra step to set the token name.

    3) The bpmn_io model will also create two different types of log entries. The first log will come under user "eca" in the tables and so it's displayed in the log table on admin/config/workflow/eca/log. The second one, though, appears only in the main log tables under user "admin". So that's why I thought it wasn't being logged.

    Thanks for your help. The insight in (1) gave me something that's working now.

  • Status changed to Fixed 24 days ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    The reason your BPMN based model isn't working is because you have disabled it, see screenshot:

    But in general, the model is now working, so I'm closing this issue and mark it as fixed.

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

    Actually, that wasn't the problem. I was turning it on and off while I tested a few other processes. Then I happened to export it when it was disabled.

    When I hit the enable button again, I see the same behavior.

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

Production build 0.69.0 2024