Skip to content

Instantly share code, notes, and snippets.

@daggerhart
daggerhart / get_file_field_uri.php
Created August 16, 2018 03:40
Drupal 8 get file or image field uri. Get default value if field is empty.
<?php
use Drupal\file\Entity\File;
/**
* Get the set or default image uri for a file image field (if either exist)
*
* @link https://drupal.stackexchange.com/questions/194176/loading-default-image-from-a-node-field-in-page-html-twig
*
* @param $entity \Drupal\Core\Entity\ContentEntityBase
* @param $fieldName string
@hansfn
hansfn / composer.bat.patch
Created August 8, 2017 20:55
Patch for fixing 'Could not open input file: composer.phar"' when running composer in Acquia Dev Desktop
--- composer.bat.orig 2017-08-08 22:25:55.769011700 +0200
+++ composer.bat 2017-08-08 22:42:33.878045000 +0200
@@ -1,2 +1,6 @@
-@SET PATH=C:\Development\AcquiaDevDesktop\php5_4;%PATH%
-php.exe composer.phar %*
+@echo off
+
+IF "%PHP_ID%"=="" (SET PHP_ID=php5_5)
+SET PATH=C:\Development\AcquiaDevDesktop\%PHP_ID%;%PATH%
+
@AllieRays
AllieRays / bar.php
Last active November 14, 2021 17:58
Programmatically create multiple taxonomy terms in Drupal 8
<?php
// Programmatically create taxonomy terms for taxonomy module on install.
// This is the bar.install file included in a module.
use Drupal\taxonomy\Entity\Term;
use Symfony\Component\Yaml\Yaml;
function foo_taxonomy_install() {
$vocabularies = [
@mchelen
mchelen / index.php
Last active November 20, 2021 18:01
php check multidimensional array for duplicate values
<?php
$arrays = array(
array(
'name'=>'foo',
),
array(
'name'=>'bar',
),
array(
'name'=>'foo',
@Jaesin
Jaesin / delete_content_entities.d8.php
Created June 22, 2015 07:14
Delete all content entities in Drupal 8.
<?php
// Delete all nodes.
entity_delete_multiple('node', \Drupal::entityQuery('node')->execute());
// Delete all files.
entity_delete_multiple('file', \Drupal::entityQuery('file')->execute());
// Delete all taxonomy terms.
entity_delete_multiple('taxonomy_term', \Drupal::entityQuery('taxonomy_term')->execute());
@massiws
massiws / gist:9593008
Last active August 17, 2022 05:15
PHP Count the number of working days between two dates.
<?php
/**
* Count the number of working days between two dates.
*
* This function calculate the number of working days between two given dates,
* taking account of the Public festivities, Easter and Easter Morning days,
* the day of the Patron Saint (if any) and the working Saturday.
*
* @param string $date1 Start date ('YYYY-MM-DD' format)
@homaily
homaily / gist:8672499
Last active April 15, 2024 05:57
Regex to validate saudi mobile numbers

السلام عليكم ، هذا كود ريجيكس بسيط للتحقق من صحة أرقام الجوالات السعودية ، يقوم الريجيكس بالتحقق من مفتاح الدولة ، مفتاح شركة الإتصالات لضمان صحة النص المدخل .

Hello, this is a simple regex to validate saudi mobile numbers, the code will validate country code, telecome company code and make sure the tested sting is correct .

/^(009665|9665|\+9665|05|5)(5|0|3|6|4|9|1|8|7)([0-9]{7})$/

Regex Breakdown - شرح الكود

@ocean90
ocean90 / box-shadow.html
Last active April 11, 2024 13:54
CSS3 Box Shadow, only top/right/bottom/left and all
<!DOCTYPE html>
<html>
<head>
<title>Box Shadow</title>
<style>
.box {
height: 150px;
width: 300px;
margin: 20px;