Skip to content

Instantly share code, notes, and snippets.

View zuhairkareem's full-sized avatar
🏠
Working from home

zuhairkareem

🏠
Working from home
View GitHub Profile
@zuhairkareem
zuhairkareem / gist:bdbd93a0a7fa5fc81c343033e9a0df5b
Created June 29, 2016 10:07
Drupal 8 - Themes appear broken in admin
--- check if tmp files are configured properly with owner,permissions
--- sites/default/files have all the permissions
$node_object = Node::load((int) $node_id);
$node_object->field_image->entity->url();
@zuhairkareem
zuhairkareem / gist:278e08d42ef2ce64052f6ae179e0fb6e
Created June 29, 2016 10:12
Statistics in Views Drupal 8
Select in Views --sort criteria - Total Views,Most recent view, Views today
@zuhairkareem
zuhairkareem / gist:3288c26c9fd62360bd458b2d67a803d1
Created June 29, 2016 10:14
Views with exposed filter with datepicker with same starting and ending date not giving any results
-- time stamp automatically gets time at the morning ie same time in From and to fields.
-- there should be a provision to change time with date.
@zuhairkareem
zuhairkareem / gist:9c62122c7313a0666d87ec975ff5453e
Created June 29, 2016 10:17
Devel memory exhausted error in Drupal 8
1) install latest dev version of devel
2) change the no. of levels to show in devel config in the following file : -
devel/kint/kint/config.default.php - $_kintSettings['maxLevels'] = 4; reduce it.
@zuhairkareem
zuhairkareem / gist:1cfe196c3799e24b88e399d6dbb3cbad
Created June 29, 2016 10:19
Get all the users with particulare role.
$query = \Drupal::service('entity_type.manager')->getStorage('user')->getQuery();
$query->condition('roles', 'administrator');
$query->execute();
@zuhairkareem
zuhairkareem / gist:6583e5a6c91667cc21d587f07c665e70
Created June 29, 2016 10:20
Get All User Roles in Drupal 8
$roles = \Drupal\user\Entity\Role::loadMultiple();
@zuhairkareem
zuhairkareem / gist:4a4e169ec7f81afc0bec24b0c2b32b05
Created June 29, 2016 10:20
Get a user's roles from uid in D8
$uid = 4; //The user ID
$user = \Drupal\user\Entity\User::load($uid);
$roles = $user->getRoles();
@zuhairkareem
zuhairkareem / gist:ac499d9798b9c851795fcc8d4bfeedd4
Last active June 29, 2016 10:22
To get current user's roles in D8
$userCurrent = \Drupal::currentUser();
$user = Drupal\user\Entity\User::load($userCurrent->id());
$roles = $user->getRoles();
@zuhairkareem
zuhairkareem / gist:3d5ca244c20617a39d0ac9a8a5c19111
Created June 29, 2016 10:24
Get field data from entity in D8
$entity_st = \Drupal::entityManager()->getStorage('entity_name');
$entity_obj = $entity_st->load(entity_id);
$field_value = $entity_obj->get('field_name')->value;