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

Add support for setting custom identifier field #1543

Merged
merged 2 commits into from
Nov 1, 2018

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Jul 29, 2018

- Summary

Sometimes title doesn't make sense as the identifier for a collection. For example I have a JSON collection called clients, which has a name field which I want to use for the slug. This PR adds support for an identifier_field setting for collections, which lets the user choose a different identifier field.

Closes #1802, #1700.

- Test plan

Try using the following collection:

- label: "Blog"
  name: "blog"
  folder: "_posts/blog"
  create: true
  identifier_field: name
  fields:
    - {label: "Name", name: "name", widget: "string"}
    - {label: "Publish Date", name: "date", widget: "datetime"}
    - {label: "Featured Image", name: "thumbnail", widget: "image"}
    - {label: "Body", name: "body", widget: "markdown"}

- Description for the changelog

Allow identifier fields other than title or path.

- A picture of a cute animal (not mandatory but encouraged)

Military hound

@verythorough
Copy link
Contributor

verythorough commented Jul 29, 2018

Deploy preview for netlify-cms-www ready!

Built with commit ff955cb

https://deploy-preview-1543--netlify-cms-www.netlify.com

@verythorough
Copy link
Contributor

verythorough commented Jul 29, 2018

Deploy preview for cms-demo ready!

Built with commit ff955cb

https://deploy-preview-1543--cms-demo.netlify.com

@erquhart
Copy link
Contributor

Thanks for this!

Just a heads up: anything that touches the slug requires thorough examination. Your changes are quite simple, it's the impact to seemingly unrelated parts of the project that we need to be sure about. Apologies this was overlooked for so long! We'll get it reviewed soon.

@ascorbic
Copy link
Contributor Author

Great. Thanks for the update.

@radusuciu
Copy link

Also would like to see this merged. This + support for custom slug synthesis from fields is the dream.

@erquhart
Copy link
Contributor

erquhart commented Nov 1, 2018

@radusuciu you can reference fields by name as placeholders in the slug field for a collection, fyi.

Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased, looks good to me - thanks @ascorbic!

Also tested locally.

@0x80
Copy link
Contributor

0x80 commented Nov 28, 2018

I started using Netlify CMS just today, and ran into this issue straight away 😅

In my index.html I'm getting the script from https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js. Do I need to do anything special to get this recent update?

Right now I'm stuck with this error:

'collections[0]' must have a field that is a valid entry identifier

And my collection config is this:

collections:
  - name: artists
    label: Artists
    label_singular: Artist
    folder: data/artists
    identifier_field: name
    create: true
    fields:
      - { label: 'Name', name: 'name', widget: 'string', description: 'The artist name' }
      - { label: 'Company Name', name: 'company_name', widget: 'string', description: 'The company name (optional)', required: false }
      - { label: 'Image', name: 'image', widget: 'image', description: A profile image }
      - { label: 'Short', name: 'short', widget: 'string', description: 'A short one-liner description' }
      - { label: 'Link', name: 'link', widget: 'string', description: 'A link to the artists website or other external resource' }
      - { label: 'Building Nr', name: 'building', widget: 'select', options: [1, 2, 3] }
      - { label: 'House Nr', name: 'house', widget: number }

@0x80
Copy link
Contributor

0x80 commented Nov 28, 2018

Ah I see. This is merged but not published yet as a new version, right?

@erquhart
Copy link
Contributor

Yep, coming soon.

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

Successfully merging this pull request may close these issues.

Remove requirement for 'title' field in folder collections
5 participants