Image field and smart date problem

Created on 11 August 2025, about 1 month ago

I have two problems with Webform and Webform Content Creator.

1) I have an image field. The user should upload an image that is then displayed in the node. I just can't get it to work. The image is uploaded (private/public makes no difference), but it is simply not transferred/mapped to the node. It is included in the submitted Webform. In the content type, it is a media field - image. Perhaps that is where the problem lies, but there is only the media field. What's the catch here? How can this be solved?

2) I have a smart date field in the content type. I can't find a relevant counterpart in the web form, only simple date/time fields. Is that really the case, or am I overlooking something? How could I adjust it so that I at least get a date with start and end times?

Many thanks in advance.

💬 Support request
Status

Active

Version

4.0

Component

Miscellaneous

Created by

🇸🇪Sweden markusdala Dalarna

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

Comments & Activities

  • Issue created by @markusdala
  • 🇧🇷Brazil aluzzardi Pelotas, RS

    I’m not sure if you’re familiar with working with hooks, but I couldn’t find a way to map file uploads to Media directly. So, I used the hook_entity_presave() to handle that.

    function mymodule_ENTITY_TYPE_ID_presave(EntityInterface &$entity) {
      // On webform creation, if the entity is a node of type,
      // create a media entity for the field_logo if it exists.
      // This is to ensure that the field_logo is a media entity.
      // This is a workaround for the fact that webforms do not support media
      // entities directly.
      // Get field_logo target_id.
      $field_logo = $entity->get('field_logo');
      $field_logo_value = $field_logo->getValue();
      $logo_entity_type = $field_logo->entity;
      // If logo_entity_type is empty, it's a new media from webform as presave 
      // from node add/edit will have the media entity already.
      if (isset($field_logo_value[0]['target_id']) && empty($logo_entity_type)) {
        // Get the file entity.
        $file = File::load($field_logo_value[0]['target_id']);
        if ($file) {
          // Create media entry.
          $media = Media::create([
            'bundle' => 'image',
            'name' => $file->getFilename(),
            'field_media_image' => [
              'target_id' => $file->id(),
              'alt' => $file->getFilename(),
            ],
            'field_caption' => $file->getFilename()
          ]);
          // Save the media entity.
          $media->save();
          $entity->set('field_logo', [
            'target_id' => $media->id(),
            'alt' => $file->getFilename(),
          ]);
        }
      }
    }
    
Production build 0.71.5 2024