Last Updated: 10/20/2023 - 14:29

Code Recipes

Our code recipes section involves snippets to copy and paste into your Web Theme site and commands to run during the development phase of the project. 

Unpublish Blades

This is a great option for temporarily disabling a blade rather then deleting it and creating it again. If your site doesn't have this option (located inside the Blade Settings group), please follow these instructions to get started.

  1. For Administrators: Go to Structure > Paragraph Types > Blade
  2. Under the Blade dropdown, select 'Manage Form Display'
  3. Locate the 'Published' field under the Disabled group and drag it to the top and place it under 'Admin Label'. If 'Admin Label' or 'Blade Settings' is not present on your site, drag the Published field to sit above 'Top Border'.
  4. Save

unpublish blades example

Once the published option is activated, all blades and newly-created blades will be published by default. If the 'publish' box is unchecked in a blade, it will not be visible to logged out visitors to your site. If you are logged in you will still see the blade on the back end (there will be a blue eyeball icon to denote the page is not visible) and you will still see any unpublished blades when logged in and viewing the page. 

Embed iframes 

How to make iframes fluid width while maintaining an appropriate height based on their aspect ratio (in this example: 16x9). This also works well with video content.

iframe {
	aspect-ratio: 16 / 9;
	height: 100%;
	width: 100%;
}

Drush Commands

Below are helpful commands working with Drush, the Drupal command line interface. In this recipe page, we are using Drush 8 but will be transitioning to Drush 10 with the launch of the UCSB Web Theme on Drupal 10. 

 

For Pantheon sites

  • connecting remotely: terminus drush <site>.<env> -- <drush command>
  • connecting locally: remote:drush -- <drush command>

 

drush pm-releases [module-name]
View all the release available for a Drupal module

drush up google_analytics-7.x-2.x
Update a module to a specific version

drush uli [user-name]
Set a temporary (24 hour) login link so the user can update their password. This is for D8 only.

drush watchdog-show
Rather than going to the error logs page to see errors and warnings, you only have to run watchdog-show.

drush cdel core.extension module.my_module_name
To completely remove a module and it's database injections from active configuration

drush sset system.maintenance_mode TRUE
Use drush to put the site in maintenance mode. Useful when the site is live.


For a deeper dive, checkout the Drush Cheatsheet with commonly-used commands.

CAS Single Sign On

On a Drupal 9 site, enable CAS by going to Extend > CAS > Install

After installation, on that same page, go back to CAS and select 'configuration'

On this page, enter the configuration details for the Server, General Settings, and User Account Handling. Below is an example of a site that uses the 'Authenticated' role upon successful login. 

CAS login configuration screenshot