I noticed that kint() function doesn’t work on a fresh Drupal 8 installation. The solution is to uninstall BigPipe module, that comes preinstalled in the latest version of Drupal. BigPipe is a caching technique that interferes with how kint() works.
Category: Uncategorized
WordPress post remove categories taxonomy
function alter_taxonomy_for_post() { unregister_taxonomy_for_object_type(‘category’, ‘post’); //register_taxonomy_for_object_type(‘custom_tax’, ‘post’);}add_action(‘init’, ‘alter_taxonomy_for_post’);
Adding node-id CSS class in Drupal 8
Let say that we’d like to add a node-id-1 CSS class name to the HTML tag. (Ideally, the front-end should not depend on node ids, however, sometimes it’s the best approach) Add a pre-processor to the theme file. Note that the preprocess function doesn’t know what the current node is, therefore you need to call \Drupal::routeMatch() function… Continue reading Adding node-id CSS class in Drupal 8
GreenSock hover over starter
Hover effects $(“.video”).hover( function () { TweenLite.to($(“.overlay .fa”, this), 0.3, {y: -15, ease: Power2.easeInOut}); }, function () { TweenLite.to($(“.overlay .fa”, this), 0.3, {y: 0, ease: Power2.easeInOut}); } );
WordPress development workflow
WordPress + Bootstrap + Visual Composer For most of the standard websites, I use the following workflow. Generate a WordPress starter theme in Underscores. Upload and activate the theme. Install and activate Visual Composer plugin (I’m slowly adapting the Guttenberg plugin instead). Import Bootstrap to the theme folder. Import Visual Composer fix that integrates the… Continue reading WordPress development workflow
Drupal 8, getting paragraph parent
function hook_suggestions_paragraph_alter(array &$suggestions, array $variables, $hook) { $parent = $variables[‘elements’][‘#paragraph’]->getParentEntity()->bundle(); if($parent){ $paragraph = $variables[‘elements’][‘#paragraph’]; $sanitized_view_mode = strtr($variables[‘elements’][‘#view_mode’], ‘.’, ‘_’); //$suggestions[] = ‘paragraph__’ . $sanitized_view_mode; //$suggestions[] = ‘paragraph__’ . $paragraph->bundle(); //$suggestions[] = ‘paragraph__’ . $paragraph->bundle() . ‘__’ . $sanitized_view_mode; $suggestions[] = ‘paragraph__’ . $paragraph->bundle() . ‘__’ . $sanitized_view_mode . ‘__parent_’ . $parent; }}
Custom plyr.io icons
In this example I’m developing a simple play/pause button using svg sprite technique. const rt = Plyr.setup(‘.audio’, { debug: true, controls: [ ‘play’ ], iconUrl: ‘path/sprite.svg’, iconPrefix: ‘audio’}); The sprite is an svg file that includes an svg icons for play and pause. You need to add the ids to the layers. It’s required by… Continue reading Custom plyr.io icons
Drupal 8 display webform programmatically
$view_builder = \Drupal::entityTypeManager()->getViewBuilder(‘webform’); $storage = \Drupal::entityTypeManager()->getStorage(‘webform’); $node = $storage->load(‘contact’); $build = $view_builder->view($node); $output = render($build);
Drupal 8 get paragraph parent
$variables[‘elements’][‘field_ra’][‘#object’]->get(‘parent_field_name’)->getString(); You can then use it as in a theme suggestion. This will allow you to override paragraphs located in other paragraphs (or other fields) paragraph–ra–field-r.html function xxx_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) { if(isset($variables[‘elements’][‘field_ra’])){ $suggestions[] = ‘paragraph__ra__’ . $variables[‘elements’][‘field_ra’][‘#object’]->get(‘parent_field_name’)->getString(); } }
Displaying view programmatically in Drupal 8
//display four related news and events view – send contextual filter $view = \Drupal\views\Views::getView(‘news_and_events’); $variables[‘frne’] = $view->buildRenderable(‘frne’);