Skip to main content

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

 

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>');

 

How to Install Tika to be used for Solr Search API Attachments

Following is a series of steps to install Tika and have it running for your Solr Search API Attachments.

Java is it running on your server

To begin you must have Java installed on your server/machine.  To check if Java is installed use the command

java -version

Performing the above command will output something similar to:

Migration is busy with another operation

The migrate process saves the status of each running migration in the database.  Any error in the code will abnormally terminate the process so the database won't be updated properly and will keep saying that "something is still running".   In Drupal I had a look through the error log and came across the following message:

Adding Solr config zip to your remote server

Adding Solr config zip (ie. solr_8.x_config.zip) to your remote server.  In this instance I'll be adding Solr config to a AWS EC2 server.

 

Log in to your remote server, then as you need to work as root type:

sudo su

Go to your solr directory:

cd /var/solr/

If you don't know the location of your solr directory run:

Formatting how date/time is displayed in Drupal 8/9

You can create a new date/time format by navigating to:

Admin -> Configuration -> Regional and Language -> Date and Time format and click on 'Add Format'.

Once you’ve created date format, you can control the way date is displayed on the node using preprocess function.

In {theme_name}.theme file, add the following lines

How merge a View exposed form with pager?

To assist in finding possible solutions some of the queries that I made include:

  • Drupal 9 pager with items_per_page
  • Drupal 9 pager merged with exposed form items_per_page

 

How do I get a page’s current URL in Twig for Drupal 9

Having access to a site’s URL in your templates can come in handy for many different use cases, such as determining if your on the admin/people page as apposed to admin/reports/dblog or admin/content.  These three pages might seem to bear on common relationship, however there is at least one.  Users.

I edited the user in the admin/people page so rather than showing just username, know shows:

Drupal - how to increase the maximum file upload size?

By default the maximum file upload size is set to 2MB.  It is not a Drupal issue, instead a php issue as upload_max_filesize is set in your php configuration (php.ini file).  Therefore it is a server-side configuration.

Drupal watchdog

Creating a message log using Drupal watchdog.

 

Simple log

// Logs a notice
\Drupal::logger('my_module')->notice($message);
// Logs an error
\Drupal::logger('my_module')->error($message);

 

Adding a layer of complexity to the log

public function submitForm(array &$form, FormStateInterface $form_state) {
    $entity = $this->getEntity();
    $entity->delete();

Subscribe to Drupal 9.x