Skip to content

Instantly share code, notes, and snippets.

View test.js
const myTest = (string) => {console.log(string)};
View popolo_custom.css
/**
* Hide <select> and submit-button
*/
#views-exposed-form-filter-articles-page-1 .form-type-select {
display: none;
}
#views-exposed-form-filter-articles-page-1 .form-submit {
display: none;
}
View popolo_custom.js
(function ($) {
/**
* Set active class on Views AJAX filter
* on selected category
*/
Drupal.behaviors.exposedfilter_buttons = {
attach: function(context, settings) {
$('.filter-tab a').on('click', function(e) {
e.preventDefault();
View popolo_custom.libraries.yml
popolo_custom.forms:
version: VERSION
css:
theme:
css/popolo_custom.theme.css: {}
popolo_custom.enable:
version: VERSION
js:
js/popolo_custom.js: {}
View popolo_custom.module.php
<?php
function popolo_custom_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
/**
* Apply the form_alter to a specific form #id
* the form #id can be found through inspecting the markup
*/
if($form['#id'] == 'views-exposed-form-filter-articles-page-1') {
/**
View popolo_custom.info.yml
name: Popolo Custom
type: module
description: 'Example module for Drupal 8.'
package: Custom
version: 8.x
core: 8.x
@leanderlindahl
leanderlindahl / gist:8be5f9947e85c7e00acb
Created Sep 3, 2015
Wordpress Responsive YouTube embed
View gist:8be5f9947e85c7e00acb
In your themes functions.php:
add_filter( 'embed_oembed_html', 'custom_oembed_filter', 10, 4 ) ;
function custom_oembed_filter($html, $url, $attr, $post_ID) {
$return = '<div class="video-container">'.$html.'</div>';
return $return;
}
In your themes css:
.video-container {
View exposedfilter_buttons.js
(function ($) {
/**
* Set active class on Views AJAX filter
* on selected category
*/
Drupal.behaviors.exposedfilter_buttons = {
attach: function(context, settings) {
$('.filter-tab a').on('click', function(e) {
e.preventDefault();
View exposedfilter_buttons.module
<?php
function exposedfilter_buttons_form_alter(&$form, &$form_state, $form_id) {
/**
* Manipulate output of Views Ajax Exposed filter
*/
if ($form['#id'] == 'views-exposed-form-exposed-filter-example-block') {
$form['#attached']['js'] = array(
drupal_get_path('module', 'exposedfilter_buttons') . '/js/exposedfilter_buttons.js',
);