Drupal Blog

2017-03-11

One of the things that makes Drupal a great CMS is the quality and robustness of its modules. Today I wanted to shine a spotlight on the Pathauto module. From Pathauto's project page;

"The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias. This allows you to have URL aliases like /category/my-node-title instead of /node/123. The aliases are based upon a "pattern" system that uses tokens which the administrator can change."

Tokens require the Token module, which you'll likely need anyway, because it's required by many modules. You also should really install Redirect, so that whenever an item's URL alias is changed, the system will automatically created a redirect (so you don't start racking up 404 errors). After installing Drupal core, we ALWAYS install Pathauto, Token, and Redirect at a minimum; they are that essential.

Now let's stop and think for a moment why we might want to be able to set URL patterns. Imagine you have a blog and you want to control the URL pattern.

Custom URL patterns in WordPress and Joomla

In WordPress you can adjust the Permalinks, and it does offer an option called Custom Structure with token-like placeholders. This is rather limited though in terms of the available placeholders. You can of course change the slug (a.k.a. alias) for each individidual post/page/category manually, but that's silly to even contemplate on large sites. Long story short, there's no WordPress equivalent for defining across-the-board URL patterns with ease the way that you can with Drupal's Pathauto module.

We have had to deal with URL patterns in Joomla before as well. That can be a frustrating experience on larger sites, because Joomla relies so heavily on its menu system, meaning a page must be in a menu for its URL alias to be set to what you want. You can set up categories and subcategories, which Joomla will use for the generated URLs. There have been attempts at making Joomla's URL structure more customizable (sh404sef comes to mind here), but these are complex and they take over some core functionality, making it incredibly difficult to uninstall should you decide to uninstall it later on. And they never quite offer the same level of control and ease of use that Pathauto does.

Pathauto Example

Let's start with the Pathauto admin screen:

Drupal PathautoThe above screenshot is from Drupal 8, but it's pretty much the same in Drupal 7. It shows a few URL patterns tied to specific content types, followed by a default of [node:title]. This means that if I add a node such as News that has no pattern defined, it will still get an SEO-friendly URL based on its title, so if its title is "My Great News Item", its URL would be "/my-great-news-item". But if it's a picture with title of "Our New Gallery", it would be "/pictures/our-new-gallery". 

Pathauto is really great in combination with Views, specifically Views page displays. In the screenshot above you see we have a content type called Person, with a URL pattern of "bios/[node:title]". We also have a view page display with URL of "/bios". So visitors go to "/bios" and then they click on a bio, and that bio will follow the above URL pattern. Using Pathauto and Views together in this manner we can enforce consistent URL patterns across the site, without forcing editors to think about URLs as they're editing. It just works.

If you want to show 'breadcrumbs' e.g. "Home > Bios > Some Person", the Pathauto/Views combination is particularly useful when combined with Easy Breadcrumb. It relies on your URL patterns for generating its breadcrumbs. 

While we use Pathauto primarily for nodes (content / pages), it can also be used for users, taxonomy, and other Drupal entities. I highly recommend it and consider it essential to any Drupal site.

2016-08-17

