Skip to content

Instantly share code, notes, and snippets.

@pcambra
pcambra / switch_node_type.php
Last active June 8, 2023 15:41
How to change the type/bundle of an entity/node
<?php
$entity_type_id = 'node';
$type = 'new_type';
$field_base_table_name = 'node__field_data';
// Fill nids with the entity ids you want to switch.
// $entity_ids = [...]
$storage = \Drupal::entityTypeManager()->getStorage($entity_type_id);
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type_id, $type);
@pcambra
pcambra / multiple-deploy-keys-multiple-private-repos-github-ssh-config.md How to configure multiple deploy keys for different private github repositories on the same computer

This is probably a common issue for people who wants to deploy serveral repository on one VPS or VM.

This is not going to be rocket science.

The first step is to generate your first ssh key, for this type the following command line in your terminal: ssh-keygen -t rsa -b 4096 -C "[email protected]" When the command CLI is asking you if you want to use a passphrase you might want to press ENTER in order to don't have to type it everytime you will want to pull your repository.

Now copy the content of your public key and add it to Github in your first repository (Settings > Deploy keys). For example on debian it might be:

<?php
namespace Drupal\log\Plugin\views\field;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
@pcambra
pcambra / queue.php
Created October 18, 2018 09:41
Drupal 8: Process a queue programmatically
$queue_factory = \Drupal::service('queue');
$queue_manager = \Drupal::service('plugin.manager.queue_worker');
$queue_worker = $queue_manager->createInstance('queue_name');
$queue = $queue_factory->get('queue_name');
$item = $queue->claimItem();
$queue_worker->processItem($item->data);
@pcambra
pcambra / gist:fefed7ebfa14c0a2602bc4cd7688928c
Created October 18, 2018 07:19
Reinstal module configuration for Drupal 8
drush php-eval "\Drupal::service('config.installer')->installDefaultConfig('module', 'module_name');"
sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
dscacheutil -flushcache
brew services restart dnsmasq
@pcambra
pcambra / custom_pane_panelizer.php
Created May 10, 2018 00:43
How to add a pane to a node with panelizer programmatically
<?php
// This code can be used in a hook_update_n to add a custom pane to an existing display in panelizer.
// Example variables used in the code below.
$nid = 1;
$pane_machine_name = 'my_example_custom_pane';
$region = 'content';
$position = 0;
const { String: { underscore } } = Ember;
export default JSONAPISerializer.extend({
// Keep Drupal underscored keys.
keyForRelationship(key) {
return underscore(key);
},
keyForAttribute(key) {
return underscore(key);
},
npm install
npm prune
npm dedupe
npm install
npm shrinkwrap --dev