Skip to content

Instantly share code, notes, and snippets.

View gormus's full-sized avatar
💭
Never be cruel, never be cowardly.

Osman Gormus gormus

💭
Never be cruel, never be cowardly.
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/css/normalize.min.css" rel="stylesheet" type="text/css" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/css/foundation.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/vendor/modernizr.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/vendor/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/foundation.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
@gormus
gormus / digging-drupal-8-code-snippets-site-builders.html
Last active July 10, 2016 06:31
Digging In To Drupal 8: Code Snippets for Site Builders. (shamelessly copied from https://chromatichq.com/blog/digging-drupal-8-code-snippets-site-builders)
<p>The more I work with Drupal 8, the more I realize how much has changed for developers in the Drupal community. While the transition to a modern, object-oriented system is what's best for the longevity of the platform, it certainly doesn't come without challenges. As someone who doesn't come from an OOP background, I've found the transition difficult at times. In many cases, I know exactly <em>what</em> I want to do, just not <em>how</em> to do it the "Drupal 8 way". On top of this, tutorials and blog posts on D8 are all over the map in terms of accuracy. Many posts written during D8's development cycle are no longer applicable because of API changes, etc.</p>
<p>Below is a list of snippets that might be helpful to site builders or developers more familiar with D7 hooks and procedural. It might also be useful to OOP folks who are new to Drupal in general. My goal below is to add to and update these snippets over time.</p>
<h2>Routes &amp; Links</h2>
<h3>Determine the Current Drupal Route</h3>
<p>Need to
@gormus
gormus / theming-hell.php
Created July 6, 2016 21:50 — forked from jacine/theming-hell.php
Give me my HTML in my Drupal 8 menu links!
<?php
/**
* Implements hook_preprocess_menu().
*/
function THEME_preprocess_menu(&$vars, $hook) {
if ($hook == 'menu__account') {
$items = $vars['items'];
foreach ($items as $key => $item) {
if ($key == 'user.page') {
@gormus
gormus / .theme.php
Created July 6, 2016 18:46 — forked from jacine/.theme.php
HTML in menu items D8
<?php
/**
* Implements hook_preprocess_menu().
*/
function THEME_preprocess_menu(&$vars, $hook) {
if ($hook == 'menu__main') {
$items = $vars['items'];
foreach ($items as $key => $item) {
$original_title = $vars['items'][$key]['title'];
@gormus
gormus / template.php
Created June 22, 2016 20:41
Improve taxonomy term add/edit form in Drupal 7.x
<?php
/**
* Implements hook_form_FORM_ID_alter().
*/
function abc_form_taxonomy_form_term_alter(&$form, &$form_state) {
// Move all fieldsets into vertical-tabs.
$form['additional_settings'] = array(
'#type' => 'vertical_tabs',
);
@gormus
gormus / unset_by_value.php
Created June 16, 2016 03:33
Unset an item from an array by its value.
<?php
/**
* Unset an item from an array by its value.
*/
function unset_byvalue(array $array = array(), $value = '') {
$index = array_search($value, $array, TRUE);
if ($index !== FALSE) {
unset($array[$index]);
}
@gormus
gormus / controller.php
Created April 23, 2016 04:40 — forked from tscheepers/GeoSpatialThingController.php
Geospatial sort by distance using Laravel 4 and MySQL. I'm using a point column named geolocation in a table called meetings.
<?php
class MeetingsController extends \BaseController {
/**
* Display a listing of the resource.
* GET /meetings
*
* @return Response
*/
@gormus
gormus / Change Drupal installation profile.md
Created February 9, 2016 20:38
Change Drupal installation profile
$ drush vset install_profile standard

$ drush rr
$ drush cc all

$ drush sqlq "DELETE FROM `system` WHERE filename LIKE 'profiles/pantheon/pantheon.profile'"
$ drush sqlq "UPDATE `system` SET status=1 WHERE filename LIKE 'profiles/standard/standard.profile'"
@gormus
gormus / Gruntfile.js
Created January 16, 2016 03:11 — forked from matt-bailey/Gruntfile.js
This is the example Gruntfile that goes with my tutorial on front-end flat builds and automation: http://www.gpmd.co.uk/blog/front-end-process-flat-builds-and-automation-part-3-grunt-tasks/
// Generated on 2013-06-04 using generator-webapp 0.1.7
'use strict';
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
@gormus
gormus / guid.php
Created December 28, 2015 20:58
Create a GUID.
<?php
$guid = getGUID(array('{','}'));
print $guid;
function getGUID($strip = array()) {
$guid = '';
if (function_exists('com_create_guid')) {
$guid = com_create_guid();