Basic HTTP Authentication in Drupal Site Using settings.php

Here’s a quick and painless way of preventing public access to a Drupal site using settings.php (or settings.local.php):

 

Tagged with: , , ,
Posted in Development

Valet+ Quickstart for Drupal Development

Here’s a README.md file that I’ve developed over time. It explains how I setup and use Valet+ for quick and powerful Drupal development.

Sorry for the formatting. I’ll get markdown support on my blog sometime…

 

Tagged with: , , ,
Posted in Development

Setting up OCI8 (PHP Oracle module) on Webfaction

Webfaction, my favorite web host, allows you to compile PHP modules in your home directory for use on your websites. Here’s the process for configuring OCI8 to talk to Oracle databases:

 

Tagged with: ,
Posted in Development

Mac High CPU Usage – WindowServer

DISCLAIMER: I’m writing about my personal experience here. I am by no means doing some exhaustive investigation. The changes I explain below seem to make a difference, at least according to what Activity Monitor is showing for CPU usage.

My laptop (3.1GHz i7 MacBook Pro with 16GB of RAM) has enough of power, so why has it been such a dog since starting from scratch with a fresh OS? A colleague posted an animated Gif today in Slack and my MacBook fans kicked in and it sounded like it was getting ready to fly away. This was the last straw in what has been weeks of wondering why my laptop has been slow.

I opened Activity Monitor and found that my WindowServer process was using a significant amount of CPU resources (up to 77% when the animated gif was visible on my screen), and that it has used significantly more than the next heaviest process since I last rebooted.

I understand that it’s probably a pretty heavy process, but it got me thinking, and Googling. As it turns out, when something is being drawn to the screen it takes processing power; go figure! One of the top suggestions was removing or disabling things from the menu bar that are constantly updating. The suggestions included CrashPlan and Little Snitch Network Monitor. Wow. I use the latter! I opened the Little Snitch preferences and unchecked “Show network activity in menu bar” and voila! the WindowServer process memory dropped about 15%. Then I closed the animated gif my colleague posted in Slack (the only other thing on the screen that was moving) and voila! it dropped again.

Now, as I’m looking at my CPU Time in Activity Monitor I’m thinking through what I really need running. Is the “Next Meeting” (which shows the name and time of my next meeting in the menu bar) application really worth running 24/7? I don’t think so; especially if I have more important things for my CPU to be doing. After quitting this application my WindowServer CPU usage dropped to 6.6%.

I’m going to continue to trim the fat to see how lean I can make my machine. Obviously it doesn’t stop at just trimming out running applications, but I’m blown away by the impact of small changes like these.

Tagged with: ,
Posted in Tech Tips

Drupal 8 User Photo Update Form

Recently I had to come up with a simple way for users to change their member profile photo without requiring them to visit the user edit screen. Here’s the result:

Member Photo Output

First, I added a new Image field called “Member Photo” to the user account fields (machine name field_user_picture). Here are the settings I used:

  • Allowed extensions: png, gif, jpg, jpeg
  • File directory: users/[date:custom:Y]-[date:custom:m]
  • Max size: 10 MB
  • Checked: Enable alt field
  • Checked: Alt field required

Read more ›

Tagged with: ,
Posted in Development

Creating a Drupal 8 Route to a User Page with Dynamic User Object

It took me some time to figure out the right combination of properties to make this work.

My goal was to create a form that lives at /user/UID/photo (think /user/1/edit).

I wanted the user object to be passed into the form as an argument.

Here’s the mymodule.routing.yml file:

Here’s the src/Form/ProfilePhoto.php file: Read more ›

Tagged with: ,
Posted in Development

Make a Field Label “visually-hidden” in Drupal 8

Using the Form API you can add a visually-hidden class to a field using the “#title_display” property as shown here:

 

Tagged with: ,
Posted in Development

Drupal 8 Search API Tips

Here are some quick tips for configuring Search API for Drupal 8.

Easy Indexing

If you’re like me you rely heavily on Display Modes (aka View Modes) for your entity types. The most convenient way to get Search API to index your data is to use the Search Index view mode on any entity types you will index. If you’re using Display Suite you may want to choose a layout that doesn’t include authoring information, published date, etc. Just fill this view mode, in each entity type, with the fields you want to index. If you plan to use this to drive the output, you should also hide labels and do whatever else will ensure clean output; more on this later.

I suggest indexing the Title (in the case of content types) separately. More on that in the Boost notes below. Read more ›

Tagged with: , , ,
Posted in Development

Manually Checking Path-based Visibility in Drupal 8

This mimics the path visibility settings on block configurations.

 

Tagged with: ,
Posted in Development

Tideways and Xhgui using DevDesktop and Docker

THIS POST IS UNFINISHED. Use at your own risk. I needed to share with a colleague, so I’m just getting it out into the world. Your Mileage May Vary!

I’ve been working on some large Drupal 8 migrations and have been wanting to profile them for some time due to a few migrations taking far more time than I expected. Acquia DevDesktop, which I happen to be using for this site, offers xhprof in the older PHP environments, but I wanted to get something setup in PHP 7.

For PHP 7 the recommendation is to use Tideways; it’s a modern fork of xhprof. After collecting (tracing/profiling) the data with Tideways you need a way to analyze the data. I used a Docker environment to get Xhgui running. Here’s what a few xhgui screens look like. The best part is that nearly everything is clickable so you can drill down to figure out what’s slow, and why! Read more ›

Tagged with: , ,
Posted in Development