This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get all countries. | |
\Drupal::service('address.country_repository')->getList(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#sources | |
# https://www.drupal.org/docs/contributed-modules/twig-tweak-2x/cheat-sheet | |
# https://straightupcraft.com/articles/how-to-check-if-a-variable-or-value-exists-using-twig | |
# Render a view | |
{{ drupal_view('who_s_new', 'block_1') }} | |
# Get the result of a view | |
{{ drupal_view_result('who_s_new', 'block_1') }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Field group does not by default show on commerce relaed entities and those can be added using a hook | |
/** | |
* Implements hook_field_group_content_element_keys_alter | |
* | |
* Add field groups to product and product variation. | |
*/ | |
function fcl_commerce_field_group_content_element_keys_alter(&$keys) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\file\Entity\File; | |
// Load a file using its ID | |
$file = File::load($fid); | |
// Find a file using its URI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Util functions to load a select lists options from a taxonomy or a node field with a text list. | |
function build_form() { | |
$form = []; | |
// Load a two level deep select tree from a taxonomy | |
$options = load_taxonomy_as_select_options('example_taxonomy'); | |
$form['select_tree'] = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function buildForm(array $form, FormStateInterface $form_state) { | |
// If the form was submited the form build has access to the user entered data. | |
$user_input = $form_state->getUserInput(); | |
$has_been_submitted = !empty($user_input); | |
// multiple submit buttons | |
$form['cases']['submit'] = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\Core\Database\Database; | |
/** | |
* Implements hook_schema(). | |
* | |
* Notes: | |
* 'not null' = requiered | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//******** user ***************// | |
$current_user = \Drupal::currentUser(); | |
$current_user_id \Drupal::currentUser()->id(); | |
$user = User::load($user_id); | |
//******** messenger - set messeges ***************// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am BBGuy on github. | |
* I am guy_schneerson (https://keybase.io/guy_schneerson) on keybase. | |
* I have a public key whose fingerprint is E0F9 7435 1C0D 3783 458E 5F99 CE91 6F6F 7690 BF49 | |
To claim this, I am signing this object: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Working with commerce stock 8.x-1.x | |
// ****** Usfull commerce code. ****** | |
// Get the curent store and user | |
$currentStore = \Drupal::service('commerce_store.current_store')->getStore(); | |
$currentUser = \Drupal::currentUser(); | |
// Load the user object |
NewerOlder