Skip to content

Instantly share code, notes, and snippets.

@schnippy
schnippy / resume.json
Last active January 4, 2022 20:54
current resume in jsonresume.org schema
{
"$schema": "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json",
"basics": {
"name": "Greg Schnippel",
"url": "https://registry.jsonresume.org/schnippy",
"image": "https://www.unclosdebate.org/sites/unclos7/files/greg-schnippel.jpg",
"label": "Lead Technical Architect",
"email": "greg.schnippel@gmail.com",
"summary": "Accomplished technical architect, problem solver, and leader with over 15 years experience in building and managing websites, ranging in scale from small citizen sector organizations to large federal agencies and Fortune 500 businesses. Recognized by colleagues as a strong communicator, able to translate complex technical topics for varying audiences as training documentation, technical plans, or business proposals. Highly skilled open-source, LAMP stack developer with expertise in Drupal and Wordpress but with a demonstrated ability to pickup new technologies quickly, deliver projects on short timeframes, and train colleagues.",
"loca

HOWTO: Expose a value in twig templates

We want to encourage front-end developers to use twig templates whenever possible as it makes long-term maintenance and update of the site a lot simpler for everyone involved if the code is easy to read like this:

<h1> Hello, {{ user.first_name }} {{ user.last_name }} </h1>

<p> Today's weather forecast is {{ forecast }} </p>

However in the above simplified example, you can probably see that one of these is going to be readily available by default in Drupal (ex. show me the value of the first_name field from the logged in user) while the other may need to be handled in a custom module. For this example, we might be pulling the forecast from a separate site using a Guzzle REST call, parsing the result and returning it as a formatted result, not something we want to build out in Twig.

@schnippy
schnippy / drupal8-media-entity-file-url.md
Last active April 24, 2024 19:13
Programmatically get file URL from a media entity entity reference field in Drupal 8

Programmatically get file URL from a media entity reference field in Drupal 8

I have a content type with a media (image) entity reference field (field_thumbnail_image) and I want to grab its file URL. For this, I need to load the media entity, isolate its source object using getSource, then load this source as a file entity so I can make a proper URL.

    // load the media entity from the media entity reference field
    $media_entity = Media::load($entity->field_thumbnail_image->target_id);

    // get the file source value for the media entity
 $source_value = $media_entity-&gt;getSource()-&gt;getSourceFieldValue($media_entity);

Getting DIVI 4.0.6 theme working on Pantheon with Wordpress 5.3

We recently updated an older site to Wordpress 5.3 and Divi theme 4.0.6, hosted on the Pantheon platform.

In doing so, we quickly found that we could no longer edit our pages as the Divi builder would not load. The error in the error logs was:

.../data/Utils.php:758  ET_Core_Data_Utils::WPFS():
[ERROR]: Unable to write to filesystem. Please ensure that the web server process has write access to the WordPress directory.

Adding authentication to the Solr 6.x+ admin console on a standalone server.

I have a standalone Solr install on my Ubuntu box which powers a number of Drupal sites. Out of the box the Solr admin panel is unsecured giving attackers the ability to delete, corrupt, or empty out my indexes.

To do this, I need to find my $SOLR_HOME folder (you can find these in the variable dump at the bottom of your Solr admin dashboard ).

For me, with Solr 7.7.2, that is in the /var/solr/data folder. I then create a file called security.json with the following:

{
@schnippy
schnippy / Drupal8Keyword.md
Last active October 8, 2019 03:23
Drupal 8 Keyword list in Twig

Modified this helpful recipe from AgileAdam to be able to take a simple Drupal 8 taxonomy term reference field (field_ct_category), iterate through it and add links to the keyword pages, ex:

Topics: Energy, Immigration and Transportation

<dd class="keywords">
  Topics:&nbsp;{%- for item in content.field_ct_category['#items'] -%}
    {%- if loop.first -%}
      <a href="{{ path('entity.taxonomy_term.canonical', {'taxonomy_term': item.entity.tid.value}) }}">{{- item.entity.name.value -}}</a>
 {%- elseif loop.last -%}
@schnippy
schnippy / terminusTips.md
Last active October 2, 2019 20:07
Terminus Power Tips

A running collection of Pantheon Terminus commands / tips I have collected for sharing.

Running complex Drush commands will often break with 'command not found errors'

For example:

drush MySite.MyEnv config-import --partial --source=modules/custom/myModule

because it is interpreting the command line options after the intial drush command as relevant to Terminus, not Drush and won't know what to do with them.

Drupal 8: Create controller to load random node by type

On many projects, I often have a need to be able to see a random node of a particular content type for debugging or load testing. I use this function on Drupal 8 sites in my core module to add a route of:

http://mysite/random/my-content-type

I use this instead of a view sorted by random because I want to be redirected to the full path of the node.

Leaving off the content-type will use a random type from the array of valid content types I have provided. Providing an invalid content type will redirect it to an item from my core (or default) content-type.

@schnippy
schnippy / machine_learning.md
Last active May 10, 2019 19:42
Practical Applications of Machine Learning with Drupal

Practical Applications of Machine Learning with Drupal

Machine learning is the hot new buzzword in the technology industry with heavy funding from the tech titans. It promises new solutions to complex problems and is already showing its potential with advances in voice assisted technologies and driverless cars capturing the headlines.

But what does any of this have to do with the work we do in Drupal? How can my organization or agency benefit from these technologies?

We are going to answer these questions in this presentation with a focus on the emerging Machine Learning as a Service (MLaaS) platforms that enable you to gain the benefits of Machine Learning without having to spend years collecting data and training a model.

In this presentation, we will address the following:

@schnippy
schnippy / pantheon_search_fix.md
Last active February 14, 2019 20:44
HOWTO: Fix Pantheon Search Instances on Multidev

HOWTO Fix Pantheon Search Instances on Multidev

If you have recently created a new multidev environment on Pantheon and search isn't working for you, this is because you will need to repost the schema and rebuild the search index to get it working.

In multidev, Pantheon is creating a new, full-stack environment for your site, including a new Solr instance but it does not provision a search core for you until you post the schema.

When you login to your environment, go to:

https://SITENAME/admin/config/search/pantheon