Friday 18 June 2021

How to add, commit, push files and database changes in git process?

We are going to explain not only famous git commands but also will discuss very useful Drush command for upload config(database) changes on a branch.

Follow these steps as given for upload files and database(config) changes on the branch.

1. drush cex => This command is used to upload a database(config) changes on the branch.

2. git status => To check the changes in files and database(config).  

3. git add => This command is used to add your changes on a branch, here you have to git add \<changes file path or config changes path>

OR

3. git add --all => This command is used to add all edited file changes at the same time.

4. git commit => This command is used to commit the added changes on branch by- [git commit -m "type message for commit here"] 

5. git push => This command is used to push all commit changes on the current branch.


OR 


If git operations are difficult for you then follow these given steps.

1. drush cex => This command is required first for upload database(config) changes on the branch.

2. Then use "Git desktop" software for all above git operations on the branch by great GUI. 

download link: https://desktop.github.com/


Note: If have any suggestions or issue regarding 'How to add, commit, push files and database changes in git process?' then you can ask by comments. 

How to show only used taxonomy terms or category in view exposed filters?

In Drupal 8, we have a contributed module that name is "Selective Better Exposed Filters". That is to show only used taxonomy terms or categories in view exposed filters.

https://www.drupal.org/project/selective_better_exposed_filters

But it will depend on the better_exposed_filters module.

https://www.drupal.org/project/better_exposed_filters

better-exposed filters (selective) module will enhance the exposed form style. you have to enable it in exposed form, check the box "show only used terms" at the bottom. 

If you have multiple exposed filters then you will have to enable them individually under the "more options for".


Note: If have any suggestions or issue regarding 'How to show only used taxonomy terms or category in view exposed filters?' then you can ask by comments. 

Thursday 17 June 2021

How to render nested paragraph field in drupal 8 paragraph twig?

It's a very easy way to render nested paragraph fields, we are going to explain with 2 methods for link field data.

Method 1: Suppose your paragraph(entity reference revisions) name is 'simple_card', so your file name will be "paragraph--simple-card.html.twig" and we have to render inner paragraph(entity reference revisions) link field data, so our approach will be...

{% for item in content.field_p_link['#items'] %}

{{ item.entity.field_link.uri }}

{% endfor %}


Method 2: Our second method will be direct one line code for this inner 'field_link' field data is...

{{ content.field_p_link['#items'].entity.field_link.uri }} 


// here field_p_link is the first paragraph revision field and field_link is a nested paragraph field.

Imp: Other text fields simply render by 

          {{ content.field_p_link['#items'].entity.field_first_name.value}} 


Note: If have any suggestions or issue regarding 'How to render nested paragraph field in drupal 8 paragraph twig?' then you can ask by comments. 

Monday 14 June 2021

Create and move to New branch in Git.

 We are going to explain with some steps..

Git Bash process..

1. 'git checkout' // from current branch.

2. 'git checkout postlaunch_qa'  //You can rename underline area, from where you get the branch data.

3. git pull

Cmd process..

  • mysql -u drupal -p cvent < dev-cvent.sql // Run the fresh database here. (dev-cvent.sql this will be on root)  [optional - not every time required]

  • drush cr  //for clear cache

  • drush cim  //for config import changes.

4. 'git branch --all'  // for get all branches. (optional)

5. 'git branch <new branch name>' // for create new branch for new work.

6. 'git checkout <new branch name>' //for checkout that branch

After this process For login/reset password:

drush uli  // run this command and will return  kind of url:

'/en/cms/reset/1/1627312926/saMxys3WxEQ2I8DowhnRIhEYbxNdkc3yVuhwj9DQ33c/login'

put this on url website url and it will redirect to reset password for login.

Note: If have any suggestions or issue regarding 'Create and move to New branch in Git.' then you can ask by comments. 

Tuesday 8 June 2021

How to generate csv file from table data and save in specific path?

 A simple way to generate a CSV file from a database table is the "file_put_contents" function. here we are giving an example of this.

Code:

// Given exmaple is relate from drupal query..

function array2csv($data, $delimiter = ',', $enclosure = '"', $escape_char = "\\")

{

    $f = fopen('php://memory', 'r+');

    foreach ($data as $item) {

        fputcsv($f, $item, $delimiter, $enclosure, $escape_char);

    }

    rewind($f);

    return stream_get_contents($f);

}


$data = array();  
$watchdog_results = db_query("SELECT wid,uid,type,message,severity,link,location,referer,hostname,timestamp FROM watchdog")->fetchAll();

if(!empty($watchdog_results)){

// for adding first Header row

$data[] = array(

  'wid',

  'uid',

  'type',

  'message',

  'severity',

  'link',

  'location',

  'referer',

  'hostname',

  'timestamp',   

);

// for adding content rows

foreach($watchdog_results as $line){

   $data[] = $line;  

}

}

$array = json_decode(json_encode($data), true);

$csdata = array2csv($array);

file_put_contents('/code/watchdog-report.csv', $csdata);

// here "/code/watchdogcustom-report.csv" is our located file path and filename, you can write filename as you want and also locate in any path.

In Drupal, you can use this code anywhere you want like, in any controller or hook_cron function, etc.


Note: If have any suggestions or issue regarding 'How to generate csv file from table data and save in specific path?' then you can ask by comments. 

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...