Drupal Planet https://purushotam.in/ en Accessing Translated Entity in Views Twig | Drupal 8 https://purushotam.in/notes/accessing-translated-entity-views-twig-drupal-8 <span property="schema:name">Accessing Translated Entity in Views Twig | Drupal 8</span> <span rel="schema:author"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">purushotam</span></span> <span property="schema:dateCreated" content="2021-07-12T23:49:18+00:00">Tue, 07/13/2021 - 01:49</span> <div property="schema:text" class="text-content field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Though ideally if we use the views correctly and override them well, Drupal Views itself take care of getting the translated version as per configurations of the view. For details check this: <a href="https://api.drupal.org/api/drupal/core%21modules%21views%21src%21Plugin%21views%21field%21EntityField.php/function/EntityField%3A%3AgetValue/8.8.x">EntityField::getValue</a></p> <p>But if somehow we wanna get translated version of the entity in a views twig, we will have to get the current language and then call <a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21ContentEntityBase.php/function/ContentEntityBase%3A%3AgetTranslation/8.8.x">ContentEntityBase::getTranslation</a> on the entity of the views row. And there are various ways of getting the current language in the views-view.html.twig:</p> <p>#1 Use preprocess to add current language</p></div> Mon, 12 Jul 2021 23:49:18 +0000 purushotam 50 at https://purushotam.in Storing extra information for any entity in Drupal https://purushotam.in/articles/storing-extra-information-any-entity-drupal <span property="schema:name">Storing extra information for any entity in Drupal</span> <span rel="schema:author"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">purushotam</span></span> <span property="schema:dateCreated" content="2021-04-03T21:20:04+00:00">Sat, 04/03/2021 - 23:20</span> <div property="schema:text" class="text-content field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>A lot of times we come across a requirement where we need to manage some additional data for the Drupal entities. Now, if we think simply, the solution is to create fields .. right... easy and best, that's what Drupal is all about, entities and their properties as fields. But, there can be scenarios where the entity is not fieldable (as of now).</p> <p>We will be specifically focusing on them in this post, though this can be implemented for any entity, the key is to understand what we want to solve and how, it's a kind of trade-off that we need to do while making any decision. As I always say Drupal has a lot of ways to solve a problem statement, it's you who decide which is the efficient one. You may not find the below solution as most efficient or scalable for you, but definitely, you would draw some important knowledge/information from this post.</p></div> Sat, 03 Apr 2021 21:20:04 +0000 purushotam 49 at https://purushotam.in Making a variable available (as global) in all twig files in Drupal https://purushotam.in/notes/making-variable-available-global-all-twig-files-drupal <span property="schema:name">Making a variable available (as global) in all twig files in Drupal</span> <span rel="schema:author"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">purushotam</span></span> <span property="schema:dateCreated" content="2021-03-30T23:28:39+00:00">Wed, 03/31/2021 - 01:28</span> <div property="schema:text" class="text-content field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Most of us know, the ideal way of making a variable available in a specific twig file is to use hook_preprocess_HOOK. But what if we have a requirement that we need a kind of global variable that should be accessible in any twig file. So, that we are able to use it wherever we want to, without additional pain.</p> <p>The best part of Drupal is, everything is possible. But at the same time, there is a trick, you always have more than one way of doing things. And now it's in your hands to pick up the best suitable performant way for your solution.</p> <p>So, over here you have the following solutions (which I can instantly think for this problem statement):</p></div> Tue, 30 Mar 2021 23:28:39 +0000 purushotam 48 at https://purushotam.in Acquia Backend Specialist Certification Guide https://purushotam.in/articles/acquia-backend-specialist-certification-guide <span property="schema:name">Acquia Backend Specialist Certification Guide</span> <span rel="schema:author"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">purushotam</span></span> <span property="schema:dateCreated" content="2021-02-27T21:49:22+00:00">Sat, 02/27/2021 - 22:49</span> <div property="schema:text" class="text-content field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Recently completed Acquia Backend Specialist Certification thought to share my thoughts around this certification exam that might help the aspiring ones. While preparing for this exam, I had heard that this is the toughest exam out of all the Acquia Drupal Certifications and in my opinion, this rumour is true.</p> <p>Actually, these certifications might be easy for others but were not for me, as, since last 1.5 yrs I have been working in Drupal 7 only. When I started preparing for this exam, I followed the same preparation pattern which I used while preparing for Acquia Drupal 8 Developer Certification Exam.</p></div> Sat, 27 Feb 2021 21:49:22 +0000 purushotam 6 at https://purushotam.in