Skip to content

Instantly share code, notes, and snippets.

@init90
init90 / scratch.txt
Created March 17, 2017 17:49
drupal, drush, chenge password
drush upwd host --password=123
@init90
init90 / gist:330ec3864635d7e46e333ab41803b322
Last active May 5, 2018 20:51
drupal 8, get entity from $form_state.
$form_state->getFormObject()->getEntity();
@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 / 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 / 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
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 / scratch.txt
Last active May 5, 2018 21:03
drupal 7, remove one value from multiple entity reference field.
$exam_wrp = entity_metadata_wrapper('event', 10);
$exam_wrp->field_assignee[ITEM_KEY]->set();
$exam_wrp->save();
@init90
init90 / gist:3a4488a7036294db4aca335e6288e5f9
Last active May 5, 2018 21:06
drupal 7, entity query by date and entity reference field.
$q = new EntityFieldQuery;
$exam_id = $exam_wrp->field_event_exan_id->value();
$assignee_user = $q->entityCondition('entity_type', 'event')
->propertyCondition('type', 'exam_event')
->fieldCondition('field_start_event_date', 'value', date('Y-m-d'), '>')
->fieldCondition('field_event_exan_id', 'value', $exam_id, '=')
->fieldCondition('field_assignee', 'target_id', array($GLOBALS['user']->uid), 'IN')
->execute();
@init90
init90 / cba_communication.manual_run.inc
Created December 29, 2016 16:42
Drupal 7, display status message in ctools popup
ctools_include('ajax');
ctools_include('modal');
ctools_modal_add_js();
drupal_set_message('test');
ctools_modal_render('test', theme('status_messages'));
@init90
init90 / cba_events.module
Created December 28, 2016 08:29
drupal 7, display add entity form in ctools popup.
/**
* Create default entity in ctools popup.
*/
function cba_events_create_default_entity_in_popup($js, $user_id) {
if (!$js) {
return drupal_goto('event/default/add');
}
ctools_include('ajax');
ctools_include('modal');