Skip to content

Instantly share code, notes, and snippets.

View BBGuy's full-sized avatar

Guy Schneerson BBGuy

View GitHub Profile
@BBGuy
BBGuy / d8_my_module.install
Last active December 10, 2021 13:08
Drupal 8, 9 Schemas
<?php
use Drupal\Core\Database\Database;
/**
* Implements hook_schema().
*
* Notes:
* 'not null' = requiered
*/
<?php
//******** user ***************//
$current_user = \Drupal::currentUser();
$current_user_id \Drupal::currentUser()->id();
$user = User::load($user_id);
//******** messenger - set messeges ***************//
@BBGuy
BBGuy / dc_emw.php
Last active November 16, 2022 14:08
Working with Drupal commerce entities using entity_metadata_wrapper. Just a bunch of exampled copied from the web or added by me. will keep adding over time. now more then just commerce entities
<?php
// Basics
// Get a value.
$value = $wrapper->field_x->value();
// If the field is a reference field you will get the field object
// To get the wrapper back use:
$wrapper_b = $wrapper->field_ref;
// To set a value.
@BBGuy
BBGuy / i18n_get_menu.php
Created November 28, 2012 13:41
Drupal - Build a localized menu programmatically using i18n menu
<?php
function i18n_get_menu_get_localized_menu($menu_name) {
// Get the menu tree
$menu_links = menu_tree($menu_name);
// reform the array to be i18n_menu compatible
$l_menu_links = array();
foreach ($menu_links as $key => $value) {
$l_menu_links[$key]['link'] = $value['#original_link'];
}
// localize the menu