Drupal Dump

Drupal Snippets, Hacks and more....

475 posts since 2011

Get all methods you can run on fields

To get all method names you can run on any field added to any entity, input this into devel/php

ksm(get_class_methods('\Drupal\Core\Field\FieldItemList'));

 

Flood and Block Ip while running tests (403)

There are 2 system in drupal 7 for IP blocking, one is flood blocking that is used on login and other is 
system_block_ip_action that is storing IP's in blocked_ips table and checking them while bootstrapping.

Check if memcache is working

drush ev 'cache_set("foo", "bar", "cache");'
drush ev '$x = new MemCacheDrupal("cache"); print_r($x->get("foo"));'

snippet to check if memcache is working.

DrupalVM can't mount NFS or similar access problems on Mac OSX

This problem with access permissions has become common in latest versions of Mac OS, you need to give permissions to apps (executables) so they can do/use stuff on your disk/computer. Most of the times you will get a prompt for asking/checking this but sometimes this will quietly fail.

Quickly create patch files from fixed contrib modules

You fixed something in contrib module and you want to create quick patch from that, if it spans through multiple commits, best way to do that is to make a patch from multiple commits, to combine them into one file, write this

3 ways to load payments associated with order in drupal 8

So you have and order, but don't know how to get to payments that are referencing this order, there are few ways you can achieve that. First is to load it by properties

$payments = \Drupal::entityTypeManager()->getStorage('commerce_payment')->loadByProperties(['order_id' => $order->id()]);

second is to load them by order