Skip to content

Instantly share code, notes, and snippets.

View sumanthkumarc's full-sized avatar

Sumanth Reddy sumanthkumarc

View GitHub Profile
@sumanthkumarc
sumanthkumarc / new drupal instance.txt
Created October 18, 2016 07:36
Instuctions for creating git repo of new drupal instance[D8]
If it's distribution, let the documentation exists and point your vhost entry to demo folder.
make a .gitignore file from example.gitignore file
check if settings file, files folder and other unnecesary files like *~ are excluded.
do got init to initiliaze a git repo
do git status to see list of files.
add git config username and email
add git remote origin points to push your repo
do commit and push it.
Hola! and you are done.
@sumanthkumarc
sumanthkumarc / git-credentials-store
Last active November 15, 2016 06:22
git credentials store
sudo apt-get install libgnome-keyring-dev
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
to store in cache:
#18000 = 5 hrs
git config --global credential.helper "cache --timeout=18000"
<?php
use Drupal\Core\Render\BubbleableMetadata;
/**
* @implements hook_token_info().
*/
function my_module_token_info() {
$type = [
'name' => t('Custom tokens'),
@sumanthkumarc
sumanthkumarc / add-all-option.js
Created November 22, 2016 12:02
Adding all option for list of options
$('document').ready(function () {
// Below code takes care of adding All checkbox to options.
var i = 0;
$(".form-checkboxes").each(function () {
i++;
// Add events.all checkbox only if there are more than 2 options.
if ($(this).children().length > 2) {
@sumanthkumarc
sumanthkumarc / temp-drush-dc-composer.txt
Created December 2, 2016 13:08
Temporarily use the drush, drupal console and composer.
Temporarily use the drush, drupal console and composer.
Drupal Console:
// download the drupal console php archive file
curl https://drupalconsole.com/installer -LO drupal.phar
// set executable on your phar file
chmod +x drupal.phar
// Set alias to use
alias dc="/path/to/file/drupal.phar"
// check if its working
@sumanthkumarc
sumanthkumarc / nodejs.config.js
Created December 12, 2016 09:39
working config for nodejs and drupal 8 integration.
settings = {
scheme: 'http',
port: 8080,
host: 'localhost',
resource: '/socket.io',
serviceKey: 'any-id-same-as-in-drupal-config',
backend: {
port: 80,
host: 'site-host-name',
scheme: 'http',
@sumanthkumarc
sumanthkumarc / solr_install.txt
Created January 25, 2017 18:12
installing apache solr
sudo apt-get install openjdk-8-jdk
cd /opt
sudo wget http://www.us.apache.org/dist/lucene/solr/6.3.0/solr-6.3.0.tgz
sudo tar xzf solr-6.3.0.tgz solr-6.3.0/bin/install_solr_service.sh --strip-components=2
sudo ./install_solr_service.sh solr-6.3.0.tgz
@sumanthkumarc
sumanthkumarc / view_submit_button.txt
Created February 8, 2017 09:29
Add a button to view and add submit handler -taken from Commerce2.x D8
/**
* Implements hook_form_alter().
*/
function commerce_checkout_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (strpos($form_id, 'views_form_commerce_cart_form_') === 0) {
// Only add the Checkout button if the cart form view has order items.
$view = reset($form_state->getBuildInfo()['args']);
if (!empty($view->result)) {
$form['actions']['checkout'] = [
'#type' => 'submit',
@sumanthkumarc
sumanthkumarc / add_member_to_group.txt
Created February 20, 2017 11:03
Adds a given user to given group as given role.
/**
* Adds a given user as member with given role to given group.
* @param GroupInterface $group
* Group Entity
* @param UserInterface $user
* An user account entity of type User Interface , not of Account Interface.
* @param array $role
* A group role in format : [GROUPTYPE]-[role] Ex: group-teacher
*/
function add_member_to_group(GroupInterface $group, UserInterface $user, $role) {
@sumanthkumarc
sumanthkumarc / save_pdf_entity_print.php
Last active November 18, 2022 14:53
D8 : save a pdf using entity_print print builder service and display it as link
<?php
use Drupal\Core\Url;
$entities = [node_object];
$scheme = 'public';
$filename = 'something.pdf';
$export_type = 'pdf';
/* @var \Drupal\entity_print\PrintBuilder $print_builder */