Quickly Implement a Block as a Paragraph in Drupal 7

Disclaimer: As with most tasks in Drupal, there are several ways to do this. My goal here was to see how quickly it could be done without writing code and without introducing unnecessary complexity.

Goal — quickly implement a newsletter listing (using Views) that can be dropped into any paragraph field and can have a unique title per use.

The output would be a simple block from Views. We already use Display Suite, so naturally we use a DS-centric approach.

Create the view

I used a “Listing” view mode on the E-Newsletter Archive Issue content type (well, on many content types throughout the site)

2016-06-06_06-42-16

Create a new paragraph bundle

2016-06-06_06-43-14

Add a title field (we are required to have at least one field)

2016-06-06_06-43-47

Choose a “One Column” Display Suite layout, which enables the “Custom fields” pane

Click the “Add a block field” button

2016-06-06_07-11-39

Add the block field as shown

2016-06-06_06-47-35

Drag the field into the content region

2016-06-06_06-46-12

Change the title to an H3 (doing it this way requires “field templates” from Display Suite Extras)

We use this anyways, so naturally it’s a quick win.

2016-06-06_06-46-36

Add the new paragraph bundle to your paragraph field(s)

2016-06-06_06-48-35

Try it out

2016-06-06_06-50-50


This is a one-trick pony. I’ve done this in the past where it was more complicated and the user could choose from a list of prebuilt output components (like the Newsletter Listing); in that scenario I used a single paragraph bundle with a select list. Then, using some preprocess hooks I spit out the component they wanted based on the select list choice.

Tagged with: , , , , ,
Posted in Development

Leave a Reply

Your email address will not be published. Required fields are marked *

*