Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken attachment reference in Flex Objects when destination: self@ used #3225

Closed
phmg701 opened this issue Feb 14, 2021 · 3 comments
Closed
Assignees

Comments

@phmg701
Copy link
Contributor

phmg701 commented Feb 14, 2021

Hello,

I'm trying to build a custom flex type photos here are the relevant code sections:

    photo:
      type: file
      multiple: false
      accept:
        - image/*
      label: Photo
      destination: self@

data section:

  data:
    # Object class to be used, allowing custom methods for the object
    object: 'Grav\Common\Flex\Types\Generic\GenericObject'
    # Collection class to be used, allowing custom methods for the collections
    collection: 'Grav\Common\Flex\Types\Generic\GenericCollection'
    # Index class to be used, works as a quick database-like lookup index
    index: 'Grav\Common\Flex\Types\Generic\GenericIndex'
    storage:
      # Storage class, use single file storage (does not support images and assets)
      class: 'Grav\Framework\Flex\Storage\FolderStorage'
      options:
        formatter:
          class: 'Grav\Framework\File\Formatter\YamlFormatter'
          options:
            file_extension: '.yaml'
            inline: 5           # Save with up to 4 expanded levels
            indent: 2           # Indent with 2 spaces
            native: true        # Use native YAML decoder if available
            compat: true        # If YAML cannot be decoded, use compatibility mode (SLOW)
        folder: user-data://flex-photos

Image storage works as expected, storing the photo in the "hashed" folder alongside with the photo.yaml file.
The problem is that no relative path is stored in the .yaml file, so attached image gets lost when editing back the object.
Generated item.yaml file:

published: true
title: 'Title'
photo:
  AAA.jpg:
    name: AAA.jpg
    type: image/jpeg
    size: 12345
    path: AAA.jpg

opposed to:

published: true
title: 'Title'
photo:
  user/data/flex-photos/files/AAA.jpg:
    name: AAA.jpg
    type: image/jpeg
    size: 12345
    path: user/data/flex-photos/files/AAA.jpeg

when using relative path destination destination: user/data/flex-photos/files.

I haven't tried yet to build a directory to list photos, but I'm guessing it wouldn't work either, if I get a basic understandig of Grav Forms and Assets management.

Thank you!

@rhukster
Copy link
Member

Probably a flex plugin issue...

@mahagr mahagr added the bug label Feb 15, 2021
@mahagr
Copy link
Member

mahagr commented Feb 15, 2021

Not having a path is actually intended behavior for images located in the object itself. For example, on pages having a path basically causes images to break whenever the path to the page changes.

This is also true with a custom destination, the field always contains information about the path, so there's no real need to include it. However, editing the item should not cause the image to be lost, which sounds like a bug to me.

@phmg701
Copy link
Contributor Author

phmg701 commented Feb 15, 2021

Thank you for the quick repilies.
Exactly. No issue in having relative path to the object itsef, but would it work as expected system-wide?
I'm afraid this also happens with user-data:// path, leading to a broken attachment path, if I recall correctly from another attempt with such attachment configuration.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants