Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Implements hook_views_query_alter().
*/
function ramsalt_shy_replacement_views_query_alter(&$view, &$query) {
if ($view->name === 'frontpage_admin') {
foreach ($query->where[1]['conditions'] as $delta => $condition) {
if ($condition['field'] === 'node.title') {
$query->add_where_expression(1, "REPLACE(node.title, '=', '') " . $condition['operator'] . " '" . $condition['value'] . "'");
@szeidler
szeidler / boost-recent-content-with-searchapi-solr.php
Created January 26, 2017 09:02
Add a boost function, to prioritize recent content in Search API Solr queries. More recent articles will get boosted heavily, older ones less and less.
<?php
/**
* Boost published_at field to prioritize newer content.
*
* @see https://wiki.apache.org/solr/SolrRelevancyFAQ#How_can_I_boost_the_score_of_newer_documents
* Implements hook_search_api_solr_query_alter().
*/
function my_module_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query) {
// Boost more recently created articles. Boost the field with score +8 shrinking during 365 days.
@szeidler
szeidler / drush-config-export-skip-development.sh
Created December 30, 2016 22:56
Drupal 8 CMI exclude development modules
drush config-export --skip-modules=devel,kint,stage_file_proxy
@szeidler
szeidler / nginx-drupal7-xml.conf
Created December 2, 2016 10:29 — forked from pprishchepa/nginx-drupal7-xml.conf
Docker4Drupal Nginx + XML
server {
server_name SERVER_NAME;
listen 80;
root /var/www/html/;
index index.php;
fastcgi_keep_conn on;
fastcgi_index index.php;
fastcgi_param QUERY_STRING $query_string;
@szeidler
szeidler / Gruntfile.js
Last active February 23, 2017 10:23
Grunt files for Drupal theming (including clever drush cache clearing)
/**
* Grunt file for Drupal theming, including clever drush cache clearing.
*
* Usage in docker4drupal environment: `grunt --docker`
* It ensures, that drush is executed from the php container.
*/
module.exports = function (grunt) {
var drush_path = 'drush';
@szeidler
szeidler / drush-alias-sql-migration.sh
Created October 28, 2016 20:01
Drush Alias SQL migration
drush @live.example.org sql-dump --gzip|zcat|drush sql-cli
@szeidler
szeidler / inline_entity_form-n1960686-36.patch
Created July 22, 2016 10:48
Add multi_edit support to inline_entity_form
diff --git a/includes/commerce_product.inline_entity_form.inc b/includes/commerce_product.inline_entity_form.inc
index 5dcb6f2..62da0b6 100644
--- a/includes/commerce_product.inline_entity_form.inc
+++ b/includes/commerce_product.inline_entity_form.inc
@@ -160,7 +160,7 @@ class CommerceProductInlineEntityFormController extends EntityInlineEntityFormCo
);
$entity_form['product_details'] = array(
'#type' => 'fieldset',
- '#title' => t('Details'),
+ '#title' => $this->getSetting('multi_edit') ? $product->title . ' (' . $product->sku . ')' : t('Details'),
@szeidler
szeidler / workaround_missing_vendor_libraries_d8_aegir_migration.sh
Last active April 21, 2016 10:45
Workaround for missing vendor libraries, when migrating D8 sites with aegir
#!/bin/bash
## Aegir has major problems while migrating sites, when the new platform doesn't have the vendor libraries available.
## Here is a workaround for solving that problem.
## Copy the working site into the new platform.
## That needs to be done, to let composer_manager know about all the site package requirements
cp -r /var/aegir/platforms/old_platform/sites/site.name.org /var/aegir/platforms/new_platform/sites/site.name.org.migration
cd /var/aegir/platforms/new_platform
## Initialize composer_manager if not already done
#!/bin/bash
drush sql-dump --gzip --result-file=backup-xxxx.sql.gz --structure-tables-list=cache,cache_*,cache_filter,cache_form,cache_menu,cache_page,history,sessions,watchdog
@szeidler
szeidler / d8-responsive-image-programmatically.php
Created March 15, 2016 08:42
Load and render responsive image from field in Drupal 8
<?php
function _load_header_image($variables) {
if ($node = $variables['node']) {
// Load main_image
$file = $node->field_main_image->entity;
if ($file) {
$variables = array(
'responsive_image_style_id' => 'header_image',
'uri' => $file->getFileUri(),