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 / 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 / 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 / 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,
<?php
function redis_set() {
$backend = new Redis_Cache('cache_sweepstakes');
$backend->set('sweepstakes:63:1', 100, CACHE_PERMANENT);
dpm($backend);
return '';
}
@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: {}
@miteshmap
miteshmap / OriginalService.php
Last active June 1, 2018 06:21
Drupal 8: Service Decorators: OriginalService.php
<?php
namespace Drupal\custom_decorator_base;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Class OriginalService
*/
class OriginalService implements CustomDecoratorInterface {
@miteshmap
miteshmap / custom_decorator_base.yml
Created June 1, 2018 06:17
Drupal 8: Service Decorators: custom_decorator_base.yml
services:
custom_decorator_base.base:
class: Drupal\custom_decorator_base\OriginalService
arguments: ['@request_stack']
@miteshmap
miteshmap / sample.php
Last active June 1, 2018 06:41
Drupal 8: Service Decorators: sample.php
<?php
$base = \Drupal::service('custom_decorator_base.base');
print $base->helper();
@miteshmap
miteshmap / custom_decorator_override.yml
Created June 1, 2018 06:19
Drupal 8: Service Decorators: custom_decorator_override.yml
services:
custom_decorator_override.base:
class: Drupal\custom_decorator_override\OriginalServiceOverride
decorates: custom_decorator_base.base
decoration_priority: 9
public: false
arguments: ['@custom_decorator_override.base.inner', '@request_stack']
@miteshmap
miteshmap / TokenServiceProvider.php
Created June 1, 2018 06:20
Drupal 8: Service Decorators: TokenServiceProvider.php
<?php
/**
* Replace drupal core token service with our own.
*/
class TokenServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {