Skip to content

Instantly share code, notes, and snippets.

@mohit-rocks
mohit-rocks / infinitescroll.js
Last active December 17, 2015 19:29
Infinite scroll.js file for the infinite scroll of the page.
(function($){
Drupal.behaviors.viewsInfiniteScroll = {
attach: function (context, settings) {
$(function(){
if (this.processed) return;
this.processed=true;
if ($('.search-results').length==0) return;
var $container = $('.search-results');
$container.imagesLoaded( function(){
$container.infinitescroll({
@mohit-rocks
mohit-rocks / date-views-pager.tpl.php
Created February 11, 2014 04:55
override the pager title for the calendar(Drupal 7)
<?php
/**
* @file
* Template file for the example display.
*
* Variables available:
*
* $plugin: The pager plugin object. This contains the view.
*
* $plugin->view
@mohit-rocks
mohit-rocks / infinitescrollajax.js
Created October 11, 2014 14:07
Infinite pager without infinitescroll.js [Drupal] [Apache solr page] Ref : https://www.drupal.org/node/1473558#comment-8597229
/**
* Js file to add load more button on the search result page.
*/
(function ($) {
Drupal.behaviors.loadMoreAjax = {
attach: function (context, settings) {
$('.load-more-ajax', context).click(function () {
var nextPage = $('.pager .pager__item--next a').attr('href');
var lastPage = $('.pager .pager__item--last a').attr('href');
@mohit-rocks
mohit-rocks / gist:7d43ec7585b89a00bf4c
Created November 9, 2015 12:58 — forked from robertmarsal/gist:9feaa9150926efa4175a
Install f.lux on Ubuntu 14.10
sudo apt-get install python-glade2 python-appindicator
git clone https://github.com/Kilian/f.lux-indicator-applet.git
cd f.lux-indicator-applet
chmod +x setup.py
sudo ./setup.py install
fluxgui
@mohit-rocks
mohit-rocks / gist:bed1fc9f2d2c6213cebd7c9a0b18ef9c
Created August 3, 2016 10:06 — forked from mitchellh/gist:1277049
Configure Vagrant VM to use Host DNS for VPN
Vagrant::Config.run do |config|
# ...
config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
@mohit-rocks
mohit-rocks / FallbackAliasStorage.php
Created January 26, 2018 04:49
Multilingual URL Alias Fallback
<?php
namespace Drupal\my_module;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Path\AliasStorageInterface;
class FallbackAliasStorage implements AliasStorageInterface {
@mohit-rocks
mohit-rocks / ContentUpdate.php
Created February 14, 2018 03:40
ID Map plugin for migration (Drupal 8)
<?php
namespace Drupal\my_module\Plugin\migrate\id_map;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\id_map\Sql;
/**
* Defines the sql based ID map implementation.
*
@mohit-rocks
mohit-rocks / node_page.yml
Last active February 14, 2018 03:58
Migration template : Specify custom ID Map Plugin (Drupal 8)
id: node_page
label: "Page Content"
migration_tags:
- content_import
# Notice ID Map plugin here.
idMap:
plugin: content_update
# ID Map plguin declaration ends.
source:
plugin: csv
@mohit-rocks
mohit-rocks / UnoconvTranscode.php
Created May 16, 2018 14:26
Sample implementation for Transcode method.
/**
* {@inheritdoc}
*/
public function transcode($source_path, $destination_path, $destination_uri) {
$unoconv_config = $this->configFactory->get('unoconv_service.unoconvconfig');
try {
$unoconv = Unoconv::create(array(
'timeout' => $unoconv_config->get('timeout'),
'unoconv.binaries' => $unoconv_config->get('binaries_path'),
));
@mohit-rocks
mohit-rocks / unoconv_example.module
Last active May 16, 2018 14:30
Example hook for how to use Unoconv service. https://drupal.org/project/unoconv_service
<?php
/**
* Implements hook_ENTITY_TYPE_presave().
*/
function unoconv_example_media_presave(EntityInterface $entity) {
$original_file_id = $entity->get('field_document_file')->getValue();
/** @var \Drupal\file\Entity\File $file */
$file = File::load($original_file_id[0]['target_id']);