
Drupal 8 is just around the corner, and it has reached an important milestone: beta-to-beta updates will be provided for each beta release going forward. That gives me some confidence that no major re-works are to be expected if I start building with Drupal 8. That said, we are still facing a sizable documentation gap regarding the changes in the API. My first encounter with this problem was when I was building a custom style plugin for Views. This post discusses how this is done in the new version of everyone's favorite CMS. In Drupal 7, we had hook\views\plugins(), which let us register new…
In my previous post, we built a custom Panels plugin that shows a node status icon to indicate whether the node is published or unpublished. This time around, we will enhance that plugin by introducing a configuration form. For the sake of demonstration, we will add a setting that lets the user choose when they want the show the status icon: only when the node is unpublished, or always. As one might expect, we will need to use Drupal's From API to define the configuration options. First, we need to tell Panels which function to call when it shows the configuration form. This can be done by…
We often use Panels to build node page layouts, because it enables a vast range of options to show content in various sections of the page. In addition, you can develop a custom plugin for Panels, which brings ultimate flexibility. I took that route when I needed to display an icon next to the node’s title to indicate whether it is published or not. The Panels module relies on the Ctools plugin API, so in order to add our custom plugin to Panels, we need to implement hook\ctools\plugin\directory(). This will tell Ctools where it can find our plugins. This hook gets called multiple times, but…
When I need to filter a view based on some elaborate condition, I often find myself using Drupal Views' contextual filters. Normally this kind of filter is supposed to pull the filter value from the URL, but it also lets you select other methods of finding a value if it’s not in the URL. For instance, if the filter is for the author, you can configure the view to use the current user’s ID. Even though this is very flexible, you may occasionally need filtering that cannot be set up with the available options. To overcome the limitations, you can add your own filtering logic by developing a…
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…