Skip to content

Instantly share code, notes, and snippets.

@init90
init90 / scratch.txt
Created January 5, 2017 14:09
drupal 7, preprocess password confirm.
function MYMODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
$form['account']['pass']['#process'] = array(
'form_process_password_confirm',
'MYMODULE_password_confirm_process',
'user_form_process_password_confirm'
);
}
function MYMODULE_password_confirm_process($element) {
$element['pass1']['#attributes']['title'] = 'Title';
@init90
init90 / records.main.inc
Created January 5, 2017 15:21
Drupal 7, disable access check in entity query.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'feasibility_plan')
->propertyCondition('uid', $uid)
->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
if ($personal_view) {
$query->fieldCondition('field_show_in_student_record', 'value', 1, '=');
}
$res = $query->execute();
@init90
init90 / scratch.txt
Last active May 5, 2018 20:58
Drupal 8, create custom config and added parameter to it.
$config = \Drupal::service('config.factory')->getEditable('domain.config.three_d8_test.system.site');
$config->set('name', 'trest');
$config->save();
@init90
init90 / gist:147eea693b633efeb0bc6f3057312983
Last active May 5, 2018 20:57
Drupal 8. Save logo settings to config for every domain.
$config = \Drupal::service('config.factory')->getEditable("domain.config.{$domain_machine_name}.omni_magazine.settings");
$config->set('logo', array('use_default' => FALSE, 'path' => drupal_realpath($file->getFileUri())));
$config->save();
@init90
init90 / gist:330ec3864635d7e46e333ab41803b322
Last active May 5, 2018 20:51
drupal 8, get entity from $form_state.
$form_state->getFormObject()->getEntity();
@init90
init90 / scratch.txt
Created March 17, 2017 17:49
drupal, drush, chenge password
drush upwd host --password=123
@init90
init90 / global.js
Created March 22, 2017 15:23
Run ctools popup after page load.
Drupal.behaviors.security_questions_popup = {
attach: function(context, settings) {
var need_add_questions = Drupal.settings.global.need_add_security_questions;
if (need_add_questions) {
$(window).bind('load', function() {
$('.security_questions_hide_link').click();
});
}
}
@init90
init90 / cba_webinar.module
Created July 3, 2017 07:31
Drupal 7, update entity path.
/**
* Implements hook_entity_info_alter().
*/
function cba_webinar_entity_info_alter(&$entity_info) {
// Update webinar event path.
$entity_info['event']['bundles']['webinar']['crud']['add']['path'] = 'event/webinar/add';
$entity_info['event']['bundles']['webinar']['crud']['edit']['path'] = 'event/webinar/%eckentity/edit';
$entity_info['event']['bundles']['webinar']['crud']['delete']['path'] = 'event/webinar/%eckentity/delete';
}
@init90
init90 / scratch.txt
Created July 19, 2017 14:48
drupal work with update scheme version
drush ev "echo drupal_get_installed_schema_version('bendrijusistema')";
drupal_set_installed_schema_version('bendrijusistema', 8001);
drupal_get_installed_schema_version('bendrijusistema');
@init90
init90 / LovebooksHelperTraits.php
Created August 8, 2017 08:48
drupal 8, commerce, get currency symbol
/**
* Get currency symbol.
*
* @param object $product_variation
* @return string
*/
public function getCurrencySymbol($product_variation) {
$currency_code = $product_variation->get('price')->currency_code;
$currency = Currency::load($currency_code);