drupal 8

Use only parent terms in view

If you want to display the top-level terms of a given vocabulary, create a "term" view ("View type: Term") with these basic settings: a field for "Taxonomy:Term", an argument for "Taxonomy: Vocabulary ID"

Then to filter:
1) add a relationship to "Taxonomy: Parent term"
2) add a filter on "Taxonomy: Term ID", using relationship "Parent", with operator set to "Is empty (NULL)"

This will list only top-level terms for the given vocabulary.

Notice: Undefined variable: pages_prefix in template_preprocess_quicktabs_view_quicktabs() (line 83 of modules/contrib/quicktabs/quicktabs.theme.inc).

diff --git a/quicktabs.theme.inc b/quicktabs.theme.inc
index d4e86cf..284f05f 100644
--- a/quicktabs.theme.inc
+++ b/quicktabs.theme.inc
@@ -79,6 +79,4 @@ function template_preprocess_quicktabs_view_quicktabs(&$variables) {
$variables['rows_with_page_starts'] = $rows_with_page_starts;
$variables['rows_with_page_endings'] = $rows_with_page_endings;
- $variables['pages_prefix'] = $pages_prefix;

Twig values

URL in link field
{{ node.field_my_link.0.url }}

{{ entity.field_name.value }} to get the true raw value, includes tags and encoding.

Example: {{ node.body.value }}
result: Batman & Robin
{{ content.field_name.0 }} to get the raw value minus tags and encoding.

Example: {{ content.body.0 }}
result: Batman & Robin

Term ID
{{ node.field_category.entity.tid.value }}

Drupal 8 – Formatting a Date Field in Twig

Here are the four easiest ways I’ve found to show dates via Twig inside of a node template.

They all result in the same output.

Use the field’s formatter settings; include wrappers

{{ content.field_blog_date }}
{{ content.field_blog_date }}
This is the only example that includes wrappers. The rest output just the date.

Use the field’s formatter settings

{{ content.field_blog_date.0 }}
{{ content.field_blog_date.0 }}
This will use the format defined in Content type » Manage Displays » Your View Mode.

Patch for fieldset views empty handler error

diff --git a/views_fieldsets.module b/views_fieldsets.module
index af518a6..8cfe495 100644
--- a/views_fieldsets.module
+++ b/views_fieldsets.module
@@ -65,6 +65,8 @@ function views_fieldsets_preprocess_views_view_fields(&$vars) {
function views_fieldsets_views_ui_display_tab_alter(&$build, ViewUI $ui_view, $display_id) {
$view = $ui_view->getExecutable();
+ // Re-init handlers.
+ $view->inited = FALSE;
$ui_view->set('executable', $view);

redirect https and without www

Enabling HTTP Secure (HTTPS)
Last updated 4 August 2018. Created on 11 November 2009.
Edited by John Morahan, hiten2112, marcoka, Joel MMCC. Log in to edit this page.

HTTPS is a protocol which encrypts HTTP requests and their responses. This ensures that if someone were able to compromise the network between your computer and the server you are requesting from, they would not be able to listen in or tamper with the communications.

Overcoming memory issues installing Drupal with Composer

Tue, 27/03/2018 - 16:34 -- James Oakley

Drupal 8 uses Composer for package management. You can still install a Drupal 8 site by downloading a tarball, but we're all encouraged to use Composer to download Drupal core and other dependencies and to keep things up to date.

I'm just starting to get my head around how Drupal 8 works, so that I can reach the point where I can build new sites in 8.x rather than 7.x, and in time migrate existing sites over. Composer is part of the learning curve for this.

Download Composer to Mac OSX

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Increase CLI php memory limit on OSX

published by Albert Skibinski on Sat, 2015-02-21 13:52
When running MAMP or MAMP Pro on a Mac OSX (this is on version 10 Yosemite) you will notice that PHP executed from the command line (CLI) will use different PHP settings than your website. In this case, OSX is using its own built-in apache server and php settings, not the ones defined by your MAMP setup.

You can easily change this though, as long as you know which php.ini to change.

First, check your memory limit, by running the following command on your SSH shell or local terminal:

Drupal 8 update

# Browse to https://github.com/drush-ops/drush/releases and download the drush.phar attached to the latest 8.x release.

# Test your install.
php drush.phar core-status

# Rename to `drush` instead of `php drush.phar`. Destination can be anywhere on $PATH.
chmod +x drush.phar
sudo mv drush.phar /usr/local/bin/drush

# Optional. Enrich the bash startup file with completion and aliases.
drush init


Views D8 suggestions

Describes various views templates & overriding options.

All views templates can be overridden with a variety of names, using the view, the display ID of the view, the display type of the view, or some combination thereof.

For each view, there will be a minimum of two templates used. The first is used for all views: views-view.html.twig.

D8 How do I add a node ID as class to the <body> tag?

down vote
In mytheme.theme file: add the below code.

function mytheme_preprocess_html(&$variables) {
// Add node id to the body class.
$node = \Drupal::routeMatch()->getParameter('node');
if($node) {
$variables['attributes']['class'][] = 'node-' . $node->id();
This will add "node-{{nid}}" class in body tag.

Theme suggestion for D8 blocks

* Implements hook_theme_suggestions_HOOK_alter() for form templates.
* @param array $suggestions
* @param array $variables
function THEMENAME_theme_suggestions_block_alter(array &$suggestions, array $variables) {
// Block suggestions for custom block bundles.
if (isset($variables['elements']['content']['#block_content'])) {
array_splice($suggestions, 1, 0, 'block__bundle__' . $variables['elements']['content']['#block_content']->bundle());