Skip to main content

Install / uninstall modules and themes using composer


Using Composer to Manage Projects and if required their dependencies

In this section, we're going to dive into how to use Composer to manage project dependencies. Specifically, we'll cover the following:

Using Wireshark to sniff network packets

I’m recently doing an IoT project. I wanted to investigate the network layer, and to do so I use Wireshark to capture the network traffic between my iOS apps and IoT hardware.

Let’s see how to start packet sniffing using Wireshark!

 

How do I generate URL by term_id (tid) or node_id (nid)

When you have an entity ID value such as node ID (nid) or taxonomy term ID, how can you create the alias in a twig file?  In other words, instead of /taxonomy/term/{tid} I would like to get the alias I have defined for this, eg: /some/path/to/my/term.

In trying to find an answer you might have queried your search criteria using something like

twig canonical taxonomy path

twig canonical entity path

twig canonical node path

 

How to check if a field exists in Drupal entity and not using PropertyExists

I had a couple of instances where I needed to check if an object field existed.  Initially I used propertyExists. However, when running Solr, it tripped on this command.  So some other function was required.  And in steps hasField().  It is a good idea to validate the existence before using it to avoid any unexpected error.

 

Code:

$entity->hasField('fieldName');

 

Drupal logging arrays with logger

In drupal 9 for logging you can use logger service to log array data in some readable format, by adding html code and print_r to array.

\Drupal::logger('my_module')->warning('<pre><code>' . print_r($responseObj, TRUE) . '</code></pre>');

 

Nginx: 413 – Request Entity Too Large Error and Solution

Working in Drupal 9.x, I was loading images via the Media module.  Below 1 mb no issue.  Any thing over - nothing.  Nothing as in no response when loading.

An interesting situation, as I had already changed the php.ini file where the following updates occured:

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 2M

Had changed to 

Percentage encoding

You would have come across a URL string that appears as

https://example.com/project-search?search_api_fulltext=&f%5B0%5D=species%3AAtlantic%20Salmon

As you would already seen %20 many times, that is a space.  Commonly seen in file names either documents or images.

However, what about the others.  Off the top do you know what %3D is?  Maybe, but I didn't.  Below is a quick guide to percentage encoding table:

How to switch users in Ubuntu and other Linux

It is really simple to switch users in Ubuntu or any other Linux distribution using the terminal, iTerm2 or your go to shell program.

All you need to do is to know the username and its account password and you can switch users with su command:

su another_username

You’ll be asked to enter the password of the user you want to switch to.

 

Install iTerm2 and integrate zsh

 

Z shell (Zsh) is a Unix shell built on top of bash (the default shell for macOS) with a large number of improvements.

In this article, I'll run through how to configure iTerm2 with ZSH and its dependencies.

 

Step 1: Install Homebrew

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS.

How to create a date range widget?

Steps to get the Solr date range widget working.

 

Steps

Enable the Facets Range Widget sub-module.

Install the jQuery-ui-Slider-Pips library, as described in the README.txt file in that sub-module's folder.  After playing with this for sometime to get it working, I found the best way to install is via composer.

Subscribe to