Advanced Drupal Tasks

Advanced Drupal Tasks afrank30
Drupal Version

This section describes some of the more advanced tasks you might need to accomplish when editing a Drupal-powered website.


Advanced Topics

Roles and Responsibilities [Drupal 10]

Roles and Responsibilities [Drupal 10] kp37
Drupal Version
Tags

Roles are used by Drupal to apply a set of permissions to a group of user accounts. Some roles are built into Drupal, and some are automatically created by different Georgia Tech community modules and distributions, such as Drupal Express.  Below are the roles normally found on a Drupal 10 Drupal Express website:

Anonymous user

Automatically applies to anyone visiting your site who is not logged in.

Authenticated user

Automatically applies to anyone who is logged in to your site, so be careful about what permissions this role is given.

Editor

This role can edit all pages, as well as the menu and some of the blocks / block regions on the website. It's not usually assigned automatically, but by one of your site's Administrators.

Administrator

This role has full access to to all features and configuration settings of a Drupal site. It should NEVER be assigned automatically and should only be given to a highly trusted user (ideally only full-time employees).

Roles and Responsibilities [Drupal 7]

Roles and Responsibilities [Drupal 7] root
Drupal Version
Tags

Roles are used by Drupal to apply a set of permissions to a group of user accounts.  Some roles are built into Drupal, and some are automatically created by different Georgia Tech community modules and distributions, such as Drupal Express.

Drupal Provided Roles

Anonymous user

Automatically applies to anyone visiting your site who is not logged in.

Authenticated user

Automatically applies to anyone who is logged in to your site, so be careful about what permissions this role is given.

Roles Provided by Georgia Tech Community Modules

Editor

This role can Edit all pages, as well as the menu and blocks on a GT Drupal site. It's not usually assigned automatically, but by one of your site's Administrators.

Administrator

This role has limited access to the Administrative section of a GT Drupal site and can also do anything Editors can. Should NEVER be assigned automatically.

Super Administrator

This role has full access to the Administrative section of a GT Drupal site. Should NEVER be assigned automatically.

Contextual Filters in Views

Contextual Filters in Views ma195
Drupal Version
Tags

Editor's Note: The following was written for Drupal 7, but should work as described under Drupal 10.  The one main difference is that Drupal 10 does not have a "master" view, but you could have "block" or other types of views.  Just make sure you're editing the view to which you want to apply a contextual filter.

Contextual filters in Views are powerful, but getting them to work perfectly can be a nightmare. This will hopefully save some people from the headaches I had.

My goal was to have a News page that could easily be filtered to only have specific stories. I started with:

  • A Taxonomy vocabulary called "Keywords"
  • A "News Story" content type
  • A field named "Keywords" in the News Story that is a Term Reference type linked to the Keywords taxonomy

Our news stories are imported from Mercury, and the keywords are automatically imported into the Taxonomy vocabulary.

The goal is to have a page that lists all our news stories at example.gatech.edu/news.  A simple view can handle that easily. With a correctly configured contextual filter, we can add a taxonomy term to the end of the URL, and the view will automatically filter itself down to just the stories tagged with a term. Basically:

  • example.gatech.edu/news will list all news stories
  • example.gatech.edu/news/robotics will list all news stories with the keyword "robotics"
  • example.gatech.edu/news/music will list all news stories with the keyword "music"

Neat, right? The problem is, contextual filters can be a nightmare to set perfectly.

Part 1: Create the Basic View

  1. Create a new view at Structure -> Views -> Add. We set ours to show content of type News, sorted newest first.
  2. Make sure the "Create a page" box is checked, give it a URL, and set the display format to something simple like unformatted list of linked titles.
  3. Save the view and head to the URL to make sure it works. Good? Let's head back and edit that view.

Part 2:  Make the View Advanced!

Make sure you are using the Page display, not the master. Usually when something isn't working, it's because I was not editing the page view.

  1. Open the Advanced menu on the right if it isn't already.
  2. Select Add next to Contextual filters.
  3. Check Content: Has taxonomy term ID in the pop-up and Apply.

On the next page, under "When the filter value is NOT in the URL:"

This controls what the view does when there's nothing added to the end of the view's URL - i.e., in our case, what will show at http://example.gatech.edu/news.  The options include:

  • Display all results for the specified field - Shows everything that matches the view's base filter. This is what makes our default news page show all stories.
  • Provide default value - Lets you chose a default tag if you want a subset shown.
  • Show "Page not found."
  • Display a summary.
  • Display contents of "No results found."
  • Display "Access Denied."

The next section is "When the filter value IS in the URL or a default is provided:"  We used two options:

  • Override title - this lets you change the default title. We entered "News stories tagged with %1", which will take the term in the URL and substitute it for the %1. So if you are on example.gatech.edu/news/music, the title will be "News stories tagged with music."
  • Specify validation criteria - this is the tricky part. Check this, then:
    • Set Validator to "taxonomy term."
    • Select the "Keywords" vocabulary.
    • Set Filter value type to "Term name converted to Term ID."
    • Check "Transform dashes in URL to spaces in term name filter values."
    • Set Action to take if filter value does not validate to "Display a summary."

Finally, save the filter, then save the view.

Create or Rename a Menu

Create or Rename a Menu jtomasino3
Drupal Version
Tags

Create a Menu

  1. Navigate to the Menus page (Structure -> Menus).
  2. Select Add Menu.
  3. In the Title field, enter a title.
  4. In the Description field, enter an optional description.
  5. Select Save.

Enable a Menu

Enabling the menu allows it show up in the dropdown list when you want to add a web page to a menu.

  1. Navigate to the content type for which you want to enable the menu (e.g. Structure -> Content Type -> Multipurpose Page)
  2. Choose Menu Settings
  3. Select the checkbox of the menu(s) you want to enable
  4. (Optional) Set the "Default Parent Item" to choose whatever menu you want as the default for that particular content type.

Rename a Menu

Note: The default menus cannot be renamed.

  1. Navigate to the Menus page (Structure -> Menus).
  2. Select Edit Menu.
  3. In the Title field, enter a new title.
  4. Select Save

Editing Menus (Advanced)

Editing Menus (Advanced) jtomasino3
Drupal Version
Tags
  1. Navigate to Structure > Menus, or you can get there by hovering over the gold primary menu bar until a little cog appears in the upper right-hand corner. Click on the cog.
  2. You will see a list of links in your primary menu.
  3. Select the Add Link button.
  4. In the Path field, enter a path for the link.
    • This can be an internal Drupal path such as "node/add." or an external URL such as http://example.com.
    • Enter <front> to link to the front page.
  5. In the Description field, enter the text that will be displayed when a user hovers over the link.
  6. Enable any of the following options:
    • Enabled: If the link is not enabled, it will not be displayed in the menu.
    • Expanded: If this option is enabled and the menu link has children, the menu will always appear expanded.
  7. In the Parent Link list, select the parent menu of the link.
  8. (Optional) In the Weight list, select the relative weight of the link. Links with the "lightest" weight will display higher in a menu. Links with the same weight will display in alphabetical order.
  9. Select Save.