Skip to content

Instantly share code, notes, and snippets.

View msankhala's full-sized avatar
🎯
Focusing

mahesh sankhala msankhala

🎯
Focusing
View GitHub Profile
@msankhala
msankhala / cloudSettings
Last active December 13, 2018 06:37
Visual Studio Code Settings Sync Gist For Crown
{"lastUpload":"2018-12-13T06:36:50.772Z","extensionVersion":"v3.2.3"}
@msankhala
msankhala / cloudSettings
Last active July 3, 2019 20:29
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-07-03T20:29:39.254Z","extensionVersion":"v3.2.9"}
@msankhala
msankhala / render-a-single-field-of-an-entity.php
Created September 11, 2018 11:07
Render a single field of an entity
use Drupal\node\Entity\Node;
$render = [];
$entity_type_manager = \Drupal::entityTypeManager();
$entity = $entity_type_manager->getStorage($entity_type)->load($entity_id);
$fields = [
'body',
'field_example'
];
if ($entity) {
@msankhala
msankhala / Trait-static-method.php
Last active July 21, 2018 06:04
Trait and static method.
<?php
/**
* FileGenerator.
*/
trait FileGeneratorTrait
{
public static function generateFile() {
echo "generating file \n";
}
@msankhala
msankhala / DebugTest.php
Created June 27, 2018 14:48 — forked from mortenson/DebugTest.php
Debugging Drupal 8 Javascript tests
<?php
class DebugTest extends YourBrokenTest {
/**
* Overrides a broken test method and saves HTML at the point of failure.
*/
public function testName() {
try {
parent::testName();
@msankhala
msankhala / Symfony-Service-container-cheetsheet.md
Created May 7, 2018 11:19
symfony dependency injection cheet sheet.

Symfony Service container cheetsheet:

https://symfony.com/doc/current/service_container.html

Passing arguments to service:

services:
  site_update_manager.superadmin:
    class: App\Updates\SiteUpdateManager
 # you CAN still use autowiring: we just want to show what it looks like without
@msankhala
msankhala / d8-entity-api-cheet-sheet.md
Created May 4, 2018 11:28
d8 entity api cheet sheet

Drupal 8 Entity API cheat sheet

The examples here contain some hard-coded IDs. These are all examples. In your real code, you should already have the node IDs, file IDs, etc. in a variable.

Working with nodes

Load a node by NID:

$nid = 123;     // example value
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$node = $node_storage->load($nid);
@msankhala
msankhala / html5-custom-validation-pattern.js
Created May 1, 2018 04:06
html5-custom-validation-pattern.js
jQuery(document).ready(function(){
jQuery('#edit-default-value-input-field-email-0-value').on('input', function(event){
var constraint = new RegExp(/^\[[\w\d][\w\d_\-]*:[\w\d_\-]*\]$/);
if (constraint.test(event.target.value)) {
console.log(event.target);
this.setCustomValidity('');
}
else {
console.log(event.target);
this.setCustomValidity('This is not a valid token');
@msankhala
msankhala / README.md
Created February 23, 2018 17:49 — forked from jmolivas/README.md
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 / ducks.sh
Created February 22, 2018 16:34 — forked from thebouv/ducks.sh
ducks: linux command for the 10 largest files in current directory
du -cks * | sort -rn | head -11
# Usually set this up in my bash profile as an alias:
# alias ducks='du -cks * | sort -rn | head -11'
# Because it is fun to type ducks on the command line. :)