You can use the following snippet to load multiple nodes without getting timeout or memory-related issues.
You can use the following code snippet to change the required attribute of the path field in the node form alter in this way:
This will keep the path tab open by default and mark the alias field as required.
You can use the following code to set URL alias for a node if your website also uses Pathauto
Where $node_url is the desired alias and $node is loaded node object.
Custom REST Resource can be get used in case you are trying to expose some data from your Drupal website to another external system. In the REST resource code, you might have to access any Drupal services to generate the desired output. Here is a sample code to achieve that.
Whenever we send a request to the Drupal website from our embedded JS application, we have to send a CSRF token with the request otherwise it is seen as a request forgery issue. You can provide CSRF token to your JS application in the following way:
And in your JS application CSRF token can be accessed from the drupalSettings object. Make sure this token is added to every request to avoid X-CSRF token not found issues.
You can use the following snippet from devel PHP or your custom module to delete all the nodes programmatically.
The configurations can be removed in the following way.
Here is a sample Nginx Server block for the Drupal 7 website.
It is always a nice practice to disable automated cron module and setup Drupal cron tasks from the crontab in linux and use of Drush instead of hitting a request on Drupal generated URL. Here is the way to achieve that:
1. Enter command crontab -e to open the cron tab in editor.
2. Enter the following line and save the file.
0 */2 * * * cd /var/www/html/example-drupal && /usr/local/bin/drush cron
So this will ensure cron runs every 2 hours. Make sure to set correct Drupal directory and drush path.
Based on the Nginx sample configuration provided the by Magento repository, I have created an Nginx configuration that can be used to set up Magento on any VPS.