Skip to content

Instantly share code, notes, and snippets.

@skounis
skounis / access.php
Created Apr 2, 2021
Access a variable in the parent scope from an anonymous function in PHP
View access.php
$result = '';
fetch("SELECT title FROM tbl", function($r) use (&$result) {
$result .= $r['title'];
});
@skounis
skounis / www-do.sh
Created Apr 2, 2021
Run commands as www-data
View www-do.sh
sudo -u www-data /var/push.sh
@skounis
skounis / www-keys.sh
Created Apr 2, 2021
Assign the user www-data an SSH key
View www-keys.sh
sudo mkdir /var/www/.ssh
sudo chown -R www-data /var/www/.ssh
sudo -u www-data ssh-keygen -t rsa
@skounis
skounis / untrack.sh
Created Apr 2, 2021
Git Untrack LFS files
View untrack.sh
git lfs untrack '<file-type>'
git rm --cached '<file-type>'
git add '<file-type>'
git commit -m "restore '<file-type>' to git from lfs"
@skounis
skounis / salt.sh
Created Feb 5, 2021
Generate a hash_salt with drush
View salt.sh
drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))"
@skounis
skounis / field_value.php
Created Aug 27, 2020
To extract the field value in Drupal 8
View field_value.php
// We can go the long way
$field = $group->some_field->first();
// then
$reference_entity_id = $field->getValue()['target_id'];
// But there is a better way to do it
$reference_entity_id = $group->some_field->target_id;
// The same way we can extract simple types, like string and integer
@skounis
skounis / one-time-logins.sh
Last active Aug 4, 2020
On time login links for all the users. Drupal
View one-time-logins.sh
for uid in $(drush sqlq "SELECT uid FROM users"); do drush user:login --uid=$uid; done
@skounis
skounis / preprocess_links__language_block.php
Last active Jul 28, 2020
Drupal - Preprocess language links
View preprocess_links__language_block.php
View prevent.php
function fut_content_preprocess_field(&$variables) {
$element = $variables['element'];
if ($element['#field_type'] == 'comment') {
if (_fut_content_prevent_comments()) {
unset($variables['comment_form']);
}
}
}
function fut_content_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {