Skip to content

Instantly share code, notes, and snippets.

@gwagroves
gwagroves / view_title.php
Created August 23, 2017 10:11
Get a Drupal 8 View title and URL from a path.
<?php
use Drupal\views\Views;
// Get the View title and URL from a path.
$path = '/my-path';
$url = \Drupal::service('path.validator')->getUrlIfValid($path);
@gwagroves
gwagroves / table_sizes.sql
Created February 2, 2017 16:09
MySQL: Shows table sizes in MB
SELECT table_name, round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` FROM information_schema.TABLES;
@gwagroves
gwagroves / module.php
Last active April 7, 2024 13:02
Drupal 8 Paragraphs: Add a theme suggestion based on the paragraph and the type of the parent node / entity.
<?php
/**
* Implements theme_suggestions_HOOK_alter().
*/
function mytheme_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) {
/** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
$paragraph = $variables['elements']['#paragraph'];
/** @var \Drupal\Core\Entity\ContentEntityInterface $parent */
$parent = $paragraph->getParentEntity();
@gwagroves
gwagroves / git.sh
Created December 11, 2016 12:06
Git force rename file on case insensitive file systems
# Used when only changing the case of a file name.
# `oldfilename` is the new file name!
git mv -f OldFileName oldfilename
@gwagroves
gwagroves / cmd.bash
Created November 17, 2016 09:03
MacBook Air FaceTime not working on Skype (El Capitan)
$ sudo killall VDCAssistant
@gwagroves
gwagroves / node.html.twig
Created October 22, 2016 08:00
Drupal 8: Show formatted node created data in Twig
{# html_date is the machine name of an existing date format #}
{% set createdDate = node.getCreatedTime|format_date('html_date') %}
<div class="date">{{ createdDate }}</div>
@gwagroves
gwagroves / drush.bash
Last active July 22, 2021 09:59
Drupal 8 Drush export config to gzip tar
# Change working directory to a temporary location
cd ~/temp
# Export config to "config" directory
# Change `@mysite.local` to your local drush alias
drush @mysite.local config-export --destination=~/temp/config
# Tar all files in "config" directory to `config.tar.gz`
tar -czf config.tar.gz -C config .
@gwagroves
gwagroves / .bash_profile
Last active October 14, 2016 11:11
HostEurope composer usage
export PATH="$HOME/bin:$PATH"
alias composer="php -d suhosin.executor.include.whitelist=phar ~/composer.phar"
@gwagroves
gwagroves / no-scroll.css
Created October 7, 2016 07:48
Prevent body scrolling on iOS
/* http://stackoverflow.com/a/19054794/698511 */
body.no-scroll {
left: 0;
-webkit-overflow-scrolling: touch;
position: fixed;
top: 0;
width: 100%;
}
@gwagroves
gwagroves / content.md
Last active October 3, 2016 15:49
Drupal 8 hook arguments
$content[field_machine_name] =>
  0,
  1,
  2,
  #theme,
  #title,
  #label_display,
  #view_mode,
 #language,