Skip to content

Instantly share code, notes, and snippets.

View msankhala's full-sized avatar
🎯
Focusing

mahesh sankhala msankhala

🎯
Focusing
View GitHub Profile
@samuelsolis
samuelsolis / example.php
Created February 7, 2018 08:15
Drupal 8 custom entity without bundle
<?php
/**
* @file
* Contains \Drupal\example\Entity\Example.
*/
namespace Drupal\example\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
@fredericmarx
fredericmarx / .hyper.js
Created July 22, 2017 14:22
Configuration file for Hyper https://hyper.is/
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 14,
// font family with optional fallbacks
fontFamily: '"Input Mono", Menlo, "DejaVu Sans Mono", "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: 'rgba(248,28,229,0.8)',
@WebReflection
WebReflection / benchmark-dom-classes.js
Last active November 13, 2021 20:52
Classes VS DOM Events Handling Benchmark
// Players
class ClickCounter {
constructor() { this.clicks = 0; }
onclick(e) { this.clicks += (e.type === 'click') ? 1 : -1; }
}
class Handler extends ClickCounter {
constructor(currentTarget) {
super();
currentTarget.addEventListener('click', this);
@jmolivas
jmolivas / README.md
Last active August 5, 2019 20:01
Render a form on a page via a Controller on Drupal8.

Create file at ~/console/chain/generate-controller-form-render.yml containing:

command:
  name: 'generate:controller:form:render'
  description: 'Controller + Form generator'
commands:
  - command: 'generate:module'
    options:
        module: example
@msankhala
msankhala / load-all-referenced-node-from-node-reference-field.php
Created February 9, 2017 06:33
load all referenced node from node reference field.
<?php
// Get all referenced node from a node reference field.
function get_related_nodes($master_nid, $field_name) {
// Load the 'master' node
$master_node = node_load($master_nid);
// Get the node reference items attached to this node
$items = field_get_items('node', $node, $field_name);
// Loop through and grab the nids
<?php
// use entity metadata wrappers as they are SMART
$wrapper = entity_metadata_wrapper('node', $node);
dsm($wrapper->getPropertyInfo());
// Retrieving an integer value of a field
// Old approach
$showid = $node->field_seriesid[LANGUAGE_NONE][0]['value'];
@msankhala
msankhala / entity-metadata-wrapper-isset.php
Last active February 17, 2017 06:11
entity-metadata-wrapper isset check.
<?php
$field_collection_item = field_collection_item_load($id);
$item_wrapper = entity_metadata_wrapper('field_collection_item', $field_collection_item);
// this results in an error if the field_contrib_headshot field is empty
$headshot = $item_wrapper->field_contributor->field_contrib_headshot->value();
Solution:
// EntityStructureWrapper implements the __isset() function according the principe of Overloading.
$headshot = array();
@jherax
jherax / filterArray.js
Last active May 6, 2024 09:35
Filters an array of objects with multiple match-criteria.
/**
* Filters an array of objects using custom predicates.
*
* @param {Array} array: the array to filter
* @param {Object} filters: an object with the filter criteria
* @return {Array}
*/
function filterArray(array, filters) {
const filterKeys = Object.keys(filters);
return array.filter(item => {
@bendc
bendc / .vimrc
Last active October 11, 2018 18:29
Vim config
set nocompatible
set encoding=utf-8 nobomb
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle
Plugin 'VundleVim/Vundle.vim'
@leymannx
leymannx / Drupal8HorizontalTabs.php
Last active February 16, 2024 10:10
How to create horizontal tabs programmatically in Drupal 8, requires Field Group module
<?php
// How to create horizontal tabs programmatically in Drupal 8, requires Field Group module
$form = array();
$form['my_field'] = array(
'#type' => 'horizontal_tabs',
'#tree' => TRUE,
'#prefix' => '<div id="unique-wrapper">',
'#suffix' => '</div>',
);
$items = array(