This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 & Links</h2> | |
<h3>Determine the Current Drupal Route</h3> | |
<p>Need to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
example.route_subscriber: | |
class: Drupal\example\Routing\RouteSubscriber | |
tags: | |
- { name: event_subscriber } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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/.*$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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),'%'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DrupalHubFlagLike extends \RestfulEntityBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function publicFieldsInfo() { | |
$public_fields = parent::publicFieldsInfo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
.bg-video { | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100vw; | |
height: 100vh; | |
overflow: hidden; | |
z-index: -1; | |
} |