Home
A blog about web development and Drupal.

Drupal Planet

October 2, 2015

Offering Configuration Options for a Custom Views Plugin in Drupal 8


In the previous post, we discussed how to write a style plugin for Views in Drupal 8. In this post, we will see how to allow the user to configure our style plugin. We had previously created a class named CardsStyle for the plugin. In order to add configuration options, we will need to extend that class with two new method: buildOptionsForm and defineOptions as follows. In buildOptionsForm, we add our options to the configuration form - in this case, the only option will be to specify the padding in the card items. This works just like a form callback; we can add our fields to the $form array…

September 14, 2015

Building a Views Style Plugin in Drupal 8

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…

August 19, 2015

Building a Configuration Form for a Custom Panels Plugin

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…

July 30, 2015

Showing a Node Status Icon Using a Custom Panels Plugin

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…