Monday 16 December 2019

How to avoid Core CSS and JS from theme in drupal 8?

Sometimes we just want to render our custom css/js, and avoid globally rendered core css or js from every page. So we have to follow given below steps:

Step 1: First go to your theme ".info.yml" file.
Step 2: Then add "stylesheets-remove:" parameter and add css file path of all core files like,
Example: Theme file name is "account.info.yml".
then we just have to add 'stylesheets-remove:' for avoid under write files there..

stylesheets-remove:
  - core/themes/stable/css/system/components/autocomplete-loading.module.css
  - core/themes/stable/css/system/components/ajax-progress.module.css
  - core/themes/stable/css/system/components/align.module.css

 
Step 3: Clear full cache of project.

So this is the easy way to avoid core file from project pages.


Note: How to remove globally CSS from theme of project in drupal 8?

Monday 2 December 2019

How to change in view ajax according to requirement in drupal 8?

It's easy to handle this core changes of views. One thing we have to sure that Views Advanced feature "Use AJAX:" should be yes.

"Use AJAX: Yes"

After that we can check our views/ajax request by Inspect and Check with Network Tab. We are giving an example to easy to use this.

Example: Suppose we have to start any view/ajax request on click on any "id" in html then our code in jquery file will be:

jQuery(document).on("click", "#prodresources", function (e) {                
    var arr = base_fullurl.split('/');
    var page_nid = arr[2]; 
    Drupal.attachBehaviors();
    getInfo('application_resources',['block_3','block_13'], page_nid);    // we are creating a function on click on "prodresources" id.
});

Parameters:
view_name : "application_resources"       // that is view machine name
view_display_id : ['block_3','block_13']  // we can use multiple views block on same view.
view_args: page_nid                       // this is argument for view


We just have to pass these three parameters view_name:machine name and view_display_id: blocks in array in multiple case and last one is view_args: if arguments pass.

function getInfo(view_name, blocks, args) {
    var base_url = window.location.origin;       
    $.ajax({
      url: base_url+'/views/ajax',
      type: 'post',
      data: {
        view_name: view_name, 
        view_display_id: blocks,
        view_args: args,
      },
      dataTypeview_display_id: 'json',
      success: function (response) {
          if (response[3] !== undefined) {
          var viewHtml = response[3].data;
          $('#destination_id').html(viewHtml);
          Drupal.attachBehaviors();
        }           
      },
          error: function(data) {
           alert('An error occured!');
          }
    });
}

Note: How to apply changes on views ajax according to requirement in Drupal 8?

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...