Using Display Suite in Drupal 8: How to Use Display Suite Fields

In the previous tutorial, you learnt how to customize content pages by using a Display Suite layout. Today, I want to show you how to use Display Suite fields.

Display Suite fields shouldn’t be confused with the standard field system. The best way to think of a field in Display Suite is as just a fancy formatter. The field will only render content.

You can’t use it to store values or define a widget like you can with the standard field system.

You’ve already seen this fields in action. If you select a layout you’ll notice a bunch of new fields appear.

These are Display Suite fields which are implemented by the module.

A field can be created in two fields: in code or through the Display Suite user interface (UI).

Today we’ll look at how to create fields using the Display Suite UI. In a future tutorial, you’ll learn how to implement a field in code.

Continue reading

Using Display Suite in Drupal 8: How to Customize Content Pages

You’ve just installed a fresh Drupal 8 website, created a few content types and attached fields to them. So far so good.

Now you want to customize the content pages. On the “Manage display” page you can re-order fields and disable them but you can’t move them into any type of region.

Display Suite enhances the “Manage display” page by offering a drag-and-drop interface for fields.

You can select different layouts and each layout has its own set of regions. The drag-and-drop interface then is used to move fields into these regions, all without writing a single line of code.

The real benefit in using Display Suite is you always have a standard workflow for modifying content pages.

If you’re working in a team, this is even more important; you want to standardize how entity types are customized. Or you’ll end up in a situation where each developer does things their own way.

Continue reading

How to Make Fields Persistent in Drupal 8

I wrote a custom module recently where I needed to programmatically attach a field; similar to how a Body field gets added to content types.

If you create a content type, via the “Content types” page, a Body field is automatically added to the content type. If you don’t need the field just delete it, but the default functionality is to have it added.

I wanted this same functionality in my custom module; when an entity is created a field is programmatically attached to it.

So I reverse engineered how the Body gets added to content types. In the Node module, the Body field is exported as field.storage.node.body.yml and the field is attached using the node_add_body_field function.

Continue reading

How to Print Variables using Kint in Drupal 8

While developing a module or modifying a template in Drupal you’ll often print variables, especially if you’re in a preprocess hook.

You learn early on how to use var_dump and print_r function. But these functions can sometimes display too much information and can be hard to filter through the arrays or methods in the variable.

In Drupal 7, with the Devel module, you could use the dpm or dsm function. When used, these functions will print variables at the top of the page or in the message area using Krumo.

Now in Drupal 8, Devel has adopted a new library to print variables and it’s called Kint.

Continue reading

Debug Site Performance Using Web Profiler in Drupal 8

In the beginning of any Drupal project the site loads very quickly because there aren’t many modules installed. But as you add modules, the performance of the site will become slower and slower.

There’s always a certain point in the project where you realize it’s time to look at the problem and see if it’s a rogue module or some dodgy code, we’ve all seen this.

Trying to debug a performance issue can be tedious work. But often, it comes down to having too many queries loaded on a page.

If you’re on Drupal 7, just enable query logging using the Devel module. This will show all the queries generated at the bottom of the page.

But for Drupal 8 we have something better: Web Profiler.

Web Profiler is a Drupal 8 port of the Symfony WebProfiler bundle. The port is possible because Drupal 8 uses Symfony components.

Web Profiler adds a toolbar at the bottom of every page and shows you all sorts of stats such as the amount of database queries loaded on the page, which services are used and much more.

Continue reading

New Videos: Banner Paragraph Type

I’m happy to announce that a new section has been published on our “Build Edge-to-edge Sites using Paragraphs in Drupal 8” course over at WebWash Courses.

The latest section will teach you how to create a Banner paragraph type. The paragraph is great for displaying images full width and can be used to display text with an image as a background.

In this section, you’ll learn the following:

  • How to nest paragraphs and create a container paragraph type
  • Learn about the Color Field module
  • Learn how to resize an image using image styles within a preprocess

The next section currently in the works will teach you how to display a Bootstrap Carousel.

Continue reading

Presentation: Search in Drupal 8

At this month’s Sydney Drupal meet up I did a presentation about Search in Drupal 8. In the video, I explain three ways you can create a search page, they are as follows.

1. Core Search

The core Search module which comes with Drupal has some new functionality in Drupal 8. The biggest change is the ability to create custom search pages without using any other module.

2. Views Filter

A common way to build search pages in Drupal 7 was to create a views page and use the “Search Keywords” filter in views. This can still be done in Drupal 8 and best of all Views is now part of core.

3. Search API

The Search API module is used to create powerful search pages and it’s highly extensible. It is the module to learn and use for building search pages.

Continue reading

Introducing WebWash Courses and the Paragraphs for Drupal 8 Course

You may have noticed that I haven’t posted any tutorials over at WebWash for a while. That’s because for the last month and a half, I’ve been working on producing an online video course for Paragraphs in Drupal 8.

With that said, I’m proud to announce the first release of “Build Edge-to-edge Sites using Paragraphs in Drupal 8“.

The course will be released in stages as the videos are produced. In the current course you’ll learn:

Continue reading

How to Create a Search Page in Drupal 8

Building a search page isn’t as straight forward as you’d think. At first a client will want something which users can search content, then they may want to modify the search results or even change the ranking of certain content. Long story short, something you thought would be as simple as enabling a module, ends up taking twice as long.

If you need to create custom search pages in Drupal 7, more often than not, you use Search API or create a search page using Views. But the core Search module for Drupal 8 has become more powerful than in Drupal 7. One of the big changes, for site builders, in Drupal 8 is the ability to create custom search pages.

However, there’re a few limitations to creating a search page. First, it’ll have a prefix of “search/” in front but the full URL can be changed by creating a URL alias. Second, you can only adjust the content ranking on these pages. If you want to index extra fields or remove ones from being indexed, you’ll still need Search API to do this.

In this tutorial, you’ll learn how to create a custom search page and how to modify the search results by overriding a template.

Continue reading

Lightning Talk: Page Manager and Panels in Drupal 8

At March’s Sydney Drupal user group, I did a lightning talk on Page Manager and Panels in Drupal 8. In the talk, I demonstrate both modules and show you how to create a custom homepage with a few clicks. You can watch the whole talk in the video above.

Panels in Drupal 8 has changed considerably. The UI for building pages is now offered by Page Manager, with Page Manager UI installed, and not Panels itself. The UI also changed, but I think it’s much easier to use than in Drupal 7, but that’s my opinion.

Continue reading