• Development

    Adding Fields to Inline Entity Form Table

    Inline Entity Form is a useful module for reference entities and being able to edit them in place.

    Here’s what the edit form looks like out of the box for an unlimited value entity reference:

    Default output

    Often it’s helpful to provide additional information to your editors.

    If you have a look at inline_entity_form.module you will find a function called theme_inline_entity_form_entity_table(). Within this you will see how this table is built, and how you can manipulate the form to add additional columns of information.

  • Development

    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).

    I’ve been using this for development and staging sites that I want to keep private.

    If you want this to be available to all settings*.php files you should put this near the top of your settings.php file:

    Then, you can leverage it wherever you’d like. For example, on an Acquia site I might add this to the bottom of settings.php:

    For non-Acquia sites I’d call the function at the bottom of settings.local.php.

  • 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…

     

  • Development

    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
  • 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:

  • 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:

     

  • 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.

  • Development

    Manually Checking Path-based Visibility in Drupal 8

    This mimics the path visibility settings on block configurations.

     

  • Development

    Block Caching “Gotcha” in Drupal 8

    I recently had a fight with the Block system in Drupal 8. To be brief, if you’re trying to disable caching on a block, make sure to set the #cache element regardless of whether the block has output or not.

    This does not work (empty result gets cached):

     

    This does work (nothing gets cached, as desired):

     

  • Development

    Send email after Migrate Import in Drupal 8

    Here’s an example of a barebones event subscriber to send an email when a Drupal migration finishes importing. The success vs failure logic isn’t working correctly, but you’ll get the gist. If you come up with a solution for this please contact me; I don’t have time to work on it at the moment.

    The file structure looks like this:

    mymodule.services.yml