Notes
Drupal 8 countQuery()
$result = \Drupal::database()->select('node')
->condition('type', 'article')
->countQuery()
->execute()->fetchField();
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);
Git Add New Remote
git remote add [REMOTE_NAME] [REPOSITORY_URL]
git push -u github master
Git reset changes
git reset --hard
Drupal 8: Mismatched entity and/or field definitions
drush updb --entity-updates
Or
drush entity-updates command
Even
drush entup
Drupal 7 Drush install
drush site-install --db-url=mysql://[db_username]:[db_username_password]@[localhost]:[port]/[database_name]
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
Drupal 8 Current Router Object
$route = \Drupal::routeMatch()->getRouteObject();
Drupal 8 Route is admin
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);
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;