Skip to content

Instantly share code, notes, and snippets.

View flesheater's full-sized avatar
🙃
при нас файловете винаги са обърнати

Nikolay Borisov flesheater

🙃
при нас файловете винаги са обърнати
View GitHub Profile
@flesheater
flesheater / drupal.unit.test.php
Last active July 15, 2019 20:42
DrupalUnitTest
<?php
#tests/src/Unit/FibonacciServiceTest.php
namespace Drupal\Tests\drupalup_fibo\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\drupalup_fibo\FibonacciService;
/**
* Our unit test for the fibonacci service.
@flesheater
flesheater / aa_PHP_QUALITY_TOOLS.md
Last active June 12, 2019 15:01
PHP quality tools cheatsheet.

Code Sniffer

Checking if code covers coding standards.

Installable with composer

Codesniffer

composer require --dev "squizlabs/php_codesniffer=*"

Coder module with the Drupal standards

@flesheater
flesheater / gist:e9deb9991d371bf4e851790496bad44f
Last active April 4, 2019 10:46
Custom variable in settings.php
settings.php
$settings['custom_var'] = '55';
then
use Drupal\Core\Site\Settings;
$my_var = settings::get('custom_var', '66') ;
composer create-project drupal-composer/drupal-project:8.x-dev some-dir --no-interaction
../vendor/bin/drush site:install --db-url=mysql://DB_ROOT:DB_PASS@localhost:3306/DB_NAME
{% include active_theme_path() ~ '/images/picture.png' %}
@flesheater
flesheater / load_translation_string.php
Last active November 15, 2018 09:48
Load translation string
$locale_storage = Drupal::service('locale.storage');
$f_name_string_source = $locale_storage->getStrings(['source' => 'First name'], []);
if (!empty(reset($f_name_string_source))) {
$f_name_string_source = reset($f_name_string_source);
$f_name_string = $locale_storage->getTranslations(['language' => 'ro', 'lid' => $f_name_string_source->lid], []);
if (!empty(reset($f_name_string))) {
$f_name_string = reset($f_name_string);
if (!$f_name_string->isNew()) {
@flesheater
flesheater / drush_backup_and_restore.sh
Last active July 2, 2018 22:58
Drush create a db backup
# create a db backup
drush sql-dump | gzip > drupal_up_28_05_2018_2145.sql.gz
# import db backup
gunzip < drupal_up_28_05_2018_2145.sql.gz | drush sqlc
@flesheater
flesheater / git_patch.sh
Last active November 21, 2018 15:55
Simple patch create and patch apply with git
# Simple create patch from changes in your git repo
git diff HEAD path-to-changed-file > description-of-patch.patch
# Creating a patch from a special branch.
# 1. I am on a feature page.
# 2. I did my changes + made a commit.
# 3. Creating the patch
git diff dev_branch > short-description-TICKETID-COMMENTID.patch
@flesheater
flesheater / drush_config_delete.sh
Last active November 21, 2018 16:00
Remove configuration from the active config with drush
drush php-eval "Drupal::configFactory()->getEditable('system.menu.devel')->delete();"
// If you load a $node or something.
kint_require();
\Kint::$maxLevels = 3;
kint($node);