Add or delete custom Drupal module

Custom Drupal modules can add functionality to a Webspark 2 site. This page provides instructions for finding and installing them on an ASURA site. It also lists the custom modules already installed on ASURA sites.

Required applications

You will need the software listed below.

You should make sure you have fairly recent versions of these tools. The version of PHP should not be older than the one in use with current versions of Webspark. You can see what version this is by logging in to one of the ASURA sites, then choosing Reports - Status report from the admin menu.

For Windows:

  • Install PHP
  • Install PHP Composer
  • Download Git (This is Git Bash for Windows.)
  • For a Windows 10 or 11 installation of Git, you will also need to have corrected a problem with the Git installation that causes patches to fail (Composer can't find the patch.exe that it needs). You need to add the directory "C:\Program Files\Git\usr\bin" path to "Environment Variables -> System variables -> Path". You can use directions from ComputerHope.com to do this.

For Macs:

To add or update a Drupal module

  1. Back up the Dev site. On the Pantheon dashboard for the site, select the Dev tab, then choose  "Code" on the left and  make sure Development Mode is set to Git. Then chose Backups from the list on the left, click on the yellow button "Create New Backup".
  2. Back up the Live site. On the Pantheon dashboard for the site, select the Live tab, then chose Backups from the list on the left, click on the yellow button "Create New Backup".
  3. Clone the Live site to Dev. On the Pantheon dashboard for the site, select the Dev tab, then choose Database / Files from the menu on the left.  Choose the Live environment, and make sure all 4 boxes are checked: Clone Database, Clone Files, Run update.php, Clear Caches. Wait for the workflows to complete.
  4. Stage any config changes that are in the database because of changes you have made. 
    1. Place Pantheon in SFTP mode for the Dev site: On the Pantheon dashboard for the site, select the Dev tab, then chose Code from the list on the left, and click on SFTP next to Development Mode.
    2. Visit the Development Site and sign in. From the Administration menu, go to configuration-development-configuration synchronization. Click on the Synchronize tab. If anything is listed there it means there have been some changes to config. You should determine whether to complete or not, and delete any updates that you don't want to apply. If you want to apply the changes, just leave them there. If there are none to apply, you can go on to preparing the local repository.
    3. Click on the Export tab, and then click on the Export button, and save the exported file to your computer. 
    4. Click on the Import tab, still in the configuration-synchronization menu, and upload the file you just created. If you see a red warning message "The directory .../config is not writable" it means that you forgot to place Pantheon in SFTP mode. Go back and do that then come back and import the file.
  5. Commit the changes in Pantheon. On the Dev tab, you should see the changes waiting. If you don't, try refreshing the browser. Give them a name that describes what the changes are, e.g., "change the Obits Search view", then commit. Switch the Development environment back to GIT mode.
  6. Clear the Pantheon caches: click on the "Clear Caches" button in the top right area of the page, and wait for the process to finish.

Clone the site Git repository (the development version) from Pantheon to your local machine.

  1. Copy the code revealed by the “Clone with Git” button on the site’s Pantheon page – the “Code” page. 
  2. Open a Git command window, set directory to the root of where you want the clone to be, e.g. type “cd c:/Webspark2” at the command line
  3. Paste the Pantheon command onto the next line. When prompted enter your Pantheon site password, then wait for the cloning process to complete.

Install the dependencies of your repository:

  1. In the Windows Powershell (Admin) window or a Git command window, set directory to the root of your downloaded repository, e.g type “cd c:/Webspark2/asura3” in the command line. 
  2. Type “composer install”.
  3. Wait for the installation to complete.

If you are using Windows and you see a red error messages that relates to not installing patches, you may not have added the necessary path to the environment variables, as listed under "Required Programs". Do that, and then try again.

  1. You will need to be at the root directory of your local repository for all of these commands. To get there, type “cd [repository location]”, e.g. cd c:/Webspark2/asura3” in the command line. 
  2. The module-name is the last piece of the URL on the module’s page on the Drupal site.Type: “composer custom-require Drupal/module-name”
  3. Repeat the preceding command for each new or updated module.
  4. You should be able to see your new module(s) in the repository folder web/modules/composer/ . If you don’t, check your syntax – did you get the module name right?
  5. Type “git status”. You should see the the file custom-dpendencies/composer.json and possibly custom-dependencies/composer.lock listed. If you see any other files, you may need to start over -- something has gone wrong.
  6. Type “git add custom-dependencies/composer.json” and, if it was changed, “git add custom-dependencies/composer.lock” 
  7. At the command line, still in the root directory of your repository, type “git commit –m “Add [name(s) of new module(s)]”. This will package the files and identify the change when it is made on Pantheon.
  8. Type “git push”. Supply your Pantheon password at the prompt. This will apply the update to the Dev environment of the site.
  9. Pantheon will commit the change and add the commit to the commit log using the name you supplied in the git commit command.
  10. Clear the Pantheon caches: click on the "Clear Caches" button in the top right area of the page, and wait for the process to finish.

Check for required module libraries

On the development site, from the Administrative menu choose Reports, Status report. If you see an error for an installed module that says "not installed" or "not found", you need to install the associated library.

The following instructions probably will not work, because the library is not pushed forward to test and live environments. You cannot install them directly in the test and live environments, as permissions prevent you. So, you can try to see if there is a means of installing via Composer for any needed library.

Required application for installing a library

You will need to have WinSCP, which is a free application for Windows that you can use to work with SFTP files that are on a server.

To install a library

  1. The error message in the status report will have a link for downloading the library to your computer. Click on that, then click on the Zip file to extract it. Delete any example folders from the extracted files.
  2. In Pantheon, from the Code menu on the left, make sure that the Development Mode is set to SFTP .
  3. Click on the Connect with SFTP button to the write of the Development Mode toggles, and then click on the Open SFTP Client button.This will begin a WinSCP session. You will be prompted for a password: Enter your PANTHEON password (not the website password), as you will be accessing a Pantheon server.
  4. In the right-hand window of WinSCP, click on the Home icon at the top, then the code folder, the web folder, and the libraries folder. Note that you can navigate up and down in the folder structure using the blue arrow icons.
  5. Refer to the Status report message to determine the name of the folder within the libraries folder that you will need. An example message says, "The Colorbox library needs to be downloaded and extracted into the /libraries/colorbox folder in your Drupal installation directory." If your message doesn't specify the folder, it probably is the same as the module name.
  6. Right-click in the open space of the libraries folder listing in WinSCP and choose New-Directory. Enter the name of the directory you need. Then open that directory
  7. In the left window of WinSCP you will see your computer's files. Navigate to the extracted library contents for your module, Select all of the contents, and drag them to the new folder on the Pantheon server.
  8. Return to the status report on your development website, and refresh the browser. The error messages should be gone.

Synchronize the updates in the Dev environment and test

  1. Visit the development site. From the Administration menu, go to configuration-development-configuration synchronization. Click on the Synchronize tab. If there are any changes listed, use the export-import procedure to apply them, as in the item above "prepare the site". There will not be any if you prepared the database as indicated above. However, if you didn't, It is possible that you will have to do this more than once to sync all of the changes. Note: the new module(s) will not result in config changes until you configure them.
  2. Clear the Pantheon caches: click on the "Clear Caches" button in the top right area of the page, and wait for the process to finish.
  3. Test the new module in the Dev environment. To do so, enable it and configure it following instructions found for the module on Drupal.org. Review the site pages to make sure everything works as it should. Enabling is done by finding the module in the Extend tab of the administrative menu, then clicking on the box next to it. If you see problems, you may want to restore the Dev site from your backup.
  4. If you did any module configuration, including permissions, repeat the export-import steps listed under "prepare the site" and Pantheon commit. 

Apply the updates to the Test environment

  1. Go to the Pantheon dashboard for the site, and chose the Test tab.
  2. On the left, click on Deploys. You should see your changes waiting. Make sure the buttons for cloning database and files are checked, and then click on Deploy. This is shown as steps 2 and 3 on the overview diagram.
  3. Visit the Test site and sign in. From the Administration menu, go to configuration-development-configuration synchronization. Click on the Synchronize tab. You should see a list of changes, although it is possible that there will be none, particularly if you did not enable the new module(s) in the dev environment. Click on Import all. This is shown as step 4 on the overview diagram.
  4. Again, make sure everything looks okay on the test site web pages. If you want to see the new module working in the test site, you will need to enable it here. Stop here if you see problems. Review your steps. 

Apply the updates to the Live environment

  1. Go to the Pantheon dashboard for the site, and chose the Live tab.
  2. On the left, click on Deploys. You should see your changes waiting. Click on Deploy. This is shown as step 5 on the overview diagram.
  3. Clear the Pantheon caches: click on the "Clear Caches" button in the top right area of the page, and wait for the process to finish.
  4. Visit the Live site and sign in. From the Administration menu, go to configuration-development-configuration synchronization. Click on the Synchronize tab. You should see your list of changes. Click on Import all. This is shown as step 6 on the overview diagram.
  5. Enable and configure the new module as you did in the Test environment.
  6. Again, make sure everything looks okay on the live site web pages. There should not be any issues if you have checked the Dev and Test sites before proceeding, and stopped if there are problems. If, however, you see problems on your live site, you can restore from the backup you created before beginning this process. 

To remove an installed module

  1. Make sure your site is in Git mode. In Pantheon, on the development site, the Code menu (on the left), set Development Mode to Git.
  2. At the root directory of your local repository (e.g, c:/Webspark2/asura2) type “composer remove Drupal/[module-name]”. This removes it locally.
  3. Type “git add composer.json” and “git add composer.lock”, git commit -m “Remove [module-name]”, and git push. Again, this won’t work if for some reason the changes to your composer.json and composer.lock files are reverted. In this case, you can again hand-modify the composer.json file to remove the requirement for the module, run composer update, then commit the two files and push.

     

Use this procedure if you have committed a module to Pantheon and so can no longer simply uninstall it.

  1. Put the Development site into Git mode.
  2. In a Git window, change directory to the site you are working on, e.g. cd c:/webpsark2\asura3 .
  3. Git revert HEAD –no-edit [note that the capitalization of HEAD is important} – or, if you are backing out a commit other than the most recent, [note that there a space and two hyphens before no-edit]/

    Git revert [commit-ID] –no-edit [Commit ID is displayed at the top of the “diff” display that is available for the commit]
  4. Git push origin master
  5. Recreate the site locally before trying to install anything else.

     

About Drupal modules

You may want to add some functionality to an ASURA Drupal site. You must, of course, be an administrator on the site to do this.

There are over 7,000 modules available at Drupal.org that provide all kinds of functionality that you can add to a Webspark 2 site. You can use the Drupal search to find possibilities, and you can also just use a general Web search to find what others are using and recommending to fill a particular need.

Webspark 2 comes with a fairly significant basic set of extension modules already installed. You can see the list of all that are currently installed in the Administration-Extend menu of your site. You should check there first to see if what you want is installed but simply not enabled. Never try to install a module that is already part of Webspark, even if you would like to use a later release. Doing so will cause problems!

If you find something that you are interested in trying, follow the directions at the left to install it on the development section of the site. Test it, and if everything looks good, you can push it on through to Live. If you don't like it, you can simply disable it using the Extend menu, or you can use Drupal's uninstall function to get rid of it.

Which custom modules have been added?

Modules that have been added to those provided as part of Webspark 2 follow:

On the main site, ASURA:

  • File Delete - to allow a file that is not in use anywhere to have its status changed from Permanent to Temporary, so it will then be deleted.
  • Media Directories - to allow media to be found through a directory structure. This module requires three other modules that are, therefore, installed: Embed, Entity Browser, and Entity Embed.

On the Help for Volunteers site, vol.asura.asu.edu:

  • Content Access - to make it possible to hide pages of a specific content type from the general public.
  • File Delete - to allow a file that is not in use anywhere to have its status changed from Permanent to Temporary, so it will then be deleted.
  • Media Directories - as for the ASURA site.

Updated 2 Apr 2024 by Connie McNeill