Skip to content

Instantly share code, notes, and snippets.

@mrded
mrded / get_links_and_change.php
Created November 7, 2013 13:10
Drupal: Get links from HTML dom and change them.
@mrded
mrded / foo.js
Created November 5, 2013 10:36
Drupal: Update item by ajax.
(function($) {
Drupal.behaviors.Foo = {
attach:function (context, settings) {
// unbind() because click events firing multiple times.
$('#foo a.update', context).unbind().click(function (event) {
// Get parrent of item.
var item = $(this).closest(".item");
// Get some data of item.
@mrded
mrded / ubuntu-vpn-install.sh
Last active December 27, 2015 02:49 — forked from nshkuro/setup vpn script
Ubuntu: Install and setup VPN (poptop)
#!/bin/bash
echo "Select on option:"
echo "1) Set up new PoPToP server AND create one user"
echo "2) Create additional users"
read x
if test $x -eq 1; then
echo "Enter username that you want to create (eg. client1 or john):"
read u
echo "Specify password that you want the server to use:"
read p
@mrded
mrded / foo.module
Created October 31, 2013 13:46
Drupal: Taxonomy terms as autocomplete using form API.
<?php
function bar_form($form, &$state) {
$form['bar'] = array(
'#type' => 'textfield',
'#title' => t('Bar'),
'#autocomplete_path' => 'taxonomy/autocomplete/field_bar_term', // Field name here.
'#element_validate' => array('foo_taxonomy_autocomplete_validate'),
);
@mrded
mrded / module-name.js
Created October 28, 2013 13:03
Drupal agreement: Working with JS variables.
(function ($) {
Drupal.behaviors.moduleName = {
attach: function(context, settings) {
console.log(settings.module_name.foo); // bar
}
};
})(jQuery);
@mrded
mrded / example.php
Last active December 26, 2015 18:19
PHP: ArrayObject examples.
<?php
$foo = isset($array['foo']) ? $array['foo'] : null;
$bar = isset($array['bar']) ? $array['bar'] : null;
# With php notices
$foo = $array['foo'] ? : null;
$bar = $array['bar'] ? : null;
# DefaultingArrayObject
@mrded
mrded / list_of_users.rules.inc
Created October 25, 2013 08:33
Drupal: How to pass list of users to bloody rules.
<?php
/**
* Implements hook_rules_event_info().
*/
function hook_rules_event_info() {
return array(
'list_of_users' => array(
'label' => t('List of users example'),
'group' => t('Example'),
'variables' => array(
@mrded
mrded / ctools_popup.php
Last active September 19, 2017 13:21
Drupal: Example of reloading ctools modals.
<?php
ctools_include('ajax');
ctools_include('modal');
ctools_modal_add_js();
drupal_add_library('module', 'fancybox.modal'); // Include js here.
$path = 'some_path/nojs';
$content = ctools_modal_text_button($text, $path, '', $class);
@mrded
mrded / codes.json
Last active December 26, 2015 06:49
AngularJS: Search by JSON.
[{"id":1,"name":"X99.7","description":"Not known","value":"X99.7"},{"id":2,"name":"X99.8","description":"Outpatient procedure carried out but no appropriate OPCS-4 code available","value":"X99.8"},{"id":3,"name":"X99.9","description":"No outpatient procedure carried out","value":"X99.9"},{"id":4,"name":"A01.3","description":"Partial lobectomy of brain","value":"A01.3"},{"id":5,"name":"A01.8","description":"Other specified major excision of tissue of brain","value":"A01.8"},{"id":6,"name":"A01.9","description":"Unspecified major excision of tissue of brain","value":"A01.9"},{"id":7,"name":"A02.4","description":"Excision of lesion of tissue of occipital lobe of brain","value":"A02.4"},{"id":8,"name":"A02.5","description":"Excision of lesion of tissue of cerebellum","value":"A02.5"},{"id":9,"name":"A03.4","description":"Stereotactic ablation of tissue of brain stem","value":"A03.4"},{"id":10,"name":"A03.9","description":"Unspecified stereotactic ablation of tissue of brain","value":"A03.9"},{"id":11,"name":"A04.
@mrded
mrded / foo.module
Created October 22, 2013 16:45
Drupal: custom entity view modes.
<?php
/**
* Implements hook_entity_info_alter().
*/
function foo_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['another_teaser'] = array(
'label' => t('Another teaser'),
'custom settings' => TRUE,
);