Skip to content

Instantly share code, notes, and snippets.

Before we get started, let’s install XCode Command Line Tools on your system.
$ xcode-select --install
Homebrew Installation
Homebrew is an excellent package manager for macOS. Homebrew installs the stuff you need that Apple (or your Linux system) didn’t; let's install it.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Homebrew can self-diagnose and check your system for potential problems. Let's see if everything is working the way it should.
@amutylo
amutylo / gist:216323f1276680789f9bbb55ef1cd600
Created January 15, 2020 15:23
Settings.json for Drupal 8 VS Code
// Place your settings in this file to overwrite the default settings
{
"editor.tabSize": 2,
"editor.fontSize": 14,
"editor.scrollBeyondLastLine": false,
"editor.renderWhitespace": "boundary",
"files.trimTrailingWhitespace": true,
"workbench.activityBar.visible": false,
"editor.minimap.enabled": true,
"editor.minimap.renderCharacters": false,
@amutylo
amutylo / gist:5cf7caa5b099034db5f3d10ca3305a6a
Created January 15, 2020 15:18
Settings.json for VS Code
// Overwrite settings by placing them into your settings file.
// See http://go.microsoft.com/fwlink/?LinkId=808995 for the most commonly used settings.
{
// Editor
// Controls the font family.
"editor.fontFamily": "Fira Code",
// Enables font ligatures
@amutylo
amutylo / form-preserialize
Created May 19, 2017 13:05
form-preserialize
$('.modal form').on('form-pre-serialize', function(event, form, options, veto){
$(form).validate();
if(!$(form).valid())
{
veto.veto = true;
}
})
@amutylo
amutylo / gist:4616047c733a39ec2850dc0196a02189
Created February 16, 2017 11:52
drupal 8 create comments programmatically
// To create a new comment entity, we'll need `use` (import) the Comment class.
use Drupal\comment\Entity\Comment;
// The function name doesn't matter. Just put the the function body where you need it.
function my_modules_function_or_method() {
// First, we need to create an array of field values for the comment.
$values = [
// These values are for the entity that you're creating the comment for, not the comment itself.
<?php
// Programmatically create and translate taxonomy terms Drupal 8.
use Drupal\taxonomy\Entity\Term;
$term = Term::create([
'vid' => 'sport_activity',
'langcode' => 'en',
'name' => 'My tag',
'description' => [
<?php
// Programmatically create node with image fields Drupal 8.
use Drupal\file\Entity\File;
use Drupal\node\Entity\Node;
$file = File::create([
'uid' => 1,
'uri' => 'public://page/logo.png',
'status' => 1,
]);
<?php
// Programmatically create and translate nodes Drupal 8.
use Drupal\node\Entity\Node;
$node = Node::create([
// The node entity bundle.
'type' => 'article',
'langcode' => 'en',
'created' => REQUEST_TIME,
<?php
// Programmatically create and translate menu links Drupal 8.
use Drupal\menu_link_content\Entity\MenuLinkContent;
$menu_item = MenuLinkContent::create([
'bundle' => 'menu_link_content',
'langcode' => 'en',
'title' => 'My menu link',
'description' => 'My description.',
'menu_name' => 'main',
<?php
// Programmatically create files in Drupal 8.
use Drupal\file\Entity\File;
$file = File::create([
'uid' => 1,
'filename' => 'logo.svg',
'uri' => 'public://page/logo.svg',
'status' => 1,
]);