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 / Drupal 8 get all views display plugins.
Last active August 18, 2017 06:23
Drupal 8 get all views display plugins.
use Drupal\views\Views;
$display_plugins = Views::pluginManager('display')->getDefinitions();
$plugin_ids = [];
foreach ($display_plugins as $id => $definition) {
// if ($definition['provider'] == 'views' || $definition['provider'] == 'views_data_export') {
if ($definition['provider'] == 'views') {
$plugin_ids[] = $id;
}
}
Follow this 2 links
https://github.com/squizlabs/PHP_CodeSniffer
http://www.kianmeng.org/2015/05/is-your-drupal-code-adheres-to-coding.html
@suresh-kumara-gist
suresh-kumara-gist / drupal 8 get default theme logo full path.
Created August 22, 2017 06:56
drupal 8 get default theme logo full path.
$config = \Drupal::config('system.theme');
$theme_settings = \Drupal::config($config->get('default') . '.settings')->get();
$variables['logo_path'] = file_create_url($theme_settings['logo']['path']);
dpm( $variables['logo_path']);
@suresh-kumara-gist
suresh-kumara-gist / drupal 8 way of creating timestamp
Created August 24, 2017 14:12
drupal 8 way of creating timestamp
use Drupal\Component\Datetime\DateTimePlus;
$format = "D";
// create current datetime.
$current_date = new DateTimePlus();
// Format $current_date to dispaly, what ever php datetime format you needed. here I am formatting to 'D'
$current_day = $current_date->format($format, ['timezone' => drupal_get_user_timezone()]);
@suresh-kumara-gist
suresh-kumara-gist / find last sunday and -1 week in drupal 8
Last active August 24, 2017 14:31
find last sunday and -1 week in drupal 8
use Drupal\Component\Datetime\DateTimePlus;
$format = "D";
$current_date = new DateTimePlus();
$current_timezone = date_default_timezone_get();
date_default_timezone_set("UTC");
$current_day = $current_date->format($format, ['timezone' => drupal_get_user_timezone()]);
$lastweek = 'last Sunday -1 week';
$dateformat = 'Y-m-d\TH:i:s';
@suresh-kumara-gist
suresh-kumara-gist / Drupal 8 Entity aggregate Query group by
Last active August 24, 2017 18:00
Drupal 8 Entity aggregate Query group by
$query = \Drupal::entityQueryAggregate('group_content')
->condition('type', 'section-group_node-session', '=')
->condition('entity_id.entity.field_session_from_time1', $startdaydate, '>=')
->condition('entity_id.entity.field_session_to_time1',$endaydate, '<=')
->groupBy('gid');
// result we will get group by field values not group_content entity ids
$result = $query->execute();
dpm($result);
@suresh-kumara-gist
suresh-kumara-gist / database backup using drush
Created August 28, 2017 07:54
database backup using drush
drush sql-dump --structure-tables-list=cache,cache_* > dumpfile.sql
jQuery(".course-rating-statics-toggle").hover(function() {
jQuery(this).children('.course-rating-statics').toggle();
});
@suresh-kumara-gist
suresh-kumara-gist / generating html link and for views route
Created August 31, 2017 11:44
generating html link and for views route
@suresh-kumara-gist
suresh-kumara-gist / select queries in drupal 8
Last active September 19, 2017 11:13
select queries in drupal 8
// get all Course Ratings.
function getCourseRatings($groupId) {
// Query to get all ratings for the course.
$query = \Drupal::database()->select('attendance__field_course', 'afc');
$query->join("votingapi_result", "vr", "vr.entity_id = afc.entity_id");
$query->fields('vr', ['value']);
$query->condition('vr.function', 'vote_sum');
$query->condition('afc.field_course_target_id', $groupId);
$courseRatings = $query->execute()->fetchAll(\PDO::FETCH_ASSOC);
return $courseRatings;