Skip to content

Instantly share code, notes, and snippets.

View woutersf's full-sized avatar

woutersf woutersf

View GitHub Profile
@woutersf
woutersf / cloudinary_metadata_export.js
Last active October 5, 2023 10:44
Cloudinary export Metadata from FOLDER
/**
1. Make sure the exported file does not exist (archive.csv)
2. Replace the following with the correct information:
- THE_FOLDER_ON_THE_DAM
- MYCLOUDNAME_HERE
- MY_API_KEY_HERE
- MY_API_SECRET_HERE
3. npm install csv-writer and npm install cloudinary
4. Run with 'node cloudinary_metadata_export.js'

Dropsolid Personalisation 1 on 1

Required

php working preferrably composer working too

Installation

Install drupal

mkdir drupal && cd drupal && curl -sSL https://www.drupal.org/download-latest/tar.gz | tar -xz --strip-components=1

@woutersf
woutersf / custom_drupal_bootstrap.php
Created January 28, 2017 10:09
custom drupal bootstrap (for performance)
<?php
if(empty($_GET['submithandler']) && empty($_POST['submithandler'])) {
http_response_code(400);
die('Invalid data');
}
define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
require_once DRUPAL_ROOT. '/includes/bootstrap.inc';
require_once DRUPAL_ROOT. '/includes/common.inc';
@woutersf
woutersf / drupal8_table_with_render_array.php
Created January 16, 2017 15:55
drupal8 nested render array in table
<?php
$header = array();
foreach ($programs->list as $program) {
$rows[] = array(
'img' => array(
'data' => array(
'#theme' => 'image',
'#attributes' => array(
'src' => $program->images[0]->url, //Images come from an external resources, otherwise use #uri on the level of #attributes
)
@woutersf
woutersf / drupal8 taxonomy_get_tree.php
Created January 16, 2017 13:58
drupal8 taxonomy_get_tree
<?php
$tree = \Drupal::service('entity_type.manager')
->getStorage("taxonomy_term")
->loadTree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE));
@woutersf
woutersf / drupal8_render_field_value_in_twig.twig.html
Created January 6, 2017 12:48
drupal8 render field value in twig
//render all content without a specific field
{{ content.without('field_name') }}
//render only one specific field
{{ content.field_audio_file }}
//render only one specific field's value
{{ content.field_audio_file.value }}
@woutersf
woutersf / drupal8_test_https.php
Last active May 12, 2020 12:30
Drupal 8 test if on https page
<?php
// Drupal 7
global $is_https;
if ($is_https) {
// Do something
}
// Drupal 8
if (Drupal::request()->isSecure()) {
@woutersf
woutersf / drupal8_variable_get_override_settings.php
Last active March 12, 2017 08:18
Drupal8 settings and config, override settings in settings.php, variable_get en variable_set
<?php
// Fetching The data via the container (old variable_get)
$data = \Drupal::config('my_module.settings')->get('my_setting_name');
// Fetching the data via the Settings class
use Drupal\Core\Site\Settings;
$settings = Settings::get('http_client_config');
$data = $settings['my_setting_name'];
@woutersf
woutersf / Drupal8_drupal_http_request.php
Last active January 3, 2017 10:00
Drupal8 version of drupal_http_request
<?php
$client = \Drupal::httpClient();
$url = 'http://something.com/data.json';
try {
$request = $client->get($url);
$status = $request->getStatusCode();
//Do something here.
//For example:
return json_decode($request->getBody()->getContents());
}
@woutersf
woutersf / drupal8_image_style_url.php
Created December 30, 2016 10:25
Drupal 8 image-Style an image
<?php
use Drupal\image\Entity\ImageStyle;
use \Drupal\file\Entity\File;
//Load the file
$file_id = 2;
$file = file_load($file_id);
//Render the IMage style "large"
$image_large_url = ImageStyle::load('large')->buildUrl($file->getFileUri());