All posts by Vasyl Zhuk

A fix for Drupal 8’s broken preview

Drupal 8 is still beta-ish in so many aspects, that “workarounds” is becoming a separate genre of Drupal development tips and tricks. 

The today’s workaround is for the bug in “node preview” functionality. It is not frequently used, but can be rather convenient for large websites with moderation enabled. The bug can be spotted only when CSS styles, applied to the  node/page template rely on the  <body> CSS classes,  namely the core-added  page-node-type-[node bundle] body class. It helps to effectively distinguish different node templates, and therefore are widely relied on by front-end developers. However, in preview mode, this class appears entirely missing, which breaks the styling.

Continue reading

Drupal 8 Migration: Field Updates

By default, the migrate module in Drupal 8 updates existing nodes by completely overwriting all the fields in the target node with the data from the migration. But what if your client has modified content on the target (D8) system, and still wants to update the content with newly-mapped fields? For instance, there is a “description” that has been updated after the first migration, but now the client wants “subtitle” field to be migrated (which was empty or not present during the first pass), without overwriting the description field changes. Continue reading

Drupal 8 migration: taxonomy term lookups

By resorting to YAML files for configuration, Drupal 8 achieved a huge boost in flexibility and understandability of the parameters. Even more it is useful for such a “commonly uncommon” task as migration.

Indeed, in D7 you had a set of forms to match source to destination, using some limited set of processing options. Now, in D8, these three stages of migration are totally separated out, unleashing a (nearly) unlimited power of building processing pipes and referencing other migrations. Continue reading

Drupal 8: Views scrollTop behavior

Drupal 8 logoIt’s a weird piece of Drupal 8 out-of-the-box behavior: each time after you AJAX-load a views block with exposed filter, you are scrolled to the top of the block! It’s especially tiresome for mobile device users… Is there a way that we can fix it??

Removing this behavior entirely is a massive improvement. Here is a recipe to circumvent the issue for Drupal 7 – but it won’t work for Drupal 8! But search no more. Here for you is the exact solution:

Continue reading

Non-zero length redirects in Drupal

Drupal logoThose of you hosting Drupal sites on Acquia might come across this issue: enabling compressed cached pages leads to Varnish errors instead of redirects. As explained by Acquia support, this happens because Varnish tries to unzip zero-length response – and, naturally, then fails. Your options for solutions are to purchase a dedicated balancer configuration – or make the response non-zero (for instance, add the “Redirecting…” text into the body).

Continue reading

ANN in Python, JavaScript & PHP

Neural networks graphicNowadays you see artificial intelligence (AI) everywhere. It suggests search terms in search fields, recognizes faces on photos, targets ads, and even gives “personality” to your smartphone/tablet.

One of the most common types of AI is the artificial neural network (ANN). As long as full-fledged neural devices with computing parallelism are not yet commonly accessible, building one on conventional computer architectures is fairly easy. Due to the resource-heavy training algorithms required by the most ANN structures, including the popular Feed-Forward Back Propagation NN (FFBP), it is better to build core ANN functionalities in low-level languages. However, there are a few options for using scripting languages. This is a short survey for my favourite scripting languages: Python, JavaScript, and PHP.

Continue reading

Truncating text responsively

Truncated text is a pain...Are you trying to truncate text according to the space available? This is something you just cannot do in the back-end. That’s the truth – unless you are really crazy and have plenty of spare time. But even approaching text truncation in the front-end is not something achievable by writing a couple of simple CSS lines. In my opinion, one of the best approaches out there is the one offered by Andres Descalzo in this discussion over at StackOverflow. I took his method and modified it to match the needs of a responsively designed site. Here’s how it’s done…

Continue reading

Keeping your blocks straight

Drupal TipsDrupal 7 projects utilizing Contexts for placing blocks tend to grow quickly and have many, many different contexts – it can get really confusing! Utilizing a smart naming convention (like Phase 2’s) is an absolute must. But if you’re on a project with several developers, even a coherently, clearly named context structure can still cause headaches; you might still have to search and open up contexts one-by-one in order to locate a specific block.

For those of you using the Devel module, here’s a great way to increase efficiency and speed things up! Just use the following code snippet:

You can place this snippet anywhere in your code or go to to run it from there. In fact, you can use this snippet to search for all sorts of reactions – just modify the filtering options!

Storing sessions with Drupal

Drupal logoWhen developing a Web app with PHP, especially when using a framework or a CMS, most often you just don’t care about sessions. Less frequently, you store and access some information from a session, accessing it via language constructs (like “singleton” object (e.g. ZendSession  in Zend framework), some special wrapper functions or just $_SESSION  global). More often, though, you don’t bother monitoring how and where sessions are stored. But sometimes you should.

The basic purpose of this post is to talk about how, when developing a high-load website, to allow users to log on and access some personalized information. When you have hundreds of thousands hits per day, you should expect that tens of thousands users will log in to their respective accounts. That’s when you need to start caring about session storage. Continue reading