A custom contextual filter for Views in Drupal 8 is demonstrated using the Data project. Only a small amount of code is needed for the custom filter.
Set up Drupal
Begin by setting up Drupal and installing the Schema and Data projects.
composer create-project drupal-composer/drupal-project:8.x-dev contextual --no-interaction
Create a database and visit the website to install it. Now install a couple of contributed projects.
The link function l() in Drupal 7 has been replaced in Drupal 8 with an object oriented approach. Adding a query and class to the link is no longer obvious.
The l() function in Drupal 7 uses the third parameter for adding a query and a class to the link.
GraphQL is well suited for Drupal since Drupal has a data schema that can be mapped to a schema for GraphQL. The GraphQL Drupal contributed project provides this mapping yet it is rapidly changing and has no documentation. Tutorials are quickly out of date. Some of the more recent changes are covered in this article. It expands on the Decoupled Drupal, GraphQL and React article.
Many tutorials on writing apps try to do almost everything graphically and use very little code. This is great for demonstrating how easy it is to quickly write an app but can leave one without real understanding.
Part 1 looked at how to put the source database credentials in settings.php. Part 2 looks at how to specify the source website root so that files are properly transferred. After the fix for the database settings in part 1 the command for configuring the migration is
drush migrate-upgrade --legacy-root=http://mydrupal7site.com --configure-only
The import of the files is done by running
Suppose that the information to be displayed comes from two different views that somehow needs to be joined. In SQL this can be done using a "UNION' but Views does not have such a construct. But it does not take a lot of code to achieve this in Drupal 8.
Tracking down an error in PHP code often requires knowledge about how the function is being called. In cases such as this a stack trace is often useful to show the call stack. PHP has a function debug_backtrace() that I have found useful in displaying the call stack. But it seems to use a lot of resources. So I wanted to quantify this and try a new approach that I have been using lately. I used something in Drupal 8 that I was debugging. Results will differ greatly depending on the case but the overall trends should be similar. I used