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
@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 / 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 / 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
<!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 / example.services.yml
Created September 22, 2016 17:54
Drupal 8 - Change the core's default path for `/contact` so that we can use it as an alias.
services:
example.route_subscriber:
class: Drupal\example\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
@gormus
gormus / drupal_redirect_for_files_dir.conf
Created October 12, 2016 16:47
Redirects your local environment's Drupal install /sites/*/files/* requests to a server that actually has them. This helps avoid having to sync (sometimes, very large) file structures onto your local machine and taking up valuable hard-drive space. Source: http://dropbucket.org/node/337
### Apache Rewrite
<IfModule mod_rewrite.c>
RewriteEngine on
# Force image styles that have local files that exist to be generated.
RewriteCond %{REQUEST_URI} ^/sites/([^\/]*)/files/styles/[^\/]*/public/((.*))$
RewriteCond %{DOCUMENT_ROOT}/sites/%1/files/%2 -f
RewriteRule ^(.*)$ $1 [QSA,L]
# Otherwise, send anything else that's in the files directory to the
# production server.
RewriteCond %{REQUEST_URI} ^/sites/[^\/]*/files/.*$
@gormus
gormus / MYMODULE.module
Created October 20, 2016 05:40
Improve user experience with Paragraphs on Drupal 8 - Modify the label of paragraph components - source: http://flocondetoile.fr/blog/improve-user-experience-paragraphs-drupal-8
<?php
/**
* Implements hook_form_alter().
*/
function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_object = $form_state->getFormObject();
// Paragraphs are only set on ContentEntityForm object.
if (!$form_object instanceof ContentEntityForm) {
@gormus
gormus / fuzzy-search.sql
Created December 17, 2016 04:34 — forked from lsauer/fuzzy-search.sql
FullText fuzzy searching in SQL / MySQL
#lo sauer, 2013 - www.lsauer.com
#see: http://www.lsauer.com/2013/05/mysql-fuzzy-searching-fulltext-queries.html
#Note: In MySQL SUBSTRING, the string-index starts at position 1
SELECT * FROM tablename
WHERE SOUNDEX(tablename_field)
LIKE CONCAT('%',SUBSTRING(SOUNDEX('Fuzti serch derm'),2),'%');
<?php
class DrupalHubFlagLike extends \RestfulEntityBase {
/**
* {@inheritdoc}
*/
public function publicFieldsInfo() {
$public_fields = parent::publicFieldsInfo();
@gormus
gormus / index.html
Created April 14, 2017 19:56 — forked from seancdavis/index.html
Full-Size, Looping Background Video with YouTube Video
<style>
.bg-video {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
z-index: -1;
}