Skip to content

Instantly share code, notes, and snippets.

View rc100's full-sized avatar

Rian Callahan rc100

  • Bixal
  • Portland, OR
View GitHub Profile
@ronaldmulero
ronaldmulero / field_link
Created September 23, 2019 18:14
Migrate link field from Drupal7 to Drupal8

Drupal 8: Create controller to load random node by type

On many projects, I often have a need to be able to see a random node of a particular content type for debugging or load testing. I use this function on Drupal 8 sites in my core module to add a route of:

http://mysite/random/my-content-type

I use this instead of a view sorted by random because I want to be redirected to the full path of the node.

Leaving off the content-type will use a random type from the array of valid content types I have provided. Providing an invalid content type will redirect it to an item from my core (or default) content-type.