Skip to content

Instantly share code, notes, and snippets.

Avatar

NikLP NikLP

View GitHub Profile
View Make views exposed filters display inline inc. apply button ~ Drupal 8, Views
.view-VIEWNAME .form--inline .form-item {
display: inline;
float: none;
}
.view-VIEWNAME .form--inline .form-actions {
display: inline-block;
}
@NikLP
NikLP / gist:aea66764f7a5173d83bab9338640754d
Last active May 14, 2018
Reposition dropbutton (multiple) on views table, remove spurious(?) padding/margin - CSS, Drupal 8
View gist:aea66764f7a5173d83bab9338640754d
.view-VIEWNAME td .dropbutton-multiple {
display: flex;
justify-content: center;
align-items: center;
padding: 0 !important;
margin: 0 !important;
}
@NikLP
NikLP / theme.theme
Created May 5, 2017
Sacrilegious's way to get forms in templates for D8
View theme.theme
/**
* Provides suggestions for different parts, so that blocks are properly loaded
*
* @see hook_theme_suggestions_alter()
*
* @param array $suggestions
* @param array $variables
* @param string $hook
*/
@NikLP
NikLP / paragraph--PARA-NAME.html.twig
Last active Apr 3, 2017
Drop-in paragraph template to display fields as bootstrap accordian
View paragraph--PARA-NAME.html.twig
{% extends "paragraph.html.twig" %}
{% block paragraph %}
<div{{ attributes.addClass('panel-group') }} id="accordion-{{ paragraph.id() }}" role="tablist">
{% for field in content %}
{% set field_instance_items = [] %}
{% for key, field_instance in field if key|first != '#' %}
{% set field_instance_items = field_instance_items|merge([field_instance]) %}
{% endfor %}
{% if field_instance_items is not empty %}
View Block templates by bundle name
/**
* Implements hook_theme_suggestions_HOOK_alter().
* Courtesy @nicrodgers
*/
function MYTHEME_theme_suggestions_block_alter(array &$suggestions, array $variables) {
if (isset($variables['elements']['content']['#block_content'])) {
$block_content = $variables['elements']['content']['#block_content'];
$suggestions[] = 'block__' . $block_content->bundle();
}
@NikLP
NikLP / paragraph--field.html.twig
Created Mar 24, 2017
Paragraph field extraction
View paragraph--field.html.twig
// paragraph text field actual text
{{ paragraph.field_title.value }}
// paragraph link field uri - internal:/ style (useless?)
{{ paragraph.field_link.0.uri }}
// content has this value - is processed, not validated (good in some cases)
{{ content.field_link[0]['#url'] }}
// paragraph image field uri
@NikLP
NikLP / zebra.html.twig
Last active Jul 14, 2019
Set zebra-style (odd/even) classes in twig loop in drupal 8 (bootstrap) theme
View zebra.html.twig
<div{{ attributes.addClass('container') }}>
{% for item in items %}
{# NB! notation: loop.index is 1 start, loop.index0 is zero start #}
<div class="row {{ loop.index0 is odd ? 'zebra-odd' : 'zebra-even' }}">
<div{{ item.attributes }}>{{ item.content }}</div>
</div>
{% endfor %}
</div>
@NikLP
NikLP / menu--yourmenu.html.twig
Last active Feb 24, 2017
Item links of a single Drupal menu, in adjacent columns, using Bootstrap.
View menu--yourmenu.html.twig
{# for a generic answer to this problem, see:
http://stackoverflow.com/questions/19836567/bootstrap-3-multi-column-within-a-single-ul-not-floating-properly
Note that this example has been tailored to a single level menu of plain links; modify a copy of the core
menu.html.twig with the changes below to keep your menu as per core.
#}
{{ menus.menu_links(items, attributes, 0) }}
{% if items %}
{%
set menu_classes = [
'list-unstyled row',
View .htaccess for www + https
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@NikLP
NikLP / gist:4a2b3aa5359017359b29
Created Oct 22, 2015
Profile2 "profile page" title set using entity_metadata_wrapper in hook_entity_view
View gist:4a2b3aa5359017359b29
/*
* Implementation of hook_entity_view
*/
function helpermodule_entity_view($entity, $type, $view_mode, $langcode) {
// we're viewing an entity
// check if it's a profile2 type
// - if there's more than one profile2, check for that too!
// - and the view mode is 'page' (not 'full', for profile2 it seems)
if ($type == 'profile2' && $entity->type == 'member' && $view_mode == 'page') {
You can’t perform that action at this time.