Debug email with Drupal

Safe url data transfer from Javascript to Drupal

  Drupal.safe_encode = function(element) {
    var encode = encodeURIComponent(JSON.stringify(element));
    var base64 = Base64.encode(encode);
    base64 = base64.replace('/', '_');
    base64 = base64.replace('+', '-');
    return base64;
  var base64 = Drupal.safe_encode(object);
  var url = Drupal.url('module-url?component_data='+ base64);


Drupal check request is Ajax

// Example for brevity only, inject the request_stack service and call 
// getCurrentRequest() on it to get the request object if possible.
$request = \Drupal::request();
$is_ajax = $request->isXmlHttpRequest();




Drupal 8 add ajax for reset button in exposed filter views

 * Implements hook_form_BASE_FORM_ID_alter().
function MODULE_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $storge = $form_state->getStorage();
  if (!empty($storge['view']) && $storge['view']->id() === 'my_view') {
    if (isset($form['actions']['reset']) && isset($form['actions']['submit'])) {
      $submit_id = $form['actions']['submit']['#id'];
      $form['actions']['reset']['#attributes']['onclick'] = 'javascript:jQuery(this.form).clearForm();jQuery("#' . $submit_id . '").trigger("click");return false;';

Apache proxy pass exception

ProxyPass /forum !
ProxyPass / http://localhost:8080/tomcat-webapp/
ProxyPassReverse / http://localhost:8080/tomcat-webapp/
Alias /forum /var/www/forum

Edit Drupal 8 config programmatically

Edit Drupal 8 config programmatically
$config_factory = \Drupal::configFactory();
$langcode = $config_factory->get('')->get('langcode');
$config_factory->getEditable('')->set('default_langcode', $langcode)->save();

How to get bundle label from entity?

$bundle_label = \Drupal::entityTypeManager()



$bundle_label = $node->type->entity->label();

Drupal 8 - Print raw SQL queries for debugging

 * 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.


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') {

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

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

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 ?

Vuejs - Hide vuejs syntax when page loading

Vuejs - Hide vuejs syntax when page loading
[v-cloak] {
  display: none;

<div v-cloak>
  {{ message }}





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('')->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

Path Finder sort order

Path Finder sort order

Help you control your Path Finder sort files/folder order.

Fix Node.js doesn't look global folder on MAC

Fix Node.js doesn't look global folder on MAC

Open your ~/.bash_profile add this line

export NODE_PATH=/usr/local/lib/node_modules

Save ~/.bash_profile

Drupal 8 get absolute url

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

MongoDB Admin software

Looking for a best MongoDB Admin for cross-platform. Try it right now:


Download multi files with wget


and your command line

wget -E -H -k -K -p -e robots=off -P /Downloads/ -i ./list.txt

Disable All Cache on Drupal 8

Open settings.php add these lines:

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

Use drush with command drush cr to clear all cache


Using XamarinForms with PixateFreestyle

Demo app show how to using Xamarin Forms with PixateFreestyle

Full source code here:

Exit iOS and Android mobile app with Xamarin

Call this function to close the app:


Get direct download links of Xamarin

Installing Drush on Mac using Homebrew

  1. Install Homebrew with command:
    ruby -e "$(curl -fsSL"
  2. Use Homebrew install drush with commands
    brew tap homebrew/dupes
    brew tap homebrew/versions
    brew tap homebrew/php
    brew install php55
    brew install composer
    brew install drush

Drupal 7 with Laravel 5

I just write a Drupal module allow integrate Drupal with Laravel to work together, you can check here:

More information and example will post in next article.

Code fun.

Install Multiple PHP Versions and PHP 5.5 with Virtualmin on CentOS


Beginning in Virtualmin 3.99, Virtualmin allow you install multiple version of PHP with Software Collections.