Skip to content

Instantly share code, notes, and snippets.

View suresh-kumara-gist's full-sized avatar

Suresh kumara suresh-kumara-gist

View GitHub Profile
@suresh-kumara-gist
suresh-kumara-gist / Jquery fetch table row and td text change it to link
Last active September 5, 2017 05:54
Jquery fetch table row and td text change it to link
@suresh-kumara-gist
suresh-kumara-gist / Drupal 8 get row fields in custom view fields
Created September 5, 2017 14:42
Drupal 8 get row fields in custom view fields
$course_id = $values->_relationship_entities[order_items]->get('field_course')->target_id;
$student_id = $values->_entity->get('uid')->target_id;
@suresh-kumara-gist
suresh-kumara-gist / entity Query
Last active September 8, 2017 09:54
entity Query drupal 8
$query = \Drupal::entityQuery('attendance')
->condition('type', 'student_attendance_tracking', '=')
// entity refernce field
->condition('field_course', 433, '>=');
$courseRatings = $query->execute();
return $courseRatings;
// get all Course Ratings.
function getCourseRatings($groupId) {
$query = \Drupal::entityQuery('attendance')
@suresh-kumara-gist
suresh-kumara-gist / preprocess paragraph entity
Created September 8, 2017 10:41
preprocess paragraph entity drupal 8
function hook_preprocess_paragraph(&$variables) {
//kint($variables['content']['field_class_label'][0]['#text']); die();
if ($variables['content']['field_class_label']['#items']) {
$variables['content']['field_class_label'][0]['#text'] = $variables['content']['field_class_label']['#items']->getString();
}
}
@suresh-kumara-gist
suresh-kumara-gist / drupal 8 entity form submit handler
Created September 8, 2017 10:44
drupal 8 entity form submit handler
$form['actions']['submit']['#submit'][] = "attendanceSubmithandler";
or
// Set redirect
$form_state->setRedirect("attendance_management.feedback_message");
// attach library
$form['#attached']['library'][] = 'attendance_management/fivestar_widget';
@suresh-kumara-gist
suresh-kumara-gist / drupal 8 paragraph field widget alter
Last active September 8, 2017 10:47
drupal 8 paragraph field widget alter
function attendance_management_field_widget_form_alter(&$element, &$form_state, &$context) {
if ($element['#title'] == "class label" && $element['#field_parents']['0'] == 'field_sessions_classes') {
$delta = $element['#delta'];
$attendance = \Drupal::routeMatch()->getParameter('attendance');
$classlabel = $attendance->field_sessions_classes->referencedEntities()[$delta]->field_class_label->getValue()['0']['markup'];
$element['markup']['#text'] = $classlabel;
}
}
@suresh-kumara-gist
suresh-kumara-gist / vagrant power management
Last active September 12, 2017 17:24
vagrant power management
dbus-send --system \
/org/freedesktop/login1 \
org.freedesktop.login1.Manager.PrepareForSleep \
boolean:false
@suresh-kumara-gist
suresh-kumara-gist / Create custom table in drupal 8
Last active February 22, 2019 17:14
Create custom table in drupal 8
Creating custom table in drupal 8 is not recommended. Create entity types instead.
But if you want to Create custom table you can create either by implementing hook_schema or
else create schema file config/schema/your_custom_module_name.schema.yml in your module
(https://www.drupal.org/docs/8/api/configuration-api/configuration-schemametadata).
( https://drupal.stackexchange.com/questions/219580/best-practice-for-creating-table-in-custom-module )
1. Implementing hook_schema in .module file (Not recommended).
/**
@suresh-kumara-gist
suresh-kumara-gist / update field with other table data and case in mysql select query.
Last active September 14, 2017 08:26
update field with other table data and case in mysql select query.
select nfd.nid,nfd.title, CASE casefield
WHEN 0 THEN '0'
WHEN 1 THEN '1'
ELSE NULL
END as casefieldalias
from table1 nfd
join table2 d on nfd.nid = d.tid
where title like '%<%' or title like '%>%' and type in ('testtype');
@suresh-kumara-gist
suresh-kumara-gist / Jquery select all checkboxes
Created September 14, 2017 10:01
Jquery select all checkboxes
jQuery('input:checkbox').attr("checked", "checked");