Monday, February 25, 2019

Content export to CSV, JSON or XML

1. Download and install Views Data Export Module (https://www.drupal.org/project/views_data_export)

If you are using composer to install the module, then all the dependencies will automatically be downloaded.  Otherwise, follow the below steps

1.a. Download and install the CSV Serialization module(https://www.drupal.org/project/csv_serialization), this module requires a library League\Csv. So if you trying to install this module you may get below error message

CSV serialization requires the League\Csv library.


1.b To fix the above issue, download and install Ludwig module (https://www.drupal.org/project/ludwig) It provides a manual alternative to Composer.

After installing Ludwig, go to reports > packages.

Follow the instructions mentioned on that page. You may be instructed to download the library and copy to a specified folder. Do as per that then,

1.c Install CSV Serialization and Views Data export modules respectively.

After successful installation,

Follow the instruction mentioned here (https://www.drupal.org/node/1820452).

Wednesday, February 13, 2019

Drupal 8 Interview questions


  1. What are the custom entities? When and how it can be used?https://opensenselabs.com/blog/tech/how-create-custom-entity-drupal-8
  2. How to create a patch?
  3. Mysql rollback to flag
  4. What are cache tags in Drupal 8?
    https://www.drupal.org/docs/8/api/cache-api/cache-tags
  5. How to create a module using Drupal console?
  6. How to deploy code - Acquia
  7. Custom entities into the single table
  8. Why we need an interface?
    An interface allows unrelated classes to implement the same set of methods, regardless of their positions in the class inheritance hierarchy. An interface enables you to model multiple inheritances because a class can implement more than one interface whereas it can extend only one class.
  9. How to pass the interface variable in the constructor
  10. How to make a string to upper case in Twig
    To make a string in upper case use filter 'upper'
    {{ 'a string'|upper }}
  11. How to create a custom pipe.
    https://symfony.com/doc/current/templating/twig_extension.html
  12. What happens behind when the twig filter used?

Tuesday, February 12, 2019

How to ping an IP address from PHP script?

<?php

$ip_address =   "32.33.45.67"; //ip or web address
exec("ping -n 3 $ip_address", $output, $status);
print_r($output);

?>

The above script will try to ping the IP address 3 times and the response will be available in variable output. It is an array variable and result will look like below

Array
(
    [0] =>
    [1] => Pinging 32.33.45.67 with 32 bytes of data:
    [2] => Reply from 32.33.45.67: bytes=32 time<1ms TTL=128
    [3] => Reply from 32.33.45.67: bytes=32 time<1ms TTL=128
    [4] => Reply from 32.33.45.67: bytes=32 time<1ms TTL=128
    [5] =>
    [6] => Ping statistics for 32.33.45.67:
    [7] =>     Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
    [8] => Approximate round trip times in milli-seconds:
    [9] =>     Minimum = 0ms, Maximum = 0ms, Average = 0ms
)

If you are running the above script from Linux and the output array results empty, then try

exec("ping -c 3 $ip_address", $output, $status);

You can also check the value of $status for the ping status. It will result in 0 if ping is successful.

Monday, February 11, 2019

Git workflow to merge 2 branches



1. Switch to the branch you want to merge another branch

git checkout branch1

2. Execute merge command, here we are going to mcommandnch2 into branch1

git merge branch1

3. If conflict occures, manually resolve the conflict and add/stage the resolved files by executing

git add <file1 file2 ...>

4. Commit the merges.

git commit -m "message"

5. Push the changes.

git push origin branch1

Saturday, February 2, 2019

How to create an empty git branch


Sometimes we may want to create a different project (storing some documentation or some other files)inside our available repository. We can achieve this by creating a new branch by using normal "git checkout <branch-name>" command. But the correct way is

git checkout --orphan <branchname>


so that a new branch will be created inside the repo and automatically switched to the same. The new branch doesn't have a parent branch. We may need to execute the below commands to clear the cache and leftover files.

git rm --cached -r
git reset --hard


Once you created the orphan branch and after adding your new files, commit and push it. So that the branch will be available to all team members.