Skip to content

Instantly share code, notes, and snippets.

View JayKandari's full-sized avatar
:octocat:

Jaideep Singh Kandari JayKandari

:octocat:
View GitHub Profile
@bdlangton
bdlangton / Blocks.md
Last active October 12, 2023 08:40
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@WengerK
WengerK / README.md
Last active January 4, 2022 21:15
Programatically use Solr on Drupal 8

🔍 Solr (6.1.0+) search Engine & Tika (1.13+) Extractor

We are using solr for search index.

Solr need to be configured for drupal. Follow the INSTALL.txt found in the search_api_solr module.

As a pre-requisite for running your own Solr server, you'll need Java 6 or higher.

Installation

@crittermike
crittermike / import.php
Last active August 11, 2023 10:39
Importing Drupal 8 config programmatically
<?php
// Import arbitrary config from a variable.
// Assumes $data has the data you want to import for this config.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');
@jez500
jez500 / d8-views-exp-form-alter.php
Last active October 12, 2023 12:20
Drupal 8 - Hook form alter views exposed form
<?php
/**
* Implements hook_form_alter().
*/
function MYMODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$view_names = array('my_view_name');
$view = $form_state->getStorage('view');
if ($form_id == 'views_exposed_form' && in_array($view['view']->id(), $view_names)) {
// Do some shilzzle.
@slivorezka
slivorezka / get_entity_by_alias.php
Created March 29, 2017 18:26
Drupal 8: Get Entity By Alias
<?php
// Some entity alias (node, taxonomy_term, user, etc).
$alias = '/about';
// Get URL obj.
$url = Url::fromUri('internal:' . $alias);
// Check exist alias.
if ($url->isRouted()) {
$params = $url->getRouteParameters();
$entity_type = key($params);
// GEt entity.
@crittermike
crittermike / get_node_by_path.php
Created September 16, 2016 15:15 — forked from thagler/get_node_by_path.php
Drupal 8 Get node ID by path alias
<?php
$path = \Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias');
if(preg_match('/node\/(\d+)/', $path, $matches)) {
$node = \Drupal\node\Entity\Node::load($matches[1]);
}
@aramboyajyan
aramboyajyan / snippet.php
Created February 7, 2016 09:54
Drupal 7 Commerce empty user shopping cart programmatically
global $user;
$order = commerce_cart_order_load($user->uid);
commerce_cart_order_empty($order);
@AlexSkrypnyk
AlexSkrypnyk / mymodule.css
Last active April 17, 2024 08:37
Drupal 'add more' and 'remove single' AJAX buttons on multi value custom field using FormAPI
input.form-submit.button-small {
padding: 4px 8px;
font-weight: bold;
}
.container-inline input.form-submit.button-small + .ajax-progress.ajax-progress-throbber .throbber {
position: absolute;
left: 19px;
margin-top: 7px;
}
@Restuta
Restuta / framework-sizes.md
Last active March 7, 2024 00:01
Sizes of JS frameworks, just minified + minified and gzipped, (React, Angular 2, Vue, Ember)

Below is the list of modern JS frameworks and almost frameworks – React, Vue, Angular, Ember and others.

All files were downloaded from https://cdnjs.com and named accordingly. Output from ls command is stripped out (irrelevant stuff)

As-is (minified)

$ ls -lhS
566K Jan 4 22:03 angular2.min.js
@wpscholar
wpscholar / array-insert-after.php
Created November 7, 2015 13:04
Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended to the end of the array.
<?php
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* @param array $array
* @param string $key
* @param array $new
*