To transform the Product Finder page into a searchable index, we’ll be adding two new filters to the view: one that restricts the results by manufacturer, and another that restricts results to reviews that mention specific words. In this lesson, we'll:
- Add a filter
- Expose a filter
- Set permissions
Additional resources
Drupal 8's out-of-the-box mobile friendliness creates quite the buzz. "Mobile friendly," "responsive," "squishy" — all words to describe the behavior a site invokes on different devices or different screen sizes. Mobile friendly can also mean content first.
Drupalize.Me Podcast Episode 42
Blog postIn this week's episode, 42: Content Delivery Systems (CDNs), Addi is joined by two bots, Joe Shindelar and Ben Chavet, along with Will Hetherington, who is a network consultant for Drupalize
One of the features of the Leaflet module is the ability to change the default map marker image. In this lesson, we'll take the iconic Druplicon and transform it into a map marker for a Leaflet map. In this lesson you'll learn how to change the default map marker image both using the field formatter in a content type's display settings as well as in Views.
Additional resources
Out-of-the-box, Leaflet module comes with one map option. In this lesson we'll add the Leaflet More Maps module to our toolbox, try out other map options, and take a look at implications for zoom settings when choosing an alternative base map layer.
Additional resources
In this lesson, we'll add the Markercluster library and contributed Drupal module which will transform the behavior the Leaflet map markers to display clusters instead of individual markers.
Additional resources
So far in the Mapping with Leaflet series, we've taken advantage of the field formatter provided by the Leaflet module to display a map on a page for a piece of content containing location data. This resulted in a single marker on a map. But what about a map of multiple locations? For this, we'll get to use Views and the Leaflet Views module that is included in the Leaflet project download. We'll also address a common problem of transforming postal addresses into geocoded data that a map can use. For this, we'll look at a solution that integrates Geocoder and Address Field modules. As a bonus, I'll walk you through the process of configuring a Feeds Importer to work with the esoteric and possibly confusing Address Field targets and I'll demonstrate how to import .CSV text file of postal addresses into Address Field, which is then geocoded and displayed on a Leaflet map.
Manually entering a latitude and longitude for each node is a tedious process. Just finding out what those numbers are for a given location less than ideal. One of the most common ways to communicate a location to another person is by using a postal address. How many times do you enter a latitude and longitude into your favorite mapping app to get directions? Hardly ever, right? Most of the time you would just enter the street address and the app "just knows" how to find it. In this lesson, we'll configure our Drupal site to Geocode a postal address into geographic data that our Leaflet map can display.
Additional resources
n the previous lesson, we configured the location content type to collect address data using Address Field module. Then we brought in Geocoder module and configured the Geofield on our location content type to use the data from the Address Field. With Geocoder all set to transform that address data, we are now ready to create some new location nodes. Since the process of geocoding addresses happens behind the scenes when a new node is created or when a node is edited and saved, it was important to do this configuration first, before creating any more location nodes. To expedite data-entry, in this lesson, I'll walk through the process of importing a comma separated value text file or CSV file into a Drupal site with Address Field using Feeds.
By the end of this lesson, you'll understand what data you need to be sure and include in your CSV to avoid trouble with Address Field, how to configure a feeds importer, and how to configure the field mapping in the importer with the somewhat esoteric field names that Address Field provides.
Additional resources
Before we can display a location on a map, we need to decide on a location storage method. This is a critical step because not all storage methods are compatible with every mapping module. Since we'll be using Leaflet, we'll need to use Geofield to store our geographic data. Geofield will provide us with a new type of field that we can add to any entity bundle or content type. Geofield provides many different field formatters that can display geographic data in a variety of formats, such as latitude and longitude or well known text. By the end of this lesson, you should be able to download and install Geofield and its dependencies, add a Geofield to a content type, and enter in the latitude and longitude for a location node.
Additional resources
Let's Debug Twig in Drupal 8!
Blog postWhen I am theming a Drupal site, I need to know which variables are available on a template file. In Drupal 8, the template engine is Twig, so we’re going to need to know a little bit of Twig to make this work. So, if Twig is totally new to you, don’t worry. Today, you’ll learn some Twig!
Drupalize.Me Podcast Episode 41
Blog postIn Episode 41, Virtualization with Vagrant, Emma Jane Westby and Erika Heidi chat about creating virtual environments with Vagrant. Through their light-hearted approach to technical topics, we hope Emma and Erika are able to make Vagrant seem a little more accessible, if not downright fun.
Before we can display a location on a map, we need to decide on a location storage method. This is a critical step because not all storage methods are compatible with every mapping module. Since we'll be using Leaflet, we'll need to use Geofield to store our geographic data. Geofield will provide us with a new type of field that we can add to any entity bundle or content type. Geofield provides many different field formatters that can display geographic data in a variety of formats, such as latitude and longitude or well known text.
By the end of this lesson, you should be able to:
- Download and install Geofield and its dependencies GeoPHP and CTools
- Create a field on a content type using Geofield
- Enter a latitude and longitude for a location node
Join Amber Matz as she walks you through how to prep your site to store location data using Geofield module.
Additional resources
Mapping with Leaflet
CourseGeographic information is used to find a location, get directions, or check on traffic – and so much more. In the Drupal mapping world, solutions range broadly.
Leaflet is one solution that works for many situations. In this series, you'll get up and running with mapping using Leaflet. We’ll add and configure field types, install Leaflet, and create and customize maps. When you complete this series, you'll be able to create a map of both single and multiple points, geocode address data, configure geofield to store geographic data, and customize the look and feel of your Leaflet maps interface.
Now that we've stored the latitude and longitude for a node, we can display it on a map. In this lesson, we'll take a look at the documentation for Leaflet and we'll download and install the Leaflet JavaScript library and the Leaflet Drupal module, which loads the Leaflet JavaScript library and provides configuration options that we'll use later on.
By the end of this lesson, you should be able to:
- Install Leaflet and its dependencies to your Drupal site
- Configure a Geofield field to display as a Leaflet map
Additional resources
The concept of blocks has been around in Drupal since the earliest versions. Chunks of information that can be placed into the regions provided by a theme and re-used throughout your site. The system for defining blocks in code has changed quite a bit for Drupal 8 though so it's worth taking a fresh look at how to create blocks in your own module. Especially since in my experience it's one of the first things we need to know how to do as module developers.
Configuring new servers by hand is tedious and prone to error. Instead of running all the installationa commands by hand to customize our Vagrant setup, we'll use a configuration management (CM) tool to automate this process for us. CM allows system administrators to establish rules which maintain the software installed on one or many computer systems. By automating the setup of a server, configuration management ensures there are no inconsistencies between machines. It also makes it faster for your to create a virtual environment without having to manually install a Web server, like we did in a previous lesson.
Lesson Outcomes
By the end of this lesson, you will be able to explain how configuration management relates to virtual machines, and why you would want to use a configuration management tool to provision new virtual machines.
Lesson Summary
- Vagrant is a wrapper which creates virtual development environments from base boxes. It acts as a wrapper around a provider, such as VirtualBox, and configuration management software, such as Chef.
- Configuration Management: Configuration management is a process which allows system administrators to establish and maintain consistency of a computer system throughout its life against a specified set of rules. Configuration management enables consistency across one, or many, machines.
- Popular open source configuration management tools supported by Vagrant include: Puppet, Chef, and Ansible. Chef tends to be popular among Drupal developers. Puppet tends to be popular among system administrators (who are not necessarily Web developers first-and-foremost).
- Provisioning is the process of creating, or altering, a system in order to prepare it for service.
- Vagrant allows you to use one or more configuration management tools from the same Vagrantfile to provision a machine; as well as use shell scripts.
Additional resources
In the previous lesson we discussed why you would want to use a configuration management tool. In this lesson we'll dive into how you automate the customization of new servers using the configuration management tool, Chef. Most of the work in assembling Chef recipes is already done for you. In this lesson you will be able to see how the pieces fit together; however, you will not be required to download each of the individual recipes to get everything working.
Lesson Outcomes
By the end of this lesson you will be able to describe how to add a Chef recipe to your setup, and re-provision Vagrant.
Lesson Summary
In the video, I've already setup Chef recipes, roles, and cookbooks for you. So instead of having to download all the pieces separately, you can just start with the code bundle for this lesson.
The outline provided below, however, includes each of the steps that I went through to prepare the configuration Chef recipes and roles that you're downloading.
Locating and Using Chef Cookbooks
- Locate Chef cookbooks for AMP stack, drush, and Drupal-specific PHP libraries you want pre-loaded.
- Place downloaded cookbooks into a sub-folder in your project directory. For example:
chef-recipes/cookbooks
. - Create a role file to include all of the recipes (from each of the cookbooks) you want to load. This file can be placed into its own roles sub-directory. For example:
chef-recipes/roles/lamp_stack.rb
. - Update the Vagrantfile to include:
- path to cookbooks folder
- path to roles folder
- role(s) to load for this server
- new values for any of the default settings for your recipes
- Provision the machine to enable / set-up / trigger the Chef configuration settings:
$ vagrant provision
The machine is now configured, but does not have Drupal installed. This is on purpose. You probably have a specific Drupal project you're working on.
Customizing Configuration Files to Use Chef Recipes
The role files contain a list of individual recipes, and/or roles that must be run to provision a specific type of server. Generally there are three or four parts to them.
- name
- description
- run list (recipes and roles to add)
- default settings for recipes (optional)
You should investigate the contents of the folder chef-recipes/roles
. There is a detailed README tailored to this learning series, as well as the two roles that were created for this lesson.
The Vagrantfile is well commented, this section includes a quick references of the settings that have been updated in the file.
config.vm.provision :chef_solo do |chef|
# default settings
chef.cookbooks_path = "path_to_cookbooks_folder"
chef.roles_path = "path_to_roles_folder"
# roles and recipes to load
# recipes are generally loaded from within roles
chef.add_role "name_of_role"
chef.add_recipe "name_of_recipe"
# overrides for settings in recipes
chef.json = {
"name_of_recipe" => {
"name_of_setting" => "new_value",
},
}
end
Gotchas
- If you are using these recipes for Drupal 8: the recipe provided for Drush won't work. You'll need to install Drush version 7 or greater (compatibility chart on the Drush project page).
- You will probably want to update Chef with the omnibus plugin for Vagrant if the cookbook you want to add requires a newer version of Chef. On the host machine, install the plugin:
$ vagrant plugin install vagrant-omnibus
. Note: Chef must be updated before it is "run". For this lesson, I opted to use older versions of the cookbooks. 20 hours of my life spent working on upgrades that didn't work. The later scripts provide more flexibility (e.g. install ANY version of Drush, not just 5.8), but they work well enough for our needs. - Apt will only run if the cache is older than a day. The first time the machine is provisioned, this might be a problem. You can force updating the cache with the following setting in Vagrantfile:
chef.json = { "apt" => {"compiletime" => true} }
- If you are running into problems with permissions, refer to the tips in Sharing Files Between Your Guest and Host Machine.
- Windows users will also need to download the following cookbooks, and add them to the directory you have configured for chef.cookbooks_path
- chef-handler
- chef-sugar
- iis
- windows
- xml
- yum
- yum-epel