Skip to content

Instantly share code, notes, and snippets.

View miteshmap's full-sized avatar
👨‍💻
Working from home

Mitesh Patel miteshmap

👨‍💻
Working from home
View GitHub Profile
@miteshmap
miteshmap / example.libraries.yml
Last active April 15, 2018 13:47
Drupal 8: libraries “css” naming convention and weights
example:
css:
theme:
css/example.css: {}
js:
js/example.js: {}
<?php
function redis_set() {
$backend = new Redis_Cache('cache_sweepstakes');
$backend->set('sweepstakes:63:1', 100, CACHE_PERMANENT);
dpm($backend);
return '';
}
@miteshmap
miteshmap / username.php
Last active February 9, 2016 07:31
Autocomplete uid to name and name to uid
<?php
function axelerant_custom_username_form($form, &$form_state) {
$default_user = user_load(3);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Search for Contributor'),
'#autocomplete_path' => 'user/autocomplete',
'#default_value' => $default_user->name,
@miteshmap
miteshmap / panels.module
Last active August 29, 2015 14:17
ltrim returns wrong block delta for "Edit block" link.
<?php
// Line - 1811 - under "panels_get_pane_links_alter"
// remove the prefix block- to get the name.
$name_of_block = ltrim( $prefixed_name, $subtype_prefix_hyphen);
// correct Method
if (substr($prefixed_name, 0, strlen($subtype_prefix_hyphen)) == $subtype_prefix_hyphen) {
$name_of_block = substr($prefixed_name, strlen($subtype_prefix_hyphen));
}
@miteshmap
miteshmap / foo.js
Created December 19, 2014 20:50
Drupal - write value to textarea with editor with js
(function ($) {
Drupal.fooModule = Drupal.enrich || {};
Drupal.fooModule.copyToTextarea = function($field, $value, settings) {
for (var editor in settings.wysiwyg.configs) break;
$("textarea[name^='"+ $field +"']").val($.trim($value));
var editorid = $("textarea[name^='"+ $field +"'].text-full").attr('id');
if (typeof editorid != 'undefined' && editorid.length > 0) {
if (editor == 'tinymce') {
tinyMCE.execInstanceCommand(editorid, 'mceSetContent', false, $.trim(html));
@miteshmap
miteshmap / drupal.foo.js
Last active November 13, 2024 15:44
Drupal - Execute custom code on ajax success call
(function ($) {
Drupal.fooModule = Drupal.fooModule || {};
Drupal.fooModule.success = function (response, status) {
// do some cusotm coding if needed.
// Call original method with main functionality.
Drupal.ajax.prototype.success.call(this, response, status);
};
Drupal.behaviors.fooModule = {
@miteshmap
miteshmap / custom_users.module
Last active August 29, 2015 14:07
Implemented use of hook_user_operations with batch.
/**
* Implements hook_user_operations().
*/
function custom_users_user_operations() {
$operations['custom_users_salesforce'] = array(
'label' => t('Create Salesforce Account'),
'callback' => 'custom_users_operations_create_salesforce_callback',
);
return $operations;
}
@miteshmap
miteshmap / query_alter.module
Created October 1, 2014 12:35
alter entity field query to print for debug
/**
* Implements hook_query_alter().
*/
function evosys_redirect_query_alter($query) {
if ($query->hasTag('debug')) {
$sql = (string)$query;
$connection = Database::getConnection();
foreach ((array) $query->arguments() as $key => $val) {
$quoted[$key] = $connection->quote($val);
}
@miteshmap
miteshmap / update_path.module.php
Created April 15, 2014 17:19
Update path for multiligual node
<?php
function foo_update_path() {
$nid = 1;
$node = node_load($nid);
foo_custom_module($node);
exit;
}
function foo_custom_module($node) {
@miteshmap
miteshmap / foo.module
Created February 14, 2014 18:23
Use of hook_cron_queue_info
<?php
/**
* Implements hook_Cron_queue_info().
*/
function foo_cron_queue_info() {
$queues['vehicle_new_queue'] = array(
'worker callback' => 'vehicle_new_queue_run',
'time' => 60,
);