Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

New plugin code review and help with file upload error

Started by Matt Mulhall 6 years ago · 2 replies · 664 views
6 years ago

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

YAML
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
6 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 44 1 week ago
Plugins · by Xavier, 4 weeks ago
2 54 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1181 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 48 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 73 2 months ago