Skip to content

Instantly share code, notes, and snippets.

View davidjguru's full-sized avatar
🍅
Working within a pomodoro cycle

David Rodriguez davidjguru

🍅
Working within a pomodoro cycle
View GitHub Profile
@davidjguru
davidjguru / from_timestamp_to_date_drupal_8.txt
Last active February 3, 2023 09:36
Getting a timestamp and transforming to date in Drupal 8
## From a current timestamp (today) to a date
$today = DrupalDateTime::createFromTimestamp(time());
## From a current timestamp to a future date (six months ahead)
$next = DrupalDateTime::createFromTimestamp(strtotime('+6 months', time()));
## And using it to poblate a datefield within a Drupal Form (by example)
$element['nextdate'] = [
'#type' => 'datetime',
'#title' => t('See you'),
@davidjguru
davidjguru / ManagingActivitiesRegisterBlock.php
Created June 24, 2020 11:18
Rendering a Form inside a custom Block by code in Drupal 8 || 9
<?php
namespace Drupal\managing_activities\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@davidjguru
davidjguru / Drupal Multisite Drush Script
Created October 3, 2022 09:49 — forked from gueno/Drupal Multisite Drush Script
If you're running multiple sites on one drupal installation, here is a script to run different Drush commands on all of them
#!/bin/bash
# Get all Drupal sites
sites=`find . -maxdepth 1 -type d -print | grep -v '/all$' | grep -v '/default$' | grep -v '\.$'`
echo "Choose the commande to execute : "
echo "1. update"
echo "2. put sites offline"
echo "3. put sites online"
echo "4. clear all cache"
@davidjguru
davidjguru / top_ten_frequent_operations_developing_with_drupal.md
Last active September 28, 2022 08:00
List of top ten most frequent operations developing with Drupal.

1. Getting config values from the system

1.1 Getting config values from a hook

$slogan = \Drupal::config('system.site')->get('slogan');

1.2 Getting config values from a preprocess function of a template file

e.g. => mytheme_preprocess_node(&$variables))

@davidjguru
davidjguru / IntegerDropdownWidget.php
Created May 8, 2018 12:06 — forked from crittermike/IntegerDropdownWidget.php
Drupal 8 form widget example: creates a select dropdown for integer fields. Place in src/Plugin/Field/FieldWidget
<?php
/**
* @file
* Defines a dropdown widget for integer fields.
*/
namespace Drupal\nba_content_core\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Field\FieldItemListInterface;
@davidjguru
davidjguru / my_favourite_git_aliases_for_prompt.md
Created March 31, 2022 09:22
Gathering my favourite git aliases (from the Linux OS level, not like Git aliases).

Git Related Aliases

Getting basic info of the situation of your project: status, branches, current branch, naming of remote repo.

alias gs='git status'
alias gb='git branch'
alias gr='git remote -v'
alias gp='git rev-parse --abbrev-ref HEAD'

Getting info from 'Git log' about last commits, last changed files in 12 months by order and by commit message.

@davidjguru
davidjguru / git_getting_all_remote_branches_updated_in_local_environment.md
Created March 30, 2022 11:30
How to get all the code from remote repository from all the available remote branches.
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
@davidjguru
davidjguru / settings.local.php
Created January 16, 2020 11:51 — forked from keopx/settings.local.php
Drupal 8 Redis settings.local.php
<?php
/**
* Set redis configuration.
*/
/** @see: https://docs.platform.sh/frameworks/drupal8/redis.html */
if (extension_loaded('redis')) {
// Set Redis as the default backend for any cache bin not otherwise specified.
// $settings['cache']['default'] = 'cache.backend.redis';
@davidjguru
davidjguru / drupal_8_working_with_links_in_different_ways.txt
Created September 6, 2019 10:37
Drupal 8: Working with links in different ways.