Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
Framework Manager, Drupal Core

Lee Rowlands larowlan

:shipit:
Framework Manager, Drupal Core
View GitHub Profile
@larowlan
larowlan / yourtheme.theme.php
Created Jan 21, 2021
Preprocess a layout to work out if its in layout builder UI
View yourtheme.theme.php
<?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();
View yourmodule.post_update.php
/**
* 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',
View yourclass.php
<?php
class SomeClass extends BlockBase {
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
$contexts = parent::getCacheContexts();
// Tell Drupal that this block should be cached per-user.
$contexts[] = 'user';
View docker-compose.yml
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
View 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
View 2820848-148.diff
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;
+
View psalm output
ERROR: TypeCoercion - core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php:61 - Argument 1 of Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator::__construct expects Drupal\Core\Entity\EntityTypeManagerInterface, parent type object provided
$container->get('entity_type.manager'),
INFO: MissingReturnType - core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php:59 - Method Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator::create does not have a return type
ERROR: PossiblyNullReference - core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php:81 - Cannot call method hasState on possibly null variable $workflow
if (!$workflow->hasState($entity->moderation_state->value)) {
ERROR: PossiblyNullReference - core/modules/content_moderation/src/Plugin/Validation/Constraint/Moderatio
View Makefile
#!/usr/bin/make -f
phpcs:
cd drupal && vendor/bin/phpcs --standard="core/phpcs.xml.dist" `git diff --staged --name-only --diff-filter=AM`
phpcs-diff:
cd drupal && vendor/bin/phpcs --standard="core/phpcs.xml.dist" `git diff --name-only --diff-filter=AM`
phpcbf:
cd drupal && vendor/bin/phpcbf --standard="core/phpcs.xml.dist" `git diff --name-only --diff-filter=AM`
View days.patch
diff --git a/src/Commands/Billable.php b/src/Commands/Billable.php
index 2df9683..39bb721 100644
--- a/src/Commands/Billable.php
+++ b/src/Commands/Billable.php
@@ -28,6 +28,7 @@ class Billable extends Command implements ConfigurableService {
const DAY = 'day';
const MONTH = 'month';
const FORTNIGHT = 'fortnight';
+ const SATURDAY = 6;
View settings.debug.php
<?php
$config['system.logging']['error_level'] = 'verbose';
// See https://gist.github.com/larowlan/5baca05f5be4e5582777a9904ecaec41 for contents.
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/default/services.local.yml';
$config['system.performance']['js']['preprocess'] = FALSE;
$config['system.performance']['css']['preprocess'] = FALSE;
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
$settings['extension_discovery_scan_tests'] = TRUE;