Drupal Best Practises
Best practises: creating content types
All content types are created on our content hub, https://dp9-content-dev.anu.edu.au/
Naming and settings
- When creating new content types, prefix site specific content types with the site name
- <site> <content type name>
- Eg. Archives Library collection
- Provide a meaningful description
- Purpose
- Location on the website (if possible)
- Absence of a page template (e.g. related links or communication channel)
- <Purpose> <location> <no page>
- Tuckwell Magazine edition - Upload an new edition of the belle magazine, /news/bell no page
- Set publishing options
- Create new revision
- Disable display settings
- Display author and date information
Adding fields
- Reuse fields whenever possible
- Since we’re reusing field as often as possible change the field label to reflect the way it’s being used per content type level
- E.g. Event thumbnail, image gallery for field_media
- Required fields
- Mirror required fields from reference content type
- If they don’t exist, create a minimum set of required fields that allow content to be useful e.g. title & email for contacts
- Whenever adding new fields:
- Use the existing field name
Add table of standard fields and their typing
Best practices: Theming
Content type layouts
We’re using Drupal’s layout builder to manage layouts.
Layouts are built on a per site basis and are made up of:
- Sections
- Blocks
Creating sections
The 2 most prevalent section layouts are 1 column and 1 column and sidebar
When creating sections name as follows:
Section title (layout shorthand)
E.g
Body (12)
Body (8:4)
List of standard sections (add)
Creating blocks
Main content blocks should have these classes by default
- mb-2
Sidebar blocks should be should have these classes by default
- band-tint-wrap
- p-2
- mb-2
- bdr-left-gold
- Bdr-thick
band-tint-wrap p-2 mb-2 bdr-left-gold bdr-thick
Displaying content fields
Create a view to display each content field. Reuse existing views when possible.
Naming and settings
- When creating a content type view for layouts name as follows
- <site> Layout: <content-type>
- Leave site blank if view is intended as global/shared
- Set Block category as content-type
- Eg.
- Layout: Contact:Person
- Layout: Article
- Name the block same name as the field we’re displaying
Reusable page elements
Gold divider
Share thing
Creating custom site specific blocks
As a general rule prefix any custom blocks with the site name
E.g. Archives: News