Skip to content

Instantly share code, notes, and snippets.

@mrkmiller
mrkmiller / theme-settings.php
Last active July 7, 2025 23:18
Add a custom image to a theme settings page
<?php
// TODO: Replace THEMENAME with the machine name for your theme.
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Entity\File;
/**
* Implements hook_form_FORM_ID_alter().
*/
@mrkmiller
mrkmiller / SeedFixtures.php
Last active May 12, 2023 18:59
Seed Cypress data into a Drupal site using JsonAPI fixtures. You will need to create a module and set up a controller to execute the SeedFixtures.php class. This will require enabling the JsonAPI module.
<?php
namespace Drupal\my_module_name\Cypress;
use Drupal\block\Entity\Block;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
import {LitElement, html} from 'https://cdn.jsdelivr.net/gh/lit/dist@2/core/lit-core.min.js'
import jsonapiParse from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'
import dayjs from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'
class SFEventListing extends LitElement {
static properties = {
baseUrl: {type: String},
url: {type: String},
imageUrl: {type: String},
imageAlt: {type: String},
parameters:
# Configure Cross-Site HTTP requests (CORS).
# Read https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
# for more information about the topic in general.
# Note: By default the configuration is disabled.
cors.config:
enabled: true
# Specify allowed headers, like 'x-allowed-header'.
allowedHeaders: ['x-csrf-token', 'authorization', 'content-type', 'accept', 'origin', 'x-requested-with']
# Specify allowed request methods, specify ['*'] to allow all possible ones.
@mrkmiller
mrkmiller / THEMENAME.libraries.yml
Last active July 6, 2021 22:37
Conditionally attach a library in Drupal based on environment
my_lib:
js:
https://path-to-file/my-script.min.js: {type: external, minified: true}
my_lib.test:
js:
https://path-to-file/my-script-test.min.js: {type: external, minified: true}
my_lib.dev:
js:
@mrkmiller
mrkmiller / react-loop.js
Last active April 22, 2020 03:38
Vue/React loop
function BasicLoop(props) {
const items = props.items;
return (
<ul>
{items.map((value, index) => {
return <li key={index}>{value}</li>
})}
</ul>
)
@mrkmiller
mrkmiller / sfseed.settings.yml
Last active April 1, 2019 17:45
sitefarm seed brand color application in a theme.
article_category_field: field_sf_article_category
event_category_field: field_sf_event_type
photo_gallery_category_field: field_sf_gallery_category
branding_field: field_sf_branding
brand_color_field: field_sf_brand_color
@mrkmiller
mrkmiller / FocalLinkIcon.php
Last active January 9, 2019 19:07
Focal Link Icon block style plugin. Replace "custom_theme" with the name of your theme and add fontawsome to the library.
<?php
namespace Drupal\custom_theme\Plugin\BlockStyle;
use Drupal\block_style_plugins\Plugin\BlockStyleBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a 'FocalLinkIcon' style.
*/
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.storage.node.body
- node.type.sf_article
- taxonomy.vocabulary.sf_article_category
- taxonomy.vocabulary.sf_article_type
content:
@mrkmiller
mrkmiller / services.local.yml
Last active October 10, 2019 17:13
SiteFarm local development settings files
# Local development services.
services:
cache.backend.null:
class: Drupal\Core\Cache\NullBackendFactory
parameters:
session.storage.options:
# Default ini options for sessions.
#
# Some distributions of Linux (most notably Debian) ship their PHP