Submitted by Thao Huynh on October 29, 2020 - 13:45
Open settings.php add this line:
$settings['http_client_config'] = ['verify' => FALSE];
Submitted by Thao Huynh on October 10, 2020 - 11:28
# Pull docker postgres
docker pull postgres
# Run postgres instance
docker run --name drupal-postgres -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres
# Exec docker
docker exec -it drupal-postgres bash
# Create database and user;
# Login to postgres command line
psql -U postgres
# Create db and user
create database drupal;
create user drupal with encrypted password 'drupal';
grant all privileges on database drupal to drupal;
# list
\l
# delete database
DROP DATABASE drupal;
# Logout
exit;
# Import database from outside
Submitted by Thao Huynh on July 30, 2020 - 13:34
Submitted by Thao Huynh on July 30, 2020 - 13:31
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);
Submitted by Thao Huynh on September 10, 2019 - 14:41
// 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();
Test
Submitted by Thao Huynh on September 9, 2019 - 14:51
/**
* 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;';
}
}
}
Submitted by Thao Huynh on August 12, 2019 - 12:44
ProxyPass /forum !
ProxyPass / http://localhost:8080/tomcat-webapp/
ProxyPassReverse / http://localhost:8080/tomcat-webapp/
Alias /forum /var/www/forum
Submitted by Thao Huynh on August 2, 2019 - 08:35
$config_factory = \Drupal::configFactory();
$langcode = $config_factory->get('system.site')->get('langcode');
$config_factory->getEditable('system.site')->set('default_langcode', $langcode)->save();
Submitted by Thao Huynh on December 31, 2018 - 08:53
$bundle_label = \Drupal::entityTypeManager()
->getStorage('node_type')
->load($node->bundle())
->label();
$bundle_label = $node->type->entity->label();
Submitted by Thao Huynh on December 22, 2018 - 10:38
<?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());
Submitted by Thao Huynh on December 5, 2018 - 15:19
/**
* 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]);
}
}
}
Submitted by Thao Huynh on December 3, 2018 - 08:25
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
Submitted by Thao Huynh on September 24, 2018 - 10:08
system.admin:
title: Administration
route_name: system.admin
weight: 9
menu_name: admin
system.admin_content:
Submitted by Thao Huynh on September 5, 2018 - 08:26
Update your THEMENAME.theme
Submitted by Thao Huynh on August 27, 2018 - 14:04
Submitted by Thao Huynh on August 16, 2018 - 10:45
How to get HTML from drupal 8 renderer array ?
How to convert Render array into HTML output code ?
Submitted by Thao Huynh on August 14, 2018 - 16:47
[v-cloak] {
display: none;
}
<div v-cloak>
{{ message }}
</div>
Submitted by Thao Huynh on July 3, 2018 - 13:28
Submitted by Thao Huynh on July 3, 2018 - 11:20
$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;
Submitted by Thao Huynh on June 24, 2018 - 10:08
Submitted by Thao Huynh on April 25, 2017 - 13:32
Help you control your Path Finder sort files/folder order.
Submitted by Thao Huynh on August 10, 2016 - 11:41
Open your ~/.bash_profile add this line
export NODE_PATH=/usr/local/lib/node_modules
Save ~/.bash_profile
Submitted by Thao Huynh on April 20, 2016 - 22:54
$current_url = \Drupal\Core\Url::fromRoute('<current>', array(), array("absolute" => TRUE))->toString();
Submitted by Thao Huynh on March 10, 2016 - 16:24
Submitted by Thao Huynh on January 25, 2016 - 22:20
Submitted by Thao Huynh on November 25, 2015 - 22:44
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
Submitted by Thao Huynh on August 4, 2015 - 11:37
Submitted by Thao Huynh on August 1, 2015 - 10:20
Call this function to close the app:
System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
Submitted by Thao Huynh on July 31, 2015 - 13:12
Submitted by Thao Huynh on June 24, 2015 - 13:13
- Install Homebrew with command:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 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