Skip to content

Instantly share code, notes, and snippets.

@vkechagias
vkechagias / Drupal 8 installation profile
Last active Jun 14, 2017
Drupal installation profile generation
View Drupal 8 installation profile
01. Composer drupal generator - https://github.com/drupal-composer/drupal-project
02. composer require all modules of original installation
03. Add premium theme to composer installation
04. Add sites/default/files files to composer installation
05. Import DB and clear cache
06. install install_profile_generator module with composer
07. install default_content module with composer
08. install file_entity module with composer
09. enable install_profile_generator, default_content, rest and file_entity modules
10. drush cr and cron
@vkechagias
vkechagias / social-media.html
Created Sep 8, 2017
Style+ social media block HTML markup
View social-media.html
<div class="social-media">
<div class="row grid-gutter-0">
<div class="col-md-3 col-xs-6">
<div class="overlay-container">
<span class="overlay overlay--visible">
<a class="overlay-target-link" href="#"></a>
<span class="overlay-caption-container">
<a href="#" class="overlay-caption overlay-caption--black">OUR BLOG</a>
</span>
</span>
@vkechagias
vkechagias / settings.local.php
Last active Jan 15, 2019
Drupal 8: Reduce Kint() levels through settings.local.php
View settings.local.php
/**
* Add at the bottom of the file and make sure path exists
*/
require_once DRUPAL_ROOT . '/modules/devel/kint/kint/Kint.class.php';
Kint::$maxLevels = 4;
@vkechagias
vkechagias / helpers.html.twig
Last active Jan 15, 2019
Drupal 8: Twig development helper snippets
View helpers.html.twig
{# List all available properties of field #}
{{ kint(node.field_machine_name[0].getProperties(true)) }}
@vkechagias
vkechagias / themename.theme.php
Last active Jan 15, 2019
Drupal 8: Get current page route name
View themename.theme.php
function THEME_preprocess_page(&$variables) {
$variables['route_name'] = \Drupal::routeMatch()->getRouteName();
}
@vkechagias
vkechagias / themename.theme.php
Last active Jan 15, 2019
Drupal 8: Proper way to consistently get field entity according to active language in themename.theme
View themename.theme.php
function THEME_preprocess_page__node(&$variables) {
$translated_node = \Drupal::service('entity.repository')->getTranslationFromContext($variables['node']);
if (!empty($translated_node)) {
$field_data = $translated_node->get('FIELD_MACHINE_NAME')->getValue();
}
}
@vkechagias
vkechagias / themename.theme.php
Created Jan 29, 2019
Drupal 8: Get crop types of image if any
View themename.theme.php
<?php
function minimalplus_preprocess_node(&$variables) {
$field_image = $variables['elements']['field_image'];
if (!empty($field_image) && !empty($field_image['#items']->first()) && !empty($field_image['#items']->first()->target_id)) {
$image_tid = $field_image['#items']->first()->target_id;
$image = File::load($image_tid);
$moduleHandler = \Drupal::service('module_handler');
if (!empty($image) && !empty($image->getFileUri()) && $moduleHandler->moduleExists('crop')) {
$crops = \Drupal::entityTypeManager()->getStorage('crop')->loadByProperties(['uri' => $image->getFileUri()]);
@vkechagias
vkechagias / commands.sh
Last active Feb 7, 2019
Drupal 8: Check theme for deprecated functions
View commands.sh
composer require mglaman/phpstan-drupal phpstan/phpstan-deprecation-rules --dev
cp phpstan.neon # place in drupal root / as in https://gist.github.com/vkechagias/05e8388734c78503cff9d5ea4e1acc19
./vendor/bin/phpstan analyse themes/custom/THEMENAME
@vkechagias
vkechagias / phpstan.neon
Last active Feb 7, 2019
Sample phpstan.neon file to use when checking for Drupal 8 deprecated functions
View phpstan.neon
parameters:
customRulesetUsed: true
reportUnmatchedIgnoredErrors: false
# Exclude directories that you may need to
excludes_analyse:
- themes/custom/scholarly/js/revolution
# Ignore phpstan-drupal extension's rules.
ignoreErrors:
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
- '#Plugin definitions cannot be altered.#'
View git-tree.sh
#!/bin/bash
git log --oneline --graph --color --all --decorate