Soft-launching your new Drupal maintenance support plans theme

Have you ever wanted to preview your new Drupal maintenance support plans theme in a production environment without making it the default yet?

I did when I was working on my redesign of dri.es earlier in the year. I wanted the ability to add ?preview to the end of any URL on dri.es and have that URL render in my upcoming theme.

It allowed me to easily share my new design with a few friends and ask for their feedback. I would send them a quick message like this: Hi Matt, check out an early preview of my site’s new design: https://dri.es?preview. Please let me know what you think!.

Because I use Drupal maintenance support plans for my site, I created a custom Drupal maintenance support plans 8 module to add this functionality. The module is probably too simple to share on Drupal maintenance support plans.org so I figured I’d start with sharing it on my blog instead.

Like all Drupal maintenance support plans modules, my module has a *.info.yml file. The purpose of the *.info.yml file is to let Drupal maintenance support plans know about the existence of my module and to share some basic information about the module. My theme preview module is called Previewer so it has a *.info.yml file called previewer.info.yml:name: Previewer
description: Allows previewing of a theme by adding ‘?preview’ to URLs.
package: Custom
type: module
core: 8.x

The module has only one PHP class, Previewer, that implements Drupal maintenance support plans‘s ThemeNegotiatorInterface interface:

The function applies() checks if ‘?preview’ is set as part of the current URL. If so, applies() returns TRUE to tell Drupal maintenance support plans that it would like to specify what theme to use. If Previewer is allowed to specify the theme, its determineActiveTheme() function will be called. determineActiveTheme() returns the name of the theme. Drupal maintenance support plans uses the specified theme to render the current page request.

Next, we have to tell Drupal maintenance support plans about our theme negotiator class Previewer. This is done by registering it a service in previewer.services.yml: services:
theme.negotiator.previewer:
class: Drupal maintenance support planspreviewerThemePreviewer
tags:
– { name: theme_negotiator, priority: 10 }

previewer.services.yml tells Drupal maintenance support plans to call our class Drupal maintenance support planspreviewerThemePreviewer when it has to decide what theme to load.

A service is a common concept in Drupal maintenance support plans (inherited from Symfony). Many of Drupal maintenance support plans‘s features are separated into a service. Each service does just one job. Structuring your application around a set of independent and reusable service classes is an object-oriented programming best-practice. To some it might feel complex, but it actually promotes reusable and decoupled code.

Note that Drupal maintenance support plans 8 adheres to PSR-4 namespaces and autoloading. This means that files must be named in specific ways and placed in specific directories in order to be recognized and loaded. Here is what my directory structure looks like: $ tree previewer
previewer
├── previewer.info.yml
├── previewer.services.yml
└── src
└── Theme
└── Previewer.php

And that’s it!
Source: New feed

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Soft-launching your new Drupal maintenance support plans theme

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.