Skip to content

Instantly share code, notes, and snippets.

View sachbearbeiter's full-sized avatar
❤️

Sachbearbeiter sachbearbeiter

❤️
View GitHub Profile
@sachbearbeiter
sachbearbeiter / comment.tpl.php
Created April 3, 2014 15:02
D7: Comments: Get access via foo_preprocess_comment(&$variables) to the comment authors profile image from an ($user) imagefield and print it into the comment.tpl.php template.
<? if (!empty($image)) : ?>
<img src="<?= image_style_url('mini',$image); ?>" alt="Profile image" />
<?php endif; ?>
<?php
/* Script located in the docroot for your Drupal 8 site */
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once __DIR__ . '/core/vendor/autoload.php';
use GuzzleHttp\Client;
@sachbearbeiter
sachbearbeiter / .bashrc
Last active August 29, 2015 14:14 — forked from cbeier/.bashrc
alias drush='~/drush/drush'
alias php='/usr/local/bin/php5-53STABLE-CLI'
export DRUSH_PHP=/usr/local/bin/php5-53STABLE-CLI

Install Composer on Managed Hosting at Domainfactory

Step 1:

Log in to your Managed Hosting Server via SSH

Step 2:

Add these two lines to .bashrc:

@sachbearbeiter
sachbearbeiter / page.html.twig
Created January 30, 2015 10:18
D8: Get the current user ID in theme file and set a variable via MYTHEME_preprocess_page to use it in page.html.twig.
{# isAdmin? #}
{% if UserID == '1' %}
{{ kint() }}
{% endif %}
@sachbearbeiter
sachbearbeiter / debug-renderable-array.twig
Created January 31, 2015 15:42
I'm not sure if I'm being too obvious but 'item' is a placeholder some "renderable array". Depending on which template you are in that variable name will change. Within any template you can get a list of the available variables when you have twig_debug turned on by means of {{ dump(_context|keys) }} which if I remember right kint() will be nicer…
{{ dump(_context|keys) }}
@sachbearbeiter
sachbearbeiter / theme.php
Created February 2, 2015 08:42
D8: Theming examples: Theme: New more specific suggestions for the image.html.twig template ... *http://drupal.stackexchange.com/questions/137652/override-image-formatter-html-twig/141340#141340 **Drupal 8 is still Beta - improvements through API modifications are possible!
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function MYTHEME_theme_suggestions_image_formatter_alter(array &$suggestions, array $variables) {
$entity = $variables['item']->getEntity();
$field_name = $variables['item']->getParent()->getName();
$suggestions[] = 'image_formatter__' . $entity->getEntityTypeId() . '__' . $entity->bundle() . '__' . $field_name;
}
@sachbearbeiter
sachbearbeiter / theme
Last active August 29, 2015 14:14
D8: Theming examples: Theme: Additional suggestion for content block templates: taking the bundle type into account. *First results of struggling through Drupal 8 - better solutions are probably out there! **Drupal 8 is still Beta - improvements through API modifications are possible!
<?php
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function MYTHEME_theme_suggestions_block_alter(array &$suggestions, array $variables)
{
$block = $variables['elements'];
$blockType = $block['#configuration']['provider'];
if ($blockType == "block_content") {
@sachbearbeiter
sachbearbeiter / theme.php
Created April 8, 2015 08:55
D8: Theming examples: Theme: Global theme variables - get path to the active theme
<?php
\Drupal::theme()->getActiveTheme()->getPath();
?>
<?php
// Load the currently logged in user.
global $user;
// Check if the user has the 'editor' role.
if (in_array('editor', $user->roles)) {
// do fancy stuff
}
?>