While updating our Mumbai and Goa itinerary, I had 23 separate place posts to bring into one story. There was the boat ride in Mumbai Harbour, the Gujarati thali in Churchgate and all those stops in Goa. I wanted readers to see where we went and then open the post about whichever place caught their eye. A map after the intro and photo cards at the end seemed like a good way to do it.
My Blog content type already had a Reference field, and the place posts already had their own photos and coordinates. I asked Codex to connect those pieces. In a couple of minutes I had a first version I could try on the India article. Then we worked out how I could turn it on for an older post from the same Drupal edit form.

I’ve been building maps for this site for a while. In 2013 I wrote about putting Drupal taxonomy terms on a map. Two years later I built a site-wide travel map with Views, Location and GMap, with filters for country, region and category.
One Reference field and two Views blocks
We made a View called Trip places with two block displays. Referenced places map uses Geolocation and Leaflet to show published references with coordinates and Display on Map enabled. Click a numbered cluster to zoom in. A single pin opens a link to that place’s story. Referenced places photo cards uses the same references and displays the linked titles and cover photos in the order I set in Drupal.
The layout and map settings live in Views. Our custom module, reinis_trip_places, connects the blocks to the article Drupal is rendering. That includes the current revision when I preview an unpublished update.

Passing the places to the block
Here’s the part that gives the map block its list of places. The module reads the node IDs from field_reference and joins them with + for the View’s content ID contextual filter. The filter is configured to accept multiple values.
$ids = array_unique(array_column(
$node->field_reference->getValue(),
'target_id',
));
$settings = \Drupal::config('reinis_trip_places.settings');
$manager = \Drupal::service('plugin.manager.block');
$block = $manager->createInstance(
$settings->get('map_block'),
['label_display' => FALSE],
);
$block->setContextValue('nid', implode('+', $ids));
The block helper also carries through Drupal’s access and cache information. The block has a contextual default called Reference field on the current article, so it can pick up the references when it is placed through Drupal’s block system. The article display passes the IDs directly from the node revision it is showing. Drupal’s ViewsBlock API
Placing the map inside the story
For the inline map, we attach the rendered block to the article body with a Drupal #post_render callback. Here $map is the render array for the Views block.
if (($build['body'][0]['#type'] ?? NULL) === 'processed_text') {
$build['body'][0]['#referenced_places_map'] = $map;
$build['body'][0]['#post_render'][] = [
TripMapPlacement::class,
'afterIntroduction',
];
}
The callback puts the map after the second paragraph on the India itinerary. On an itinerary with a Day 1 heading, it puts the map just before that heading. The photo cards go in the Reference section below the story.
Trying it on an older trip
I tried the same setup myself on 14 Things to Do in Latgale. I opened the article in Drupal and ticked Show map of referenced places and Show referenced places as photo cards. The 14 places I had linked years ago appeared on the map and in the gallery.

That was my favourite part. I could open an old trip, check two boxes and see it in a different way. I’m going back through a few more travel articles to see which ones already have places ready to go.