Notes

Drupal 8 countQuery()
$result = \Drupal::database()->select('node')
  ->condition('type', 'article')
  ->countQuery()
  ->execute()->fetchField();

 

Sunday, December 11, 2016 - 20:30
Drupal 8 Delete all content by code
// Define entity type to lookup.
$entity_type = 'node';

// Execute a query in order to retrieve an array of Article's ids.
$ids = \Drupal::entityQuery($entity_type)
  ->condition('type', 'article')
  ->execute();

/** @var \Drupal\node\NodeStorage $controller */
$controller = \Drupal::entityTypeManager()
  ->getStorage($entity_type);

/** @var \Drupal\node\Entity\Node[] $entities */
$entities = $controller->loadMultiple($ids);

// Deletes permanently saved entities.
$controller->delete($entities);

 

Sunday, December 11, 2016 - 20:26
Git Add New Remote
git remote add  [REMOTE_NAME] [REPOSITORY_URL]
git push -u github master

 

Sunday, December 4, 2016 - 02:23
Git reset changes
git reset --hard

 

Sunday, December 4, 2016 - 02:23
Drupal 8: Mismatched entity and/or field definitions
drush updb --entity-updates

Or

drush entity-updates command

Even

drush entup

 

Sunday, December 4, 2016 - 02:23
Drupal 7 Drush install
drush site-install --db-url=mysql://[db_username]:[db_username_password]@[localhost]:[port]/[database_name]

 

Sunday, December 4, 2016 - 02:23
Git Remove Branches
# Delete from local
git branch –D branch-name

# Delete from remote
git push origin :branch-name

# Another way to delete from remote
git push origin --delete branch-name

 

Sunday, December 4, 2016 - 02:22
Drupal 8 Current Router Object
$route = \Drupal::routeMatch()->getRouteObject();

 

Sunday, December 4, 2016 - 02:21
Drupal 8 Route is admin
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);

 

Sunday, December 4, 2016 - 02:20
Drupal 8 MySQL Truncate all caches
TRUNCATE cache_config;
TRUNCATE cache_container;
TRUNCATE cache_data;
TRUNCATE cache_default;
TRUNCATE cache_discovery;
TRUNCATE cache_dynamic_page_cache;
TRUNCATE cache_entity;
TRUNCATE cache_menu;
TRUNCATE cache_render;
TRUNCATE cache_toolbar;

 

Sunday, December 4, 2016 - 01:28