Skip to content

Instantly share code, notes, and snippets.

View nicaralava's full-sized avatar

Jean Nica Ralava nicaralava

View GitHub Profile
@nicaralava
nicaralava / highlight.html
Created February 4, 2023 18:33
Use highlight.js
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/monokai.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
</head>
<body>
<pre>
<?php
/**
*
*/
function imageCreateFromUrl($url) {
// Ex Remote image URL.
$url = 'https://www.mon-site.com/sites/default/files/logo_upload/logo.png';
// Image path.
$remote_image_directory = 'https://www.mon-site.com/sites/default/files/logo_upload/';
@nicaralava
nicaralava / part-of-alias.php
Created October 3, 2020 22:02
Drupal 8 - Get All Nodes With a Part of Url Alias
<?php
$input = '/carousel-';
$node_query_result = [];
$path_query = \Drupal::database()->select('path_alias', 'a');
$path_query->addField('a', 'path');
$path_query->condition('a.alias', '%' . $input . '%', 'LIKE');
$path_query_result = str_replace('/node/', '', $path_query->execute()->fetchCol());
if ($path_query_result) {
$node_query = \Drupal::database()->select('node_field_data', 'n');
$node_query->addField('n', 'nid');
@nicaralava
nicaralava / display-menu-drupal.php
Last active October 3, 2020 12:43
Displaying sub menu tree in Drupal 8
<?php
// For mor information: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Menu%21MenuLinkBase.php/class/MenuLinkBase/8.9.x
$tree = \Drupal::menuTree()->load('main', new \Drupal\Core\Menu\MenuTreeParameters());
function loadMenu($tree) {
$menu = [];
foreach ($tree as $item) {
if($item->link->isEnabled()) {
$menu[] = [
'weight' => $item->link->getWeight(),
@nicaralava
nicaralava / drupal-states.php
Created March 19, 2020 18:17
Drupal states Field Conditional State
<?php
public function buildForm(array $form, FormStateInterface $form_state) {
$form['valider'] = [
'#type' => 'checkbox',
'#title' => 'valider',
];
$form['Text'] = [
'#type' => 'textfield',
'#default_value' => 'Rechercher',
'#states' => [
@nicaralava
nicaralava / drupal-states.php
Created March 19, 2020 18:16
Drupal states Field Conditional State
<?php
public function buildForm(array $form, FormStateInterface $form_state) {
$form['valider'] = [
'#type' => 'checkbox',
'#title' => 'valider',
];
$form['Text'] = [
'#type' => 'textfield',
'#default_value' => 'Rechercher',
'#states' => [
@nicaralava
nicaralava / send-mail.php
Created January 7, 2020 17:52
Send mail php
<?php
$to = "ralava@andrana.nn";
$subject = "Télétravail";
$message='Bonjour,<br>Je suis en télétravail aujourd\'hui le '.date("d/m/Y").'<br><br>Très Sincèrement,<br><br>Jean Nica';
$headers = [
'MIME-Version: 1.0',
'Content-Type: text/html; charset=UTF-8',
'From: moiralava@andrana.nn',
'Cc: izy@andrana.nn, izy2@andrana.nn',
];
@nicaralava
nicaralava / getAltitudeByAddress.html
Created June 28, 2019 15:56
get Altitude By Address
<!DOCTYPE html>
<html>
<head>
<title>Geocoding Service</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
@nicaralava
nicaralava / autocomplete.css
Last active May 7, 2019 11:56
Removing input background color for Chrome autocomplete
@-webkit-keyframes autofill {
to {
color: #000;
background: transparent;
}
}
input:-webkit-autofill {
-webkit-animation-name: autofill;
-webkit-animation-fill-mode: both;
}
@nicaralava
nicaralava / dateToFrench.php
Created April 25, 2019 13:03
Date to french
<?php
public static function dateToFrench($date, $format)
{
$english_days = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
$french_days = array('Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche');
$english_months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$french_months = array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
return str_replace($english_months, $french_months, str_replace($english_days, $french_days, date($format, strtotime($date) ) ) );
}