Giter VIP home page Giter VIP logo

statamic-uuid's Introduction

Uuid (Statamic 3)

One of its kind; unlike anything else

This fieldtype auto-generates UUIDs for empty fields. This can be useful if you need unique, persistent IDs for each row in a Replicator, for example.

Installation

Install the addon via composer:

composer require aryehraber/statamic-uuid

Publish the fieldtype assets:

php please vendor:publish --tag=uuid

Usage

Inside your blueprint, simply use type: uuid and a UUID will be generated for that field if it's blank. Already occupied fields (including previously generated UUIDs) will not be overwritten.

Settings

Name Default Description
hidden false Hide the field from the CP while still generating a UUID.
read_only false Set the input to read-only, stopping the user from editing the field.
id_prefix '' Add a prefix to the ID.
id_type uuid Set the underlying ID generator, options: uuid & nanoid.
alphabet null Set a custom alphabet when using nanoid.
size null Set the max character limit when using nanoid.

Example:

Blueprint

fields:
  -
    handle: sections
    field:
      type: replicator
      sets:
        section:
          fields:
            -
              handle: uuid
              field:
                type: uuid
            -
              handle: fields
              field:
                type: replicator
                sets:
                  value:
                    fields:
                      -
                        handle: uuid
                        field:
                          type: uuid
                          id_type: nanoid
                          alphabet: ABCD1234
                          size: 5

Output

sections:
  -
    uuid: 026fd166-8638-4c21-9e38-730b4ab3d4ea
    type: section
    fields:
      -
        uuid: A4C11
        type: value
  -
    uuid: 4a7ce0b0-0483-42d9-a7b0-ce0201dd9c84
    type: section
    fields:
      -
        uuid: B1CB3
        type: value
      -
        uuid: 41CD1
        type: value

Credits

Originally built at Series Eight, now maintained by Aryeh Raber.

statamic-uuid's People

Contributors

aryehraber avatar edalzell avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

statamic-uuid's Issues

Read only doesn't work

In Statamic v3, to make a field read only, you set read_only to true. This show as read only the CP but isn't actually read-only.

Shorter IDs for human readability

I'm curious whether a shorter unique/random ID could be generated?

I'm building a site for a film and image archive and we need to auto-generate a human readable ID (6 or 8 characters, A-Z 0-9). There will be around 10k items in the collection so in practice the uniqueness probability for a shorter string should be fine.

One option I've considered is to truncate the {s} id to first 8 characters but I'm not sure how I'd present that in the CP as readonly and truncated.

Thanks.

The prefix is empty

I've got a situation where the prefix remains empty. What info do you need from me to try to fix this?

FR: When using in a grid with hidden set to true, hide the corresponding grid column

First of all - thanks for making this add-on! We're finding it really useful.

We're trying to leverage this field in a Grid, which respects the hidden: true config flag, but only in stacked mode. Ideally, it would also hide the corresponding grid column when not 'stacked' as well.

Not entirely sure on the best approach to this, but our current way of achieving this is to extend the hide method in fieldtype.js as follows:

hide: function() {
      var el = this.$el
      var uuidClass = 'uuid-fieldtype'

      while (! el.classList.contains(uuidClass) && el.parentNode) {
        el = el.parentNode
      }

      if (el.classList.contains(uuidClass)) {
        el.style.display = 'none'
      }

      // check if the field is currently being rendered in a grid table
      var gridContainer = typeof el.closest === 'function' ? el.closest('.grid-table') : null
      if (!gridContainer) return

      // get the cell index of the current field
      var cellIndex = el.closest('td') ? el.closest('td').cellIndex : -1
      if (cellIndex < 0)  return

      // if there is a valid cell index, lets find the corresponding th and hide it's contents
      var th = gridContainer.querySelectorAll('thead tr th')[cellIndex]
      if (!th || th.children.length === 0) return

      th.children[0].style.display = 'none'
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.