Drupal 8

How to get bundle label from entity?

Drupal 8 - Print raw SQL queries for debugging

<?php
/**
 * Debugging using the database connection.
 */
/** @var \Drupal\Core\Database\Connection */
$connection = \Drupal::service('database');
$query = $connection->select('node', 'node');
$query->fields('node', ['nid'])
  ->condition('node.type', 'page')
  
// Debug.
dump($query->__toString());

 

Remove query condition in Drupal 8

/**
 * Implements hook_query_QUERY_ID_alter().
 */
function mymodule_query_taxonomy_term_access_alter($query) {
  /** @var \Drupal\Core\Database\Query\Select $query */
  $conditions = &$query->conditions();
  foreach ($conditions as $i => $condition) {
    if (isset($condition['field']) && $condition['field'] === 't.default_langcode') {
      unset($conditions[$i]);
    }
  }
}

Disable cache for a specific page

Disable cache for a custom page from route declaration.

If you want to disable cache for a custom controller (Custom module), You have no_cache option (YOUR_MODULE.routing.yml).
Example :
File : mymodule.routing.yml

Drupal 8 System Link Menu

system.admin:
  title: Administration
  route_name: system.admin
  weight: 9
  menu_name: admin
system.admin_content:

Drupal 8 remove css,js query strings

Drupal 8 remove css,js query strings

Update your THEMENAME.theme

Render a Render array to HTML code

Render a Render array to HTML code

How to get HTML from drupal 8 renderer array ?

How to convert Render array into HTML output code ?

Drupal 8 local settings for development

Drupal 8 Check is front page with alias

Drupal 8 Check is front page with alias
$current_path = \Drupal::service('path.current')->getPath();
$front_uri = Drupal::config('system.site')->get('page.front');
$front_alias = \Drupal::service('path.alias_manager')->getAliasByPath($front_uri);
$current_alias = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);
$isFrontPage = \Drupal::service('path.matcher')->isFrontPage() || $front_alias === $current_alias;

Drupal 8 Twig concat string

Drupal 8 Twig concat string

Drupal 8 get absolute url

    $current_url = \Drupal\Core\Url::fromRoute('<current>', array(), array("absolute" => TRUE))->toString();

Disable All Cache on Drupal 8

Open settings.php add these lines:

$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
$settings['cache']['bins']['render'] = 'cache.backend.null';

Use drush with command drush cr to clear all cache