Skip to content

Instantly share code, notes, and snippets.

@Bhavdip
Bhavdip / sketch-never-ending.md
Created October 6, 2016 15:53
Modify Sketch to never ending trial

###Sketch trial non stop

Open hosts files:

$ open /private/etc/hosts

Edit the file adding:

127.0.0.1 backend.bohemiancoding.com

127.0.0.1 bohemiancoding.sketch.analytics.s3-website-us-east-1.amazonaws.com

@annikaC
annikaC / AccountEditRedirectController.php
Created September 29, 2016 14:03
Drupal 8 redirect user to own user edit page (for use in menu links)
<?php
namespace Drupal\yourmodule\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* A controller that redirects to the current user's edit account page.
@Laro88
Laro88 / README.md
Created September 27, 2016 08:37
function to format data for chart to plot series of timestamp,value

The topic of interest in the "function slice and aggregate...." It solves the problem of plotting {timestamp, value} points, not just adding a new value.

It originates from polling a public api that exposes recorded IoT data. The data received contains the latest value for the inquired sensors, however since the data is timestamped, these should be respected in the plotting.

Notice: The context stores the obtained dataset and adds points if the timestamp is not previously seen. Some memory is wasted maintaining a lookup array that is not used for anything.

<?php
$referenced_files = $node->get('your_field')->referencedEntities();
$vars['download_article'] = file_create_url($referenced_files[0]->uri->value);
@raphaellarrinaga
raphaellarrinaga / drupal_8_twig_cheatsheet.md
Last active February 23, 2025 02:49
[Drupal 8 Twig cheatsheet] #tags: drupal8, twig, cheatsheet

Drupal 8 Twig cheatsheet

Please note I created that sheet as a personal side note/draft and not everything is fully tested. There could be errors or better things to do. So if you spot something wrong or something that can be improved, feel free to comment below and I will do the changes.

Getting Drupal 8 field values in Twig

Image path: {{ file_url(content.field_name['#items'].entity.uri.value) }}

@mortendk
mortendk / image-widget.html.twig
Created July 13, 2016 10:57
image widget upload label as a button trick
{#
.theme:
function birch_preprocess_image_widget(&$variables, $hook) {
// the image widget needs to know what the label is
// look in admin/image-widget.hmtl.twig
$variables['form_label_id'] = $variables['element']['#id'];
}
#}
{#
@waako
waako / theme.php
Created June 3, 2016 12:11
Drupal Paragraphs get image url with image style
<?php
use Drupal\image\Entity\ImageStyle;
/**
* Implements hook_preprocess_HOOK() for paragraph--para-slide.html.twig.
*/
function themename_preprocess_paragraph__para_slide(&$variables) {
$paragraph = $variables['paragraph'];
if (!$paragraph->field_image->isEmpty()) {
$parameters = new MenuTreeParameters();
$parameters->setMaxDepth(2)->onlyEnabledLinks();
$menuTreeService = Drupal::menuTree();
$tree = $menuTreeService->load('main', $parameters);
if ($tree) {
$build = $menuTreeService->build($tree);
<?php
/**
* Implements template_preprocess_paragraph().
*/
function TEMPLATE_preprocess_paragraph(&$variables) {
$paragraph = $variables['paragraph'];
$bundle = $paragraph->bundle();
if ($bundle == 'mybundle') {
// do stuff
//in dollartheme.theme where dollartheme is your theme name
function dollartheme_preprocess_node(array &$variables) {
$node = $variables['node'];
$variables['abs_url'] = $node->url('canonical', array(
'language' => $node->language(),
'absolute' => TRUE,
));