Skip to content

Instantly share code, notes, and snippets.

View Jaesin's full-sized avatar

Jaesin Mulenex Jaesin

View GitHub Profile
@Jaesin
Jaesin / delete_content_entities.d8.php
Created June 22, 2015 07:14
Delete all content entities in Drupal 8.
<?php
// Delete all nodes.
entity_delete_multiple('node', \Drupal::entityQuery('node')->execute());
// Delete all files.
entity_delete_multiple('file', \Drupal::entityQuery('file')->execute());
// Delete all taxonomy terms.
entity_delete_multiple('taxonomy_term', \Drupal::entityQuery('taxonomy_term')->execute());
@Jaesin
Jaesin / user_shell.sh
Created June 12, 2015 02:44
Get the user shell for user in OS X
#!/bin/bash
dscl . -read /Users/$user UserShell | sed s/^UserShell:\ //
@Jaesin
Jaesin / rest-request.php
Last active February 23, 2023 10:39
Guzzle 4 in Drupal 8. Get a JSON version of a node.
<?php
// Example using cookie auth.
print (string) \Drupal::httpClient()
->get('http://example.com/node/1', [
'headers' => ['Accept' => 'application/json'],
'cookies' => ['SESS07e0668737e9f97189850d2cf0c79892' => 'dasGegKQ6ZzEF0xvRZWWzwrl9tt7UT8fGuXrAeLC9P1'],
])
->getBody(TRUE);
@Jaesin
Jaesin / php7_install.sh
Last active August 29, 2015 14:20
Install php 7 in /usr/local/builds/php/7.x in OSX 10.10.3
#!/bin/bash
# The easy version is `curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0`
# It might be better to use (build-entropy-php)[https://github.com/liip/build-entropy-php] for building.
# Create the destinaiton folder.
mkdir -p /usr/local/builds/php
# Clone the php source (Just using the master branch).
git clone https://git.php.net/repository/php-src.git /usr/local/builds/php/7.x
@Jaesin
Jaesin / empty-db.sh
Created April 30, 2015 02:25
Drop all tables.
# Drop all tables in a db.
function mysql-drop-tables {
if [[ $1 != "" ]]; then
if [[ $(get_yes "$@") != "1" ]]; then
echo "You are about to drop all files in the $1 database. Are you sure? (Y or N):"
read RESPONSE
fi
if [[ $(get_yes "$@") == "1" || $RESPONSE == "y" || $RESPONSE == "Y" ]]; then
mysqldump -uroot --add-drop-table --no-data $1 | grep ^DROP | mysql -uroot $1
echo "$1 has been emptied!"
@Jaesin
Jaesin / d8-toogle-toolbar.js
Last active August 29, 2015 14:17
Toggle the toolbar orientation on Drupal 8 via hidden button.
jQuery('.toolbar-toggle-orientation button').click();
@Jaesin
Jaesin / type_introspection.php
Last active August 29, 2015 14:17
Let PHPStorm know what gets served from a factory method.
<?php
/** @var \Drupal\Core\Entity\EntityManager $entity_manager */
$entity_manager = \Drupal::service('entity.manager');
@Jaesin
Jaesin / autocomplete-block-widget.php
Last active August 29, 2015 14:15
Getting an autocomplete field widget for use in block configuration.
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\Plugin\DataType\ItemList;
/**
* Provides a 'FooBlock' block.
*
@Jaesin
Jaesin / D8-create-snapshot.php
Created February 22, 2015 04:50
Create a new configuration snapshot in Drupal 8.
<?php
\Drupal::service('config.manager')->createSnapshot(\Drupal::service('config.storage'), \Drupal::service('config.storage.snapshot'));
@Jaesin
Jaesin / d7.settings.php
Last active November 13, 2017 22:41
Some settings.php options
<?php
/**
* @file
* Some possible additions to the settings.php file or the settings.local.php file.
*/
$databases = ['default' => ['default' => [
'database' => 'db',
'username' => 'user',
'password' => 'pwd',