Home
A blog about web development and Drupal.

hooks

November 23, 2015

Where is hook_page_alter in Drupal 8?

In Drupal 7, hook\page\alter was a convenient way to go when we needed to modify page elements that were added by other modules. Drupal 8 does away with this hook - hopefully for the better. To fill the void created by hook\page\alter’s dismissal, the following hooks have been introduced. - hook\page\attachments() - hook\page\attachments\alter() - hook\page\top() - hook\page\bottom() - hook\theme\suggestions\HOOK() - hook\theme\suggestions\HOOK\alter() In addition, we can still implement hook\preprocess\page, which does let us override or add content to the page. However, this hook is…

February 23, 2015

Changing Link Texts in Solr Facets

In a recent post, I wrote about how we can group items in Solr search facets. This latest addition to the Solr post series will discuss how one can change the link text in Facet API’s Drupal blocks. Let’s assume I have a content type facet, as illustrated in the image below, and I wish to change the link text of the Discussion filter to Thread. Now, this sounds easy, right? One would think you could just implement hook\block\view\alter, and change the block’s content. However, this will turn out not to be the best approach. Even though this will allow you to manipulate the facet block’s…

February 6, 2015

Three Options to Rename Drupal Paths

Built-in Drupal pages and pages created by contrib modules have static paths that are hard-coded. An example of this would be /user where you can log in, or /node, which shows a list of recent nodes. Often times, we care about what the URL in the browser’s address bar looks like, and wish to change these. This post is a summary of three options to achieve this. Creating an alias Drupal has support for path aliases, which allows us to specify alternative paths for pages. This is the simplest solution and works in most cases. Some aspects of this solution that may be undesirable in certain…

November 29, 2014

Grouping Values in Apache Solr Facets

It is common nowadays for Drupal sites to offload search duties to Solr by employing the Apache Solr Search and Facet API modules. Working together, these two modules can automatically build search facets that display filters for various aspects of the content, such as the content type, or taxonomy terms. In certain cases, it might be necessary to influence the way those facets filter content. This post will discuss a scenario where we may want to group multiple filters together inside a facet block such that they only appear as one item. This method may be useful if the site has too many…

June 12, 2014

Writing Field Handlers for Views

While working on a recent project, we found ourselves in a situation where we needed to customize a Views field in a way that was not possible using Views' configuration or theming. In such cases, writing a custom Views handler might be the best or only option. Let's assume the following scenario: we need to build a list of contents that has two columns. The first column shows the content's title, and the second shows the content's status. If the content is published, the second column shows the date the content was created, but if it is not published, the field in that column only shows…