New plugin code review and help with file upload error

I have previously posted about a plugin I made to store author bios and then output them in various pages. With a LOT of help from @pamtbaau the plugin is almost ready for release. I am having one specific issue: when I upload an image to an author profile, the upload appears to complete, but when I hit save the page reloads and I get the message “Data type ‘authors’ doesn’t exist!”, and the image is nowhere to be seen. All other text input saves perfectly in user/data/authors/authors.yaml. I am intending for the images to save in user/images but something is amiss.

Beyond the issue above I’m also calling for a general review of the code if anyone is willing to point out anything I may have missed, potential improvements etc. Thanks.

The Aura Authors plugin as it stands is available here: https://github.com/matt-j-m/grav-plugin-aura-authors

It integrates closely with my original Aura plugin, the develop branch of which is sitting ready for its next major release to support Aura Authors: https://github.com/matt-j-m/grav-plugin-aura/tree/develop

Below is my blueprint for saving the author data and image.

Cheers

form:
  name: authors
  action: '/authors'
  template: authors
  refresh_prevention: true

  fields:
    authors:
      type: list
      display_label: false
      collapsed: true
      style: vertical
      help: "Add or edit author details"
      data-default@: ['\Grav\Plugin\AuraAuthorsPlugin::getAuthors']

      fields:
        .name:
          type: text
          size: large
          label: Name
          validate:
            required: true
        .label:
          type: text
          size: large
          label: Taxonomy Label
          validate:
            pattern: "[a-z][a-z0-9_\-]+"
            message: "Use all lowercase letters and replace spaces with hyphens."
            required: true
        .image:
          type: file
          size: large
          label: Image
          multiple: false
          destination: 'user/images'
          accept:
          - image/*
        .description:
          type: textarea
          size: long
          label: Description
        .person-facebook-url:
          type: text
          size: large
          label: Facebook URL
          placeholder: 'https://www.facebook.com/username'
        .person-twitter-user:
          type: text
          size: large
          label: Twitter Username
          placeholder: 'username'
        .person-instagram-url:
          type: text
          size: large
          label: Instagram URL
          placeholder: 'https://www.instagram.com/username'
        .person-linkedin-url:
          type: text
          size: large
          label: LinkedIn URL
          placeholder: 'https://www.linkedin.com/in/name'
        .person-pinterest-url:
          type: text
          size: large
          label: Pinterest URL
          placeholder: 'https://www.pinterest.com/user/username'
        .person-youtube-url:
          type: text
          size: large
          label: YouTube URL
          placeholder: 'https://www.youtube.com/username'
        .person-website-url:
          type: text
          label: Website URL
          placeholder: 'https://www.example.com'

  buttons:
    submit:
        type: submit
        value: ' Save'
        classes: button
        id: authorSave

Did you notice that it’s not possible to add an image when creating an author? The file field does not show the usual “Drop your files here or click in this area” text and is completely disabled so it seems. When editing an author the file field suddenly is enabled and an image can be uploaded. And yes, then I get the same error as well.

I can’t detect anything wrong in your blueprint or your plugin. It must be something simple though. Maybe you can post a question in the Admin Plugin repo asking why this doesn’t work and what you are possibly doing wrong.

1 Like

Thanks @bleutzinn yes I did see that the upload is not available until something is already saved, but I figured that was normal behaviour similar to when you add a page via the admin plugin. I’ve taken your advice and submitted and issue on the admin plugin repo: https://github.com/getgrav/grav-plugin-admin/issues/1891. Cheers.