Skip to content

Instantly share code, notes, and snippets.

View larowlan's full-sized avatar
:shipit:
Framework Manager, Drupal Core

Lee Rowlands larowlan

:shipit:
Framework Manager, Drupal Core
View GitHub Profile
diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php
index 098ba2f..0442bf6 100644
--- a/core/modules/contact/src/ContactFormEditForm.php
+++ b/core/modules/contact/src/ContactFormEditForm.php
@@ -68,10 +68,10 @@ public function form(array $form, FormStateInterface $form_state) {
if ($url = $contact_form->getRedirectUrl()) {
$path = $url->toString();
}
- $form['route'] = array(
+ $form['url'] = array(
@larowlan
larowlan / git-cleanup
Created June 14, 2013 01:31
Clean up old git branches
#!/bin/bash
# This has to be run from master
git checkout master
# Update our list of remotes
git fetch
git remote prune origin
# Remove local fully merged branches
git branch --merged master | grep -v 'master$' | xargs git branch -d
; generates interdiff into ~/patches from current diff
alias.interdiff=!git diff > ~/patches/interdiff.txt
; generates interdiff into ~/patches from current staged diff
alias.interdiff-stg=!git diff --staged > ~/patches/interdiff.txt
; generates patch into ~/patches based on branch name.
; usage git genpatch {comment number}
alias.genpatch=!sh -c "br=`git symbolic-ref HEAD|sed s#refs/heads/##`; git diff origin/8.0.x > ~/patches/\${br}.$1.patch"
; rebase branch of 8.0.x
alias.rebase8x=!git fetch origin && git rebase origin/8.0.x
; merge 8.0.x
@larowlan
larowlan / place_block.php
Created February 6, 2014 04:02
Place a block using update hook - Drupal 7
<?php
/**
* Place the views exposed search block.
*/
function YOURPROFILE_update_7001() {
$default_theme = variable_get('theme_default', 'YOURTHEME');
// Enable some standard blocks.
$blocks = array(
array(
'module' => 'views',
@larowlan
larowlan / yourtheme.theme.php
Created January 21, 2021 21:31
Preprocess a layout to work out if its in layout builder UI
<?php
/**
* Implements hook_preprocess_HOOK() for your_layout().
*/
function your_theme_preprocess_your_layout(&$vars) {
// Note this only works for 'defaults'. You could adapt it for OverridesSectionStorage.
// Ascertain if we're in layout-builder edit mode.
$parameters = \Drupal::routeMatch()->getParameters();
$vars['is_layout_builder'] = FALSE;
$cache = new CacheableMetadata();
@larowlan
larowlan / yourmodule.post_update.php
Created August 4, 2020 06:33
Create a missing block
/**
* Create a missing block (with empty fields but matching UUID).
*/
function yourmodule_post_update_create_a_missing_block() {
$block_entity_manager = \Drupal::service('entity.manager')->getStorage('block_content');
$missing_uuid = 'CE7DA6B0-C2A0-4EE9-8F6B-8854A3705FB7';
$block = $block_entity_manager->create([
'info' => 'Block title goes here',
'type' => 'block_type_machine_name_here',
<?php
class SomeClass extends BlockBase {
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
$contexts = parent::getCacheContexts();
// Tell Drupal that this block should be cached per-user.
$contexts[] = 'user';
@larowlan
larowlan / docker-compose.yml
Created November 19, 2017 23:15
d4d mount my own
version: "2"
services:
mariadb:
image: wodby/mariadb:10.1-2.3.5
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
@larowlan
larowlan / docker-compose.yml
Created October 9, 2017 21:24
docker-compose.yml
version: "2"
services:
mariadb:
image: wodby/drupal-mariadb:1.0.0
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: local
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
diff --git a/core/modules/block_content/block_content.install b/core/modules/block_content/block_content.install
index 6af2ac4e8f..c6556e719c 100644
--- a/core/modules/block_content/block_content.install
+++ b/core/modules/block_content/block_content.install
@@ -6,6 +6,23 @@
*/
use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\StringTranslation\TranslatableMarkup;
+