Latest Articles
Our latest news updates and insightful blog posts, designed to empower you with the knowledge and strategies you need to succeed.
In views template how can check user is logged in drupal 8
In a Drupal 8 views template, you can check if a user is logged in by using the following code
{% if logged_in %} Welcome, {{ user.name }} {% else %} {{ path('user.login') }} {% endif %}
Explanation:
- The logged_in variable is a boolean that is set to true if the user is logged in, and false if they are not.
- The user variable contains information about the currently logged-in user, such as their username…
In Google Index API get an error private://google_index_api/ is invalid
Google Index API module installed but on configuration screen get following error when upload jason file. "The file could not be uploaded because the destination private://google_index_api/ is invalid"
So I have found the solution
In sett…
How to remove trailing slash from URL Drupal 10
You can remove trailing slashes from URLs using the .htaccess
file and mod_rewrite
Add the following code to your .htaccess
file to Remove Trailing slashes from all URL of website.
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
This code will remove the trailing slash from URLs and issue a 301 redirect, so if someone accesses a URL with a trailing slash, they will be redirected to the same URL without the trailing slash.
Make sure…
How to form alter of node page in DRUPAL 8
I want to change select list value in my state field so we follow the step My content type is 'project' so we can get the form id as 'node_project_form' I have a feild 'state' in my content type so field machine name is 'field_state'
function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) { $dropdown_array = array('DL'=>'Delhi'); if ($form_id == 'node_project_form') { $form['field_state']['widget'] = array( '#type' => 'select', '#defau…
How to design OMR Sheets using the OMR Software?
With the advancement of science and technology, the OMR industry too has experienced a major enhancement of the provided features. The traditionally developed OMR software was just used to read the OMR sheets that would be contributing to the effective checking and calculation of final scorecards. The user can conduct exams on a specific pattern of OMR sheets only.
Now, with the modification to the OMR software the user can easily design a vivid range of OMR sheets. OMR sheet scanning soft…
How to create user programatically in DRUPAL 8
$language = \Drupal::languageManager()->getCurrentLanguage()->getId(); $user = \Drupal\user\Entity\User::create(); // Mandatory. $user->setPassword('password'); $user->enforceIsNew(); $user->setEmail('email'); $user->setUsername('user_name'); // Optional. $user->set('init', 'email'); $user->set('langcode', $language); $user->set('preferred_langcode', $language); $user->set('preferred_admin_langcode', $language); $user->set('setting_name', 'setting_value');…
How to create or manage configuration form in Drupal 8
How to create or manage configuration form in Drupal 8
Create configuration form
create path in routing.yml, here my module name is "mymodule" so I am using it, you can use your module name.
mymodule.Myfiguration: path: 'myconf' defaults: _form: '\Drupal\mymodule\Form\MyConfigurationForm' // I have created form "MyConfigurationForm.php" _title: 'My API Configuration' requirements: _permission: 'mymodule dashboard_admin' // this is permission setting…
How to add condition in views with custom field in DRUPAL 8
If you want to add if condition in my "global custom text" field in views Drupal 8
Example 1: Check node status and put conditional link according to publish status
{% if status %} put your HTML as condition {% endif %}
Example 2: In this example we are checking a field value is empty or not. according to value in we are showing link or status
{% if field_final_layout_date is empty %}
put your HTML as condition
{% else %}
Complete…
How to add Captcha in Webform in Drupal 8
If you have already created a webform then you can follow thi step
1. Open this url /admin/structure/webform (Structure -> Webform)
2. Click on "Build" in OPERATIONS column
3. Click on "+Add element" button, there will be seen a list form element
4. You can select Captcha from available list.
How to access field value for a node in Drupal 8
Use this code at the top of your coding
use Drupal\node\Entity\Node //Working with nodes Load a node by NID:
$nid = 123; // example value
Method 1
$node_storage = \Drupal::entityTypeManager()->getStorage('node'); $node = $node_storage->load($nid);
Method 2
$node = \Drupal\node\Entity\Node::load($nid);
Get node's NID:
echo $node->id(); // 123Get node's bundle type: echo $node->bundle(); // 'article' e…
How render term field on node template in drupal 9
In Drupal 9, you can render a term field on a node template using the field_view_field() function. This function takes the following parameters:
Entity type: The type of the entity (in this case, it's "node").
Entity: The node object that contains the term field.
Field name: The machine name of the term field you want to render.
Display mode: The view mode you want to use to render the field (e.g., "full", "teaser", "default", etc.).
Here's an example of how to render a t…
How can run my code on user login Drupal 8
In Drupal 8, you can execute code before user login by implementing a custom module and using a hook to execute the code. Here are the steps you can follow:
- Create a custom module by creating a directory in the
modules
directory of your Drupal installation. For example, if you want to name your module "custom_login", create a directory named "custom_login" in themodules
directory. - Create a
custom_login.info.yml
file in your module dir…