Skip to content

Instantly share code, notes, and snippets.

View yann-yinn's full-sized avatar

Yann yann-yinn

  • Yann
  • France, Nantes
View GitHub Profile
@yann-yinn
yann-yinn / drupal-7--user_has_role.php
Last active August 29, 2015 14:13
Drupal 7 - check if user has a specific role, checking role id and NOT role labels
/**
* Check if user has one of the roles passed as an array
*
* @param array $roles : array of roles as int (rid stored in database.
* @param int $user_id : optionnal, default to current user if not defined
* @return bool
*/
function user_has_role($roles = array(), $user_id = null) {
if (is_null($user_id)) {
$user_id = $GLOBALS['user']->uid;
@yann-yinn
yann-yinn / jquery--ajax-popup.js
Last active October 8, 2015 15:18
Ajax popup drupal
// limit scope fo our variable, and pass Jquery object as "$".
(function ($) {
Drupal.behaviors.rf_frequence = {
attach : function (context){
popup_open(context);
}
}
@yann-yinn
yann-yinn / jquery--socialsharing--facebook.js
Last active October 8, 2015 16:58
social sharing js facebook
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/fr_FR/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, \'script\', \'facebook-jssdk\'));
</script>';
@yann-yinn
yann-yinn / drupal-6--cck-update.php
Last active December 26, 2015 18:58
cck update programmatically d6
<?php
module_load_include('crud.inc', 'content', 'includes/content');
$field = content_field_instance_read(array('field_name' => 'field_obsarticle_image'));
$field[0]['display_settings'][4]['exclude'] = 1;
content_field_instance_update($field[0]);
dpm($field);
?>
<?php
function HOOK_preprocess_page(&$variables) {
if (menu_get_object()->type == 'temoignage') {
drupal_set_breadcrumb([
l('Home', '<front>'),
l('Tous les témoignages', 'tous-les-temoignages')
]);
}
}
@yann-yinn
yann-yinn / await-getWpPosts.js
Created June 13, 2017 11:00
Get data property from response returned by Axios
const endpoint = 'https://public-api.wordpress.com/wp/v2/sites/yineo.fr'
const axios = require('axios')
async getPosts (perPage = 10) {
return {data} = await axios.get(endpoint + '/posts?_embed&per_page=' + perPage)
}
@yann-yinn
yann-yinn / bulma-grid.vue
Last active June 28, 2017 15:10
Create automatically a Bulma css Grid from :items using slot
<!--
Create automatically a Bulma css Grid from :items
USAGE :
<bulma-grid :items="yourItems" itemsByRow="3">
<template scope="row">
<recipe-card :node="row.item"></recipe-card>
</template>
@yann-yinn
yann-yinn / gist:98d4c9acade0425899da06a9d6dd4000
Created June 29, 2017 22:26
example subrequest response
--8008cc8c5062d2956217bc47b0e08169
Cache-Control: must-revalidate, no-cache, private
Content-Id: <27c656e5c6f170d20649584828a7f7aa>
Content-Language: en
Content-Type: application/vnd.api+json
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Status: 200
X-Content-Type-Options: nosniff
X-Drupal-Cache: HIT
X-Drupal-Dynamic-Cache: MISS
@yann-yinn
yann-yinn / gist:e06cb195a361d97ad4b8f1333ac7e63b
Created June 29, 2017 22:27
example subrequest response
--8008cc8c5062d2956217bc47b0e08169
Cache-Control: must-revalidate, no-cache, private
Content-Id: <27c656e5c6f170d20649584828a7f7aa>
Content-Language: en
Content-Type: application/vnd.api+json
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Status: 200
X-Content-Type-Options: nosniff
X-Drupal-Cache: HIT
X-Drupal-Dynamic-Cache: MISS
@yann-yinn
yann-yinn / example subrequest
Last active June 29, 2017 22:34
example subrequest
[
{
"requestId": "0",
"uri": "/api/recipes?filter[category.name][value]=Main%20course&page[limit]=4",
"action": "view",
"headers": {
"Accept": "application/json",
"Content-Type": "application/vnd.api+json"
}
},