Latest posts

Browse topics

How To Reference Nodes in Drupal 8 + Views Relationships Display

Lately I feel very enthusiastic working with latest Drupal 8 release, though Drupal 8 have been around for a while already, there are still few drawbacks which keeps me avoiding developing full scale on Drupal 8.

I will write down my notes of pros and cons about switching from Drupal 7 to Drupal 8 in some of the future posts, in today's Drupal tutorial series I will provide information how to use reference fields and build something awesome, as usual I will use a live example. We are going to build a views display, listing tours in a blog article.

You can see my previous simple tutorial on the same functionality for Drupal 7 site here: Node reference views display using relationships

In fact if you are familiar with relationship fields and node reference fields in Drupal 7, there is basically nothing new in Drupal 7, with exception that this functionality is already built out of box in Drupal 8, you don't need to download and install any modules

Here is what the final result looks

Referenced node view

Referenced node view

You can see a live preview here: John Graham Tours joins Tourgeorgia

Add a reference field to content type

In Drupal 8, node references are already in core, you don't need to install and enable any new modules. In this tutorial I'm using default article content type to add reference field:

Under your content type manage fields settings, click to add a new field

  • Select Reference -> Content
  • Give it a nice label, for example Tour listings
  • Save 

On the next page choose content types that can be referenced and select display value to unlimitedReference Type Field settings

Reference Type Field settings

As this reference field is attached to article content type, I will reference tours, so I select tour content type.

Save settings and go to content creation page (or edit existing content), you should see this newly created field there - add few referenced nodes and save your node.

You will see ugly formatted referenced items under your content, now go to your content type manage display settings and hide this field, as we are going to display it nicely using block built by views.

Drupal 8 views for referenced field

  • Create a new view, make sure your are enabling block display
  • Under Advanced, add Contextual Filter: ID (provide default value)
  • then from Relationships add referenced field:content

Now you are good adding fields and styling your view. Once ready save your view, go to block admin display and place this newly created block in content section.

Hope it helps. 

Magic Fish - Tbilisi Restaurant

Magic Fish is another interesting restaurant I've discovered in Tbilisi (see complete list with Tbilisi restaurant reviews). The fun fact is following, I had seen this place countless times by passing it by on lively Aghmeneshabeli avenue, but never thought, there is a restaurant located inside.

As flashy banner, and kind of strange name lead me to think there is some disco bar or something. Turns out I was wrong, and Magic Fish actually is a decent seafood restaurant in Tbilisi.

I was taken here actually by friend, I met at gym, see Champions academy in Tbilisi.

Shrimps

Shrimps

Fish

Fish

Hard Rock Cafe Tbilisi

I've found one of my favorite Tbilisi restaurants - meet Hard Rock cafe Tbilisi, located on lively Vasil Petrashvili street 1, near Tbilisi Philharmonic building.

Hard Rock Cafe Tbilisi, in fact is first Hard Rock cafe I've ever visited, but now I know, there is a good reason to visit them around the World.

Hard Rock Cafe Tbilsi

Hard Rock Cafe Tbilsi

​Located steps away from Casino Sakartvelo in the historical Vera District of Tbilisi (the capital of Georgia), our brand-new cafe combines the modern style of the Hard Rock brand with a sense of local history. Hard Rock Cafe Tbilisi is located within a restored wine factory, which was originally built in 1896 by famous Georgian industrialist and philanthropist David Sarajisvili, who is known as the founder of brandy production in Georgia. In fact, our building is listed as a cultural heritage site.

Fish & Chips

Fish & Chips

Amazingly well done, I had a chance to try fish & chips in US based Red Robin place, well the one you can get in Tbilisi is 100 times better than that at New Jersey's Red Robbin. 

Delicious Oreo biscuit cake

Delicious Oreo biscuit cake

Now, that was stunning.

Drupal 8 Custom Taxonomy Term Pages with Views

By default, out of the box, Drupal taxonomy term pages are styled kind of ugly, but with the help of just a few simple tweaks, we could style them as we wish, just by using CSS. In today's Drupal tutorial series, I will provide a simple how-to on how to create custom Drupal 8 taxonomy term pages using views.

Luckily, you won't need to install any additional modules, as in Drupal 8, views are already built in the core, and if you are already familiar with how to style taxonomy term pages in Drupal 7, it will be an easy task in Drupal 8, as most of the steps involved are the same.

Although this aticle was writtne for Drupal 8, most of it still applies in Drupal 9 and Drupal 10 versions. If you need any help with configuring Drupal taxonomy pages I might be just the person you're looking for. As the founder of Terramatris.eu, a Drupal development agency, I have years of experience working with this platform and helping clients achieve their goals through custom Drupal installations. Learn more at Terramatris.eu

Default taxonomy term page view in Drupal 8

Default taxonomy term page view in Drupal 8

