trilbymedia / grav-plugin-flex-objects

Powerful and supremely flexible object support for Grav
MIT License
40 stars 10 forks source link

File upload broken #34

Closed schliflo closed 4 years ago

schliflo commented 4 years ago

File upload fails with Undefined index: name:

Screenshot 2019-10-14 at 22 55 52

user/blueprints/flex-objects/slides.yaml:

title: Slides
description: Slides for slideshows
type: flex-objects

config:
  admin:
    list:
      fields:
        header.title:
          link: edit
  data:
    object: 'Grav\Plugin\FlexObjects\Types\FlexPages\FlexPageObject'
    collection: 'Grav\Plugin\FlexObjects\Types\FlexPages\FlexPageCollection'
    index: 'Grav\Plugin\FlexObjects\Types\FlexPages\FlexPageIndex'
    storage:
      class: 'Grav\Framework\Flex\Storage\FolderStorage'
      options:
        formatter:
          class: 'Grav\Framework\File\Formatter\MarkdownFormatter'
        folder: 'user-data://slides'
        pattern: '{FOLDER}/{KEY}/default.md'
form:
  validation: loose

  fields:
    header.img:
      label: Slide Image
      help: The image used for in the slide
      type: file
      size: full
      style: vertical
      multiple: false
      destination: 'user://pages/images/'
      accept:
        - 'image/*'

    header.title:
      type: text
      autofocus: true
      style: vertical
      label: PLUGIN_ADMIN.TITLE

    content:
        type: markdown
        validate:
          type: textarea
mahagr commented 4 years ago

I've reproduced the issue.

mahagr commented 4 years ago

The issue is not fully fixed but goes over the error.

In the mean time, please use this blueprint (updated for the upcoming version):

title: Slides
description: Slides for slideshows
type: flex-objects

# Flex configuration
config:

  # Administration Configuration
  admin:
    # Admin menu
    menu:
      list:
        route: '/slides'
        title: Slides
        icon: fa-address-card-o
        # Authorization to be able to see the menu item
        authorize: ['admin.pages', 'admin.super']
        # Priority -10 .. 10 (highest goes up)
        priority: 2

    # Admin template type (folder)
    template: default

    # List view
    list:
      # Fields shown in the list view
      fields:
        header.title:
          link: edit
          search: true
      # Extra options
      options:
        # Default number of records for pagination
        per_page: 20
        # Default ordering
        order:
          by: title
          dir: asc

    edit:
      title:
        template: "{{ form.value('header.title') }}"

  # Site Configuration
  site:
    templates:
      collection:
        # Lookup for the template layout files for collections of objects
        paths:
          - 'flex/{TYPE}/collection/{LAYOUT}{EXT}'
      object:
        # Lookup for the template layout files for objects
        paths:
          - 'flex/{TYPE}/object/{LAYOUT}{EXT}'
      defaults:
        # Default template {TYPE}; overridden by filename of this blueprint if template folder exists
        type: slides
        # Default template {LAYOUT}; can be overridden in render calls (usually Twig in templates)
        layout: default

  # Data Configuration
  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, if you want to have associated assets, such like images, use FolderStorage
      class: 'Grav\Framework\Flex\Storage\FolderStorage'
      options:
        formatter:
          # File formatter class, in this case the file is stored in markdown
          class: 'Grav\Framework\File\Formatter\MarkdownFormatter'
        # Folder where all the objects will be stored
        folder: 'user-data://slides'
        # File pattern to generate the filename
        pattern: '{FOLDER}/{KEY}/{FILE}{EXT}'
        # Filename
        file: slide
        # Field which will be used as {KEY}
        key: storage_key
        # Keep index file in filesystem to speed up lookups
        indexed: true
    search:
      # Search options
      options:
        contains: 1
      # Fields to be searched
      fields:
        - header.title

# Regular form definition
form:
  validation: loose

  fields:
    header.img:
      type: file
      label: Slide Image
      help: The image used for in the slide
      size: full
      style: vertical
      multiple: false
      accept:
        - 'image/*'

    header.title:
      type: text
      autofocus: true
      style: vertical
      label: PLUGIN_ADMIN.TITLE

    markdown:
      type: markdown
      validate:
        type: textarea

EDIT: updated to use GenericObject

schliflo commented 4 years ago

very cool to see the extra menu items! while this does not completely solve the issue i have, it's a lot better already! thank you for your help. I'm looking forward to the new release :)

chesjon commented 4 years ago

I installed the latest version today and am having an issue with the file type. When creating or editing a flex object I choose an image and it saves without any errors or warnings. The file doesn't appear to be uploaded and the image field in the markdown file does not have a value.

I am wondering if the problem I am describing is related to this issue or if I am doing something wrong. I tried using the blueprint provided by @mahagr to make sure it wasn't just an issue with my blueprint.

schliflo commented 4 years ago

The issue still persists in RC5 (no error, file does not get saved). Do you think this will get fixed in time for the final release @mahagr ? Either way I'd suggest closing this issue (labeled bug) or #37 (labeled enhancement) -otherwise they seem to be the same.

dwr-studio commented 4 years ago

I am facing this issue too, @mahagr why in your blueprint it's missing the destination option under the header.img field? Just asking. Thanks

mahagr commented 4 years ago

Should be fixed. @ricardo118 Can you test it out?

ricardo118 commented 4 years ago

@mahagr using the blueprint above I get

without using a destination, no save happens for the object.

Using a destination like destination: data://slides/images I get

The object saves with

---
title: title
img: {  }
---

slide content
mahagr commented 4 years ago

Updated the blueprint again and fixed the bug in Grav. Thanks for testing, now it really works.

clivebeckett commented 4 years ago

Updated the blueprint again and fixed the bug in Grav. Thanks for testing, now it really works.

@mahagr I reckon this will work with the next Release Candidate? I’m on Admin v1.10.0-rc.11 which was released three weeks prior to your comment here.

I copied the above pasted blueprint and everything works except the file upload – no matter whether I added a destination to the file field definition or not.

rhukster commented 4 years ago

@mahagr addressed file uploads in an independent branch of grav. It’s a big change to unify and cleanup the logic and has not been merged yet.

https://github.com/getgrav/grav/tree/feature/1.7-media