Developing any kind of enterprise site typically involves multiple environments, for example Development, Staging, and Production. A very common scenario developers run into is that a site is developed locally (on the developer's own machine) and then the code changes get pushed to a repository (version control using Git, Subversion, Mercurial, etc). But what about database changes? Those aren't code ... but they can be.

What is considered configuration?

Module configuration (set via Drupal's UI), content types, fields, Site Information settings, basically any kind of settings that you can control from Drupal's UI. Content (nodes, terms, users or any sort of entities) is not part of this and does not get exported.

How to copy configuration from one site to another:

Keep in mind this will only work for the same site, existing in two different environments. The typical way this would go is you create a site in one place (some cloud server e.g. Amazon Ec2, RackSpace CloudServer, Linode, Acquia Cloud, Pantheon, etc), do some initial commits after getting Drupal set up there, and then clone that locally in your computer. There you can go to town and add all the modules and code you want, configure everything, then export it and import it back into the remote dev site.

Before attempting to export your configuration, make sure to commit all your code changes, push them to the repo, and make sure the remote dev environment has pulled those changes. You don't want to try and change settings for modules that don't yet exist in code - that can lead to all kinds of nasty things!

In Drupal 7 this was accomplished using the Features module, which is a pretty complex beast to work with, but very powerful too. The Features module has been made part of Drupal 8 core and is now known as Configuration Synchronization. This can be accessed from the Configuration > Development > Configuration Synchronization menu (/admin/config/development/configuration):

​(Drupal core's admin menu does not have dropdowns by default. Install the Admin Toolbar module for that awesomeness.)

Next, click Export (/admin/config/development/configuration/full/export) you can export:

This gathers up all your settings and downloads a gzipped tarball for you. Now go to your remote dev environment, log into Drupal, and go to Import (/admin/config/development/configuration/full/import):

As you can see, it provides you an overview of the new/changed items it will import. In this case I had added a single text field called "Sample text field" to the Basic Page content type. Click "Import all":

This does not always complete without error. Sometimes it will fail with obscure-looking fatal errors (500 - Internal Server Error), but so far I've found if you re-run the import it will usually complete without further issue. Such errors can be useful for ironing out configuration issues though, so pay attention and see if you can fix whatever is triggering those.

And that's it! My field was created. Here's a screenshot of the Basic Page content type's fields on the remote dev site:

Multiple the above by a zillion for the number of other settings a complex Drupal site can have, and you can see how incredibly useful the Configuration Synchronization in Drupal 8 is. It has made great strides in becoming easy to use. The UI is admittedly very simple, and for a full-site export that's a good thing. If you want more fine-grained control in order to export only certain things, this too is possible. Have a look at /admin/config/development/configuration/single/export:

This allows you to export specific settings, for example for a content type, a field, text format, menu, etc. This does not yet allow you to select multiple such settings and export them together, so you have to either export EVERYTHING or export just one thing at a time. When you do export one item, you'll need to copy the resulting code, then go to the destination site and import a single item... there you can paste this. Make sure you select the same "Configuration type" option from the pulldown menu as when you exported it:

This aspect of Drupal 8 is a real time-saver, and takes a lot of human error out of the equation. We're excited to take advantage of this in our current and upcoming work!

2016-06-14

We had added a new term reference field to one of our content types, but it already had an term reference field in place, and had data in it. We needed to populate the new term reference field with the data from the old field, so that we could then delete the old field. 

Had this been a text field, it would have been easy to achieve this using Views, Admin Views (optional), Views Bulk Operations, and Token. Using VBO with "Modify Entity Values" you could then paste a token in the desired text field, and run this on whichever nodes you want - in bulk. Admin Views is a handy way of improving the /admin/content overview, enhancing it with content type and keyword filters with Ajaxy goodness.

Term reference fields don't accept text or tokens that way. In that case we can use VBO's "Execute Arbitrary PHP Script" option, using the following code. 

[This is for Drupal 7]

 

$node = node_load($entity->nid); 
foreach($node->taxonomy_vocabulary_7[LANGUAGE_NONE] as $tid){ 
  $node->field_campus[LANGUAGE_NONE][0]['tid'] = $tid; 
} 
node_save($node);

 

Since VBO runs this on one node at a time, in bulk, node_load is still decently performant. If you were to do something like this in custom code - without VBO - it would be better to use entity_load() along with entity_save() for some performance gains. Using the above code I was able to get the new field populated with VBO in a matter of minutes, as opposed to manually editing 150 nodes, or doing this some other way (custom SQL query, custom module, etc).

2016-04-26

Engaged learning microsite selected among nearly 13,000 entries

A Rider University microsite has been selected as an Official Honoree for the 20th Annual Webby Awards. The distinction puts Rider in the top 20 percent of nearly 13,000 entries from 66 countries around the world. 

The microsite focuses on engaged learning at Rider, showcasing the multiple ways in which the University creates opportunities for profound learning experiences. The site highlights the opportunities and results of students participating in internships, study abroad, service learning, student/faculty collaboration, the arts and leadership development.

“The engaged learning microsite takes users through a series of high-impact visuals, which include video and interactive storytelling, that portray how our students take part in a vibrant learning community and cultivate the foundation needed for future career and personal success,” says Rider’s director of enrollment digital strategy, Tara Laposa, who oversees every aspect of the website, including design, strategic planning and execution. 

Plethora built this microsite from the ground up and designed its UI with jQuery, CSS, and a responsive layout.

2016-03-02

That's right, Drupal 6 is at 'end of life' (EOL). 

Drupal 8 and 7 have both had security patches. Drupal 6 got a final security patch as well.

If your Drupal installation has not been updated in a while, make sure to get it taken care of soon, or drop us a line. 

2016-01-31

Our design for EIT Avionics was recently featured on Drupal.org's Featured Showcase. It is currently displayed on the drupal.org home page and as the first item on https://www.drupal.org/case-studies . In our case study we go into detail about the process of building a Drupal 8 site before the full release was out, which certainly posed some challenges. View case study »

2016-01-17

Drupal just celebrated a major milestone - its fifteenth birthday!

The Drupal project has grown tremendously over the years and with Drupal 8 it is now 'off the island'. Since its early days, Drupal has held on to its own internal ways of coding and using PHP, but with Drupal 8 this change changed dramatically. Now Drupal uses Composer, OOP, Twig, YAML, and Services to name a few. This new policy of openness will help Drupal grow and improve. It will allow themers to do their thing and coders to do theirs - better than before.

Drupal founder Dries Buytaert's post about Drupal's 15th birthday

2015-11-11

It's official: Drupal 6 will be going the way of the dinosaurs on February 24th, 2016.

Have a look at the official announcement

Sites still running Drupal 6 could continue to do so, but without Drupal community support. This means you'd be on your own when it comes to security issues, patches, and the like. If you're running a dedicated or virtual dedicated server, you can of course continue running PHP 5 but eventually that too will become untenable, because if you have PCI scans the scanner may force you to upgrade PHP, for example.

Updating Drupal 6 to 7 (or 8! is not easy but we have tools in our arsenal to get it done. 

2015-10-30

Drupal 8 will be released November 19th. It is currently at rc2 (release candidate two) and there may be one or more additional release candidates before then. 

We have already built a number of sites with Drupal 8, and love it. The code is leaner and meaner, and the administrative interface is much more intuitive and streamlined, and (we think) gives WordPress's UI a run for its money. On top of that, you get the full power of Drupal's content types, fields, and views at your disposal, something WordPress cannot match, though there are some plugins that do similar things.

More details here.

2015-10-20

Clients often ask us to set up CSV feeds / exports of views (lists of data). Now that Drupal 8 rc1 is out and we're starting to use Drupal 8 more and more, we're running into more and more requests for CSV export on Drupal 8. 

For example, let's say the site has a page that lists a company's staff directory, and HR wants to be able to download CSV containing all the staff member details for use elsewhere. This is a perfect use case for the Views Data Export module, together with Views. Views is built into Drupal 8 core. 

We can just add that CSV export onto an existing view

As of about one month ago there is now a Drupal 8 port of Views Data Export - have a look here and here. We have used it to put together a basic CSV export display in a Drupal 8 view, and it works as expected. This module is still very much under development, but it is looking quite solid and promising so far.

Pages