In the above example, you can see the default taxonomy term page view (taxonomy/term/%) in Drupal 8. For this tutorial, I'm using Tourgeorgia.eu website, listing tours in Georgia where each tour is tagged with predefined taxonomy, for example, cultural tour, spiritual tour, and so on.

Though technically speaking, taxonomy term pages are not the ones generating the most page views and in fact, are rarely visited, that doesn't mean we should leave a bad user experience. On the other hand, taxonomy term pages might be used in your Drupal's SEO strategy, and in case of that - even more, it's time to make them rock.

Drupal views for Taxonomy term pages

  • Go to the views page (admin/structure/views), edit the Taxonomy term page
  • Under Format, change display from Content to Fields
  • Add fields, like title, body, image, and custom block
  • Exclude all, but custom block fields from the display
  • Construct your display in a custom block using replacement variables, you should add here CSS classes as well
  • Apply CSS to your themes style sheet

Here is the final result

Custom Drupal 8 taxonomy term page

Custom Drupal 8 taxonomy term page

Now, looks much better. As you can see I have displayed additional custom fields on taxonomy pages as well, like price,  and even a direct link to the booking form. The sky is the limit when working with taxonomy term pages in Drupal.

Tip: If you are figuring out how to remove subscribe to RSS link from taxonomy term pages, go back to the taxonomy term page view, select feeds to display, and under the Feed setting remove Attach to Page

Now you have some basic knowledge of how to create custom Drupal 8 taxonomy term pages using views.

In case you are using more than just one vocabulary for taxonomy terms, you could create some additional rewrites per vocabulary. Personally, I prefer using just one taxonomy term page display, with most rewrites done already in views.

Like in the case of tourgeorgia.eu - we have two vocabularies, one for tour type and other tags in free format, using rewrites in Drupal view construct page it's not a problem to display on one page two different displays (see example)

Taxonomy terms from different vocabularies on same taxonomy term page in Drupal

Taxonomy terms from different vocabularies on the same taxonomy term page in Drupal

Here we can see two nodes, both tagged with Tbilisi, the first one is an article, and as you can see from the display it shows an image, title, description, and read more button, while the second is a tour, displaying additional info on the same taxonomy term page, tour type, duration, price, and booking.

When constructing a custom taxonomy view page, make sure to list all possible fields and then use the hide if empty option to rewrite the final result.

Another great feature of Drupal 8, is displaying taxonomy term descriptions on the taxonomy term page, out of the box. It was kind of complicated to get this done in Drupal 7, see: How to List Drupal Child Terms on Taxonomy Pages with Views

Taxonomy description in Drupal 8

Taxonomy description in Drupal 8

There is nothing much you should do to print taxonomy term descriptions on the Drupal 8 taxonomy term page, just edit the taxonomy term and add a brief term description, the rest is handled by the taxonomy/term/% views page.

As you can see - the sky is the limit when dealing with taxonomy term pages in Drupal. If implemented with SEO strategy, well optimized taxonomy pages can help to improve overall site rankings in Google search. 

If you're in need of someone with expertise in Drupal development and module configuration, I might be just the person you're looking for. As the founder of Terramatris.eu, a Drupal development agency, I have years of experience working with this platform and helping clients achieve their goals through custom Drupal installations. Learn more at Terramatris.eu

EU Cookie Compliance For Drupal 8 Website

I'm not an expert in EU laws, but as far as I remember since 2012 there have been passed a law, so called EU Cookie Compliance law, asking website located in the territory of European Union to provide cookie disclaimer to website visitors if any cookie installed on website. 

To play safe, I have enabled cookie information bar on my blog (you can see it in the bottom of each page)

As, recently I started Drupal 8 development on .eu domain website, which actually is hosted from EU territory I decided to wrap up a simple tutorial on best practice how to enable EU cookie compliance notification bar for Drupal 8 websites.

The good news, there is a special module to handle EU cookie directive: EU Cookie Compliance

This module intends to deal with the EU Directive on Privacy and Electronic Communications that comes into effect in the UK on 26th May 2012. From this date on, you run the risk of enforcement action if you are not compliant or visibly working towards compliance. More information can be found here: Privacy and Electronic Communications Directive 2002

The above information applies to the UK however the EU law will be enforced in all EU countries and hence the module can be used everywhere in the EU.

By enabling and configuring the module you will demonstrate to the regulator that you, as the owner of the website:

  • are doing as much as possible to reduce the amount of time before your visitors receive information about cookies (information appears as soon as a visitor enters the site).
  • are providing your visitors with options. (find out more about cookies, do not browse if you disagree).
  • ensure that the information on cookies is readily available to your visitor(visible pop-up at the bottom of the screen).
  • are visibly working towards compliance (even if you do not perform a full cookie audit, it's clear that some effort has been made).

Right, now when you are familiar how this module can help you:

Hope, it helps!