Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Drupal 10 Development Cookbook

You're reading from   Drupal 10 Development Cookbook Practical recipes to harness the power of Drupal for building digital experiences and dynamic websites

Arrow left icon
Product type Paperback
Published in Feb 2023
Publisher Packt
ISBN-13 9781803234960
Length 442 pages
Edition 3rd Edition
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Matt Glaman Matt Glaman
Author Profile Icon Matt Glaman
Matt Glaman
Kevin Quillen Kevin Quillen
Author Profile Icon Kevin Quillen
Kevin Quillen
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Chapter 1: Up and Running with Drupal 2. Chapter 2: Content Building Experience FREE CHAPTER 3. Chapter 3: Displaying Content through Views 4. Chapter 4: Extending Drupal with Custom Code 5. Chapter 5: Creating Custom Pages 6. Chapter 6: Accessing and Working with Entities 7. Chapter 7: Creating Forms with the Form API 8. Chapter 8: Plug and Play with Plugins 9. Chapter 9: Creating Custom Entity Types 10. Chapter 10: Theming and Frontend Development 11. Chapter 11: Multilingual and Internationalization 12. Chapter 12: Building APIs with Drupal 13. Chapter 13: Writing Automated Tests in Drupal 14. Chapter 14: Migrating External Data into Drupal 15. Index 16. Other Books You May Enjoy

Creating menus and linking content

Drupal allows you to link content being authored to a specified menu on the website, generally the main menu. You can, however, create a custom menu to provide links to content. In this recipe, we will show you how to create a custom menu and link content to it. We will then place the menu as a block on the page, in the sidebar.

Getting ready

This recipe assumes that you have installed the standard installation profile and have the default node content types available for use. You should have some content created to create a link.

How to do it…

  1. Visit Structure and click on Menus.
  2. Click on Add menu.
  3. Provide a title of Sidebar menu and an optional summary and then click on Save.
  4. Once the menu has been saved, click on the Add link button.
  5. Enter a link title and then type in the title for a piece of content. The form will provide autocomplete suggestions for linkable content.
  6. Click on Save to save the menu link.
  7. With the menu link saved, go to Structure, and then Block layout.
  8. Click on Place block next to Sidebar first. In the model, search for Sidebar menu and click on Place block.
  9. In the following form, click on Save block.
  10. View your Drupal site by clicking on Home in the administration menu.

How it works…

Menus and links are part of Drupal core. The ability to make custom menus and menu links is provided through the Menu UI module. This module is enabled on the standard installation but may not be in others.

The Link input of the menu link form allows you to begin typing content titles and easily link them to existing content. It will automatically convert the title into the internal path for you. Link input also accepts a regular path, such as /node/1 or an external path. You may use <front> to link to the home page, <nolink> to render a non-linked anchor tag, and <button> for a keyboard-accessible text-only link.

There’s more…

Links can be managed through the content edit form itself, which will be covered next.

Managing a contents menu link from its form

A piece of content can be added to a menu from the add or edit form. The menu settings section allows you to toggle the availability of a menu link. The menu link title will reflect the content’s title by default.

The parent item allows you to decide which menu and which item it will appear under. By default, content types only have the main menu allowed. Editing a content type can allow for multiple menus or only choosing a custom menu.

This allows you to populate the main menu or complimentary menu without having to visit the menu management screens.

You have been reading a chapter from
Drupal 10 Development Cookbook - Third Edition
Published in: Feb 2023
Publisher: Packt
ISBN-13: 9781803234960
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime