Skip to content

Instantly share code, notes, and snippets.

@raphaellarrinaga
raphaellarrinaga / drupal_7_php_cheat.md
Last active Jul 1, 2020
[Drupal 7 php/config cheatsheet] #tags: drupal7, php, cheatsheet, config
View drupal_7_php_cheat.md

Drupal 7 PHP cheatsheet

Get the NID of the current node

Assuming your code is running for a node page, the methods I see used most often in core/contrib modules are either using menu_get_object() or arg():

if ($node = menu_get_object()) {
  // Get the nid
  $nid = $node->nid;
@raphaellarrinaga
raphaellarrinaga / git_cheatsheet.md
Last active Jul 16, 2020
[GIT cheatsheet] #tags: git, cheatsheet
View git_cheatsheet.md
@raphaellarrinaga
raphaellarrinaga / drupal_install.md
Last active Oct 6, 2021
[Drupal install & config process from scratch] #tags: drupal, drupal8, config
View drupal_install.md

// Update 2021

composer create-project drupal/recommended-project myproject -n or

composer create-project drupal/recommended-project:^8.9 myproject -n

cd myproject
lando init --source cwd --recipe drupal8 --webroot web --name myproject
lando start
@raphaellarrinaga
raphaellarrinaga / drupal_8_php_cheat.md
Last active Sep 4, 2022
[Drupal 8 php/config cheatsheet] #tags: drupal8, php, config, cheatsheet
View drupal_8_php_cheat.md

Drupal 8 PHP cheatsheet

Get current node id

$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
  $nid = $node->id();
}
@raphaellarrinaga
raphaellarrinaga / drupal_8_twig_cheatsheet.md
Last active Sep 4, 2022
[Drupal 8 Twig cheatsheet] #tags: drupal8, twig, cheatsheet
View drupal_8_twig_cheatsheet.md

Drupal 8 Twig cheatsheet

Please note I created that sheet as a personal side note/draft and not everything is fully tested. There could be errors or better things to do. So if you spot something wrong or something that can be improved, feel free to comment below and I will do the changes.

Getting Drupal 8 field values in Twig

Image path: {{ file_url(content.field_name['#items'].entity.uri.value) }}