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--fapi_multifield.php
Last active June 14, 2018 15:12
Creat multiple field (add more buttons) for form api elements
<?php
/**
* @file
* Re-usable stuff.
*
* @FIXME multifield function seems not to work in included several times in the same page.
*/
/**
* Implements hook_theme()
@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);
?>
@yann-yinn
yann-yinn / drupal-7--bootstrap--phpunit.php
Last active October 10, 2019 01:42
Drupal 7 bootstrap for php unit
/**
* Script to bootstrap Drupal 7 for PHPUnit tests.
* On multisite installation, set $http_host variable
* to the site you want to test.
*/
/*=====================
SETTINGS
====================*/
// set here drupal root path
$drupal_root = guessDrupalRootPath();
@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;
<?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 / nuxt-js-and-gsheet-example.vue
Last active August 27, 2018 19:00
Nuxt.js vue component to display datas from a google spreadsheet (with google api V4 without oAuth )
<template>
<div id="homepage">
<h1>Les dernières Articles</h1>
<div class="article" v-for="article in articles">
<h2> {{ article.title }} </h2>
<p> {{ article.content }} </p>
</div>
</div>
</template>
@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>