Skip to content

Instantly share code, notes, and snippets.

View henrytran9x's full-sized avatar

Andy Tran henrytran9x

  • Mercury
  • Vietnam
View GitHub Profile
@henrytran9x
henrytran9x / function.php
Created January 3, 2017 09:06
Render menu navigation menu Drupal 8
<?php
function render_menu_navigation($menu_name,$theme_alter = ''){
//Set system menu mobile
$menu_tree = \Drupal::menuTree();
// Build the typical default set of menu tree parameters.
$parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
// Load the tree based on this set of parameters.
$tree = $menu_tree->load($menu_name, $parameters);
// Transform the tree using the manipulators you want.
$manipulators = array(
@henrytran9x
henrytran9x / mod_block_twig_mod_block_twig.info.yml
Created December 21, 2016 09:56
Module Create function Twig Block render
name: Mod Block Twig
type: module
description: Create function twig render display block
package: Custom module - Required
dependencies:
- block
core: 8.x
version: 1.0
@henrytran9x
henrytran9x / gist:ae6a92d2d78edc7b5244f944b88576b8
Created December 19, 2016 02:37
*SOLVED* Drupal installed in subfolder, want url without subfolder Drupal
For most of my installs, I have Drupal running from subfolders. Here is what I do:
settings.php
Uncomment and modify this line:
# $base_url = 'http://www.example.com'; // NO trailing slash!
.htaccess (in your subfolder)
Unless there are server/web host-specific items to add, this can be left alone
.htaccss (in Web root)
@henrytran9x
henrytran9x / gist:1a561551243e8499bd08d8d2c0453a5f
Created December 7, 2016 03:25
Fix "Additional uncaught exception thrown while handling exception" Drupal
;Change config in mysql database
;my.in in mysql Xampp
max_allowed_packet = 64M (default 1M)
innodb_buffer_pool_size = 500M (default 5M)
@henrytran9x
henrytran9x / function.php
Created December 2, 2016 02:42
File Managed set permanent in Drupal 8 !
<?php
/* Load the object of the file by it's fid */
$file = File::load('fid_file');
/* Set the status flag permanent of the file object */
$file->setPermanent();
/* Save the file in database */
$file->save();
@henrytran9x
henrytran9x / gist:c2b72421656f5672bc280e1ed5349ea1
Created November 23, 2016 02:43 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@henrytran9x
henrytran9x / function.php
Last active November 11, 2016 01:53
Truncate String Words
<?php
function truncateStringWords($str, $maxlen,$replace = '...') {
if (strlen($str) <= $maxlen) return $str;
$newstr = substr($str, 0, $maxlen);
if (substr($newstr, -1, 1) != ' ') $newstr = substr($newstr, 0, strrpos($newstr, " "));
return $newstr.$replace;
}
?>
@henrytran9x
henrytran9x / gist:64ae536728a42854f19eac10e66fad11
Created October 8, 2016 08:34
This patch fix Slider Price in module "better_exposed_filters" drupal 8
diff --git a/better_exposed_filters.module b/better_exposed_filters.module
index 3d67a71..446d726 100644
--- a/better_exposed_filters.module
+++ b/better_exposed_filters.module
@@ -246,8 +246,9 @@ function better_exposed_filters_element_validate_slider_animate($element, &$form
*/
function better_exposed_filters_element_validate_slider_min_max($element, &$form_state) {
$value = $element['#value'];
- $slider_min = $form_state['values']['exposed_form_options']['bef'][$element['#bef_filter_id']]['slider_options']['bef_slider_min'];
- $slider_max = $form_state['values']['exposed_form_options']['bef'][$element['#bef_filter_id']]['slider_options']['bef_slider_max'];
@henrytran9x
henrytran9x / function.php
Created September 9, 2016 23:32
Get keys array by pattern match , return array keys index
<?php
function _array_filter_key($matches,array $array){
$matchedKeys = preg_grep($matches, array_keys($array));
return array_intersect_key($array, array_flip($matchedKeys));
}
@henrytran9x
henrytran9x / hosting.profile
Created July 5, 2016 08:55
Profile Hosting
<?php
/**
* Implements hook_install_tasks_alter().
*/
function hosting_install_tasks_alter(&$tasks, &$install_state) {
$new_tasks = array(
'install_select_profile' => $tasks['install_select_profile'],
'install_select_locale' => $tasks['install_select_locale'],
'install_load_profile' => $tasks['install_load_profile'],
'install_verify_requirements' => $tasks['install_verify_requirements'],