Skip to content

Instantly share code, notes, and snippets.

View shelane's full-sized avatar

Shelane French shelane

View GitHub Profile
@shelane
shelane / gist:3e4edcab3a4224266f54d56bae3bb011
Created July 18, 2024 11:40
Best CSS trick: instead of position relative + position absolute; use grid to overlay children
.parent { display: grid; }
.child { grid-area: 1/1; }
Instead of:
.parent { position: relative }
.child { position: absolute; top: 0; left: 0; width: 100%; height: 100% }
@shelane
shelane / DrupalCallback.php
Created July 19, 2023 19:10 — forked from purushotamrai/DrupalCallback.php
Implementing Custom Pagination without Drupal Entity Query - Drupal 8
<?php
namespace Drupal\custom_module\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Pager\PagerManagerInterface;
class ListNonDrupalItems extends ControllerBase {
@shelane
shelane / range.php
Created July 7, 2023 03:29
replace display day, month, etc with range function
<?php
// This is leading zeros:
$n = 10; // The desired end number
$numbers = range(1, $n);
$numbersWithLeadingZeros = array_map(function ($number) {
return sprintf('%02d', $number);
}, $numbers);
@shelane
shelane / displaytime.php
Created July 7, 2023 02:54
generate times by half hour increments
<?php
// This should replace the DisplayPracticeTimes function.
$startTime = strtotime('08:00');
$endTime = strtotime('21:00');
$increment = 30 * 60; // 30 minutes in seconds
$times = array();
@shelane
shelane / D9 example code
Created May 10, 2021 22:29
Basic code examples for Drupal 9
<?php
// Load a Node
use Drupal\node\Entity\Node;
$node = Node::load($nid);
// Load Multiple Nodes
use Drupal\node\Entity\Node;
$nodes = Node::loadMultiple($nids);
@shelane
shelane / nodemaker_term_create.php
Created March 2, 2021 19:52 — forked from himerus/nodemaker_term_create.php
Create a taxonomy term programmatically in Drupal 8.
<?php
/**
* @file
* Contains various helper functions.
*/
use Drupal\taxonomy\Entity\Term;
/**
<?php
/**
* @file
* Token related hook implementations.
*/
use Drupal\Core\Render\BubbleableMetadata;
/**
@shelane
shelane / placeholders.php
Created November 15, 2020 05:18
t function variables
Including a link:
$link = Link::fromTextAndUrl($this->t('Bootstrap Documentation'), Url::fromUri('https://getbootstrap.com/docs/3.4/css/#grid-example-mixed-complete', ['attributes' => ['target' => '_blank']]))->toString();
'#description' => $this->t('When this option is selected, clearfix divs will be used to "clear" the columns as needed per device size (see %bootstrap_docs). Please note this option applies only when "Single row" is selected for the "Number of columns per view row" option.',
['%bootstrap_docs' => $link]),
The most common placeholder is probably @variable. This placeholder runs static::placeholderEscape() on the text before replacing it.
You may also use %variable, which runs placeholderEscape() on the text similar to @ placeholders. Using this placeholder will also create <em> tags around the placeholder values.
@shelane
shelane / MyService.php
Created October 10, 2020 03:53 — forked from JeffTomlinson/MyService.php
Drupal 8 Configuration Dependency Injection
<?php
namespace Drupal\my_module\Services;
use Drupal\Core\Config\ConfigFactory;
/**
* Class MyService.
*
* @package Drupal\my_module\Services
@shelane
shelane / drupal8-links.php
Created October 9, 2020 23:47 — forked from colorfield/drupal8-links.php
Drupal 8 links, or where is my l() function