Blog

In your theme's template.php file, you could add something like **/ /** * Implements hook_preprocess_html */ function THEME_NAME_preprocess_html(...
Get user role of current loggedin user $user_roles = \Drupal::currentUser()->getRoles(); Get user detail of curent loggedin user $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id()); user_delete(uid); $user_roles = \Drupal::currentUser()->getRoles(); $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id()); $uid = $user->get('uid')->value;
global $user; $nid = 4; //nid is the node id of your webform. $node = node_load($nid); The values to save. Take case about array indexes! (see below) $data = array( '1' => array('0' => $type), '2' => array('0' => $method), '5' => array('0' => $volume), '6' => array('0' => $comment), '7' => array('0' => $phone), '8' => array('0' => $length) ); $...
When we enabled cache and check "Aggregate CSS files" and "Aggregate JavaScript files"  at ca/admin/config/development/performance but sometime we don't want to compress some specific CSS and JS files. Method 1. You can add css as given format, by using {preprocess: false} with file name we can exclude that css or js from aggregation mylibraryname: css: theme: css/...
When we create views by using flexslider by default its slide one image on click/slide. If you want slide multiple images in one slide follow these step. Step 1: Open '/admin/config/media/flexslider' and add  new setting Step 2: On tab "General Slideshow and Animation Settings" change setting according to following instructions Flexslider settings as follows: Starting Slide = 1...
I found issue with my website, when I have enabled SSL then compressed CSS and JS doesn't work. If disable compression of JS and CSS then worked but its issue with loading speed.  I found solution for this issue I have added this code in settings.php then its works fine. put your domain name instead of website $base_url = 'http://www.website.com';
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.
Set current date in custom form element in DRUPAL8 Add this line at top use Drupal\Core\Datetime\DrupalDateTime; function HOOK_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == 'node_article_form') { $form['field_date']['widget'] = array( '#type' => 'datetime', '#title' => 'Enter Date', '#required' =>...
Method to redirect on node id url $url = Url::fromRoute('entity.node.canonical', ['node' => $nid]); $form_state->setRedirectUrl($url); Method to redirect on custom url $url = Url::fromRoute('olsys.mycustom_dashboard'); $form_state->setRedirectUrl($url); Redirect on user view page of loggedin user use Drupal\Core\Controller\ControllerBase; // Use this on top return $this->...
Code to query for getting node according to field condition in DRUPAL 8 $query = \Drupal::entityQuery('node') ->condition('status', NODE_PUBLISHED) ->condition('type', 'custom_type'); $and = $query->andConditionGroup(); $and->condition('custom_taxonomy', 2); $query->condition($and); $and = $query->andConditionGroup(); $and->condition('custom_taxonomy', 8); $...
We can get value at node.html.twig for the following feild type using these given method. Field Type Body Text List Image File Boolean Number Email Phone Date Taxonomy/Entity Reference Labels for any field type Multi-value for any field type I use the word ‘display’. When I’m talking about the more raw version of the content, I use ‘value’. 01. Body The default body field on a content type is...
$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', $...
When we apply coupon for discount its applied for sale price by default but we need to apply discount coupon on regular price so you can use this code on function.php By default cart and product show sale price after applying this code Regular price will be update on cart. add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 10, 1); function add_custom_price( $cart_object...
Soln. 1. Install Ludwig module https://www.drupal.org/project/ludwig,  2. Download library from https://github.com/commerceguys/addressing  3. Extract folder and replace folder name as v1.0.0 4. place the library folder (v1.0.0) in modules/address/lib/commerceguys-addressing 5. You can check library status at /admin/reports/packages (Ludwig module show status and suggesstion of...
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...

Pages