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.
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.
Drupal 8 forms are usually classes that inherit from the FormBase class. The FormBase class provides underlying functionality such as AJAX for Drupal forms. This article explores how to use only the form API without the FormBase class yet provide a light weight AJAX behavior. To keep this from getting too complex only buttons and event handling are considered. While this
Integrated Development Environments (IDEs) are nice for debugging problems but with Docker containers they have to be set up to work remotely. Vim may not be as nice an interface but has an advantage of being able to run in the container making it easier to get set up and running quickly. This is especially true for new releases where there is not much information yet on configuration.