2.0.1releasedHashid Field

Enables you to add a unique and read-only hash to an entry, generated using the entry ID.

Clone URLhttps://github.com/nathanhornby/hashid_field.git

Add as a submodulegit submodule add https://github.com/nathanhornby/hashid_field.git extensions/hashid_field --recursive

Compatibility

2.x.x2.1.x2.2.x2.3.x2.4.x2.5.x2.6.x2.7.0
NoNoNoNo2.0.12.0.12.0.1No. Soon?

Readme

Hashid Field

Enables you to add a unique and read-only hash to an entry, generated using the entry ID. Ideal for using as an obfuscated URL slug or non-sequential ID. This extension uses the Hashids library.

Code Climate

Installation and usage

  1. Upload the hashid_field folder to your Symphony /extensions folder.
  2. Enable it by selecting Hashid Field in the Extensions list, choose Enable from the "With Selected…" dropdown, then click Apply.
  3. Add to any section where you need a hash!

The field requires no interaction from the end-user as it automatically populates when the entry is created.

Hashes are regenereated when a pre-existing entry is saved, so if you change the salt or hash length and update an entry, its hash will change (otherwise it will remain the same). So it's generally advised to set-and-forget unless that's your intention. This is especially important if you plan on using the hashes for URL slugs. The field will warn the user if the hash is going to regenerate.

You can also regenerate Hashid fields via the 'With selected' toggle on the publish page. This works under the same conditions as above.

The minimum hash length and the salt can be set for each instance of the hashid field, and you can set defaults in your Symphony preferences.

Hash salt

Your sitename is used as the default salt when the extension is installed. If your hashes are to be used for any obfuscation purposes then ensure that your salt is as random/chaotic as possible, as two sites using the same salt will share hash values for the same corresponding entry IDs.

Hash length

The default hash length is set to 5 when the extension is installed. This is sufficient for the vast majority of cases, and you're highly unlikely to hit the unique limit in a single section. The field supports up to 32 characters, lengths set above 32 will be truncated.

How to's

Using the hash for URL obfuscation

This ones easy; just set a 'hashid' parameter on your page and filter by your hashid field in the datasource.

Using the hash for ID obfuscation in events

There are a few ways of using the hashid with events, but my preferred method is to use the hash in place of the entry ID. i.e.

<input type="text" name="id" value="{section/entry/hashid_field}" />

Then you just have to swap this out for your entry ID in your __trigger function in the relevant event:

``` protected function __trigger() { // If the ID isn't a number then it's a hash, so convert it to the entry ID if( isset($POST['id']) && !isnumeric($POST['id']) ) { requireonce EXTENSIONS . '/hashid_field/lib/Hashids.php';

    $hash = new HashidsHashids( 'TheSaltForThisField' , 6 );
    $decrypt_array = $hash->decrypt($_POST['id']);
    $_POST['id'] = $decrypt_array[0];
};

return $result;

} ```

Where 'TheSaltForThisField' and 6 are your hash salt and hash length. These need to be manually set in the event and are static values.

Version history

Symphony 2.4 to 2.6.x

        - Removed `size` from field table (#37)
	

Symphony 2.4 to 2.6.x

        - Hash can now be up to 255 characters long
	        - The hash value column in the database now enforces uniqueness
	        - Improved coding style (Enforce PSR-2 code)
	        - [#28](https://github.com/nathanhornby/hashid_field/issues/28) Make compile method do all the work
	        - [#31](https://github.com/nathanhornby/hashid_field/issues/31) Fix bug when editing from frontend
	        - Return value of the FieldHashid_field::compile() method is boolean now (but the entry object is updated)
	        - Importers (XMLImporter) must rely on compile methods
	        - Simplify, drop registerField method (see also #31)
	        - Fix and simplify publish panel
	        - Update Hashids to v1.0.5, using composer now
	        - Use database insert instead of update, so the compile method will work without committing the entry beforehand
	

Symphony 2.4 to 2.6.x

        - Make the FieldHashid_field::compile() method returns the hash id
	        - Removed dead code and members
	        - Added prepareTextValue implementation
	

Symphony 2.4 to 2.6.x

        - Prevent the field from being registered multiple times.
	

Symphony 2.4 to 2.6.x

        - Make sure FieldHashid_field::commit() always returns a value
	

Symphony 2.4 to 2.5.x

        - Version bump.
	        - Added support for 'not:' in data source filtering. (Thanks @nitriques!)
	

Symphony 2.4 only

        - Scaled back styling.
	        - Improved readme.
	

Symphony 2.4 only

        - Added publish toggle for regenerating Hashid's.
	        - Added hash salt and length as attributes to output XML for more advanced implementations that may want access to them.
	

Symphony 2.4 only

        - Changed hash length settings fields to only accept numbers.
	        - Checked compatability with older versions of Symphony, doesn't work pre-2.4.
	        - Changed layout of preferences.
	        - Titied up code and style inconsistencies, lots of comments added.
	

Symphony 2.4 only

        - Removed optional flagging from field settings.
	

Symphony 2.4 only

        - UX improvements.
	

Symphony 2.4 only

        - Entries created with events now generate the hash.
	        - Fixed issue with displaying a new hash before the old hash has been replaced.
	

Symphony 2.4 only

        - Changed extension name.
	        - Added field settings to allow for different salt's and lengths for each hashid field instance.
	        - Hashes are now created when the entry is created, not requiring a re-save.
	

Symphony 2.4 only

        - Extension created! Kind of works.