Skip to main content

Drupal

FOSS CMS

Upgrading from Drupal 7 to Drupal 10

Submitted by system on
Create a new D10 portal. Enable migrate modules. Enable https://www.drupal.org/project/migrate_upgrade to allow migrations via Drush. Set up a Migrate Database $databases['migrate']['default'] = [
'database' => 'drupal7db',
'username' => 'drupal7db',
'password' => 'drupal7db',
'prefix' => '',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql',
'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
];

Upgrading from Drupal 9 to Drupal 10

Submitted by system on

1. Install Upgrade Status[https://www.drupal.org/project/upgrade_status] module to check issues contrib and custom modules compatibility. 

2. Remove Upgrade Status when all checks are green and ready to go. Uninstall Upgrade status and remove it from Composer.

 
composer remove drupal/upgrade_status 

3. Temporarily add write access to protected files and directories
chmod 777 sites/default chmod 666 sites/default/*settings.php chmod 666 sites/default/*services.yml 

Installing Drush using Composer

Submitted by system on
With the advent of Drupal 8 and composer integration, there is a better way of installing Drush. Install Composer: curl -sS https://getcomposer.org/installer | php
Enable Composer access for All Users: mv composer.phar /usr/local/bin/composer
ln -s /usr/local/bin/composer /usr/bin/composer

Install Drush: git clone https://github.com/drush-ops/drush.git /usr/local/src/drush
cd /usr/local/src/drush

How to get the current node object

Submitted by amitsedai on
For Drupal6 , it is recommended to use menu_get_object() <?php $node = menu_get_object(); $story = $node->type == 'story'; ?> However in Drupal 7, node_load() also caches the current node object and in many cases, node_load() returns an object faster than menu_get_object() -- http://www.thecarneyeffect.co.uk/menugetobject-vs-nodeload-when-getting-node-object-drupal-7 https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_object/7

Creating PDF Document using DomPDF

Submitted by amitsedai on
<?php /** * Convert the HTML into a PDF and store it in a particular location. * In this example, the dompdf library is stored under libraries folder in Drupal. */ function ji_custom_convert_pdf($user_html){ //Get path of dompdf folder under libraries set_include_path(libraries_get_path('dompdf')); require_once "dompdf_config.inc.php"; $dompdf = new DOMPDF(); $dompdf->load_html($user_html); $dompdf->render(); $output = $dompdf->output(); file_put_contents("sites/default/files/resume/".$user->name."_resume.pdf", $output); } ?> --

Rules cron based condition code for allowing execution only once

Submitted by amitsedai on
<?php /* * Part of Rules condition code that returns true if the current time during cron is between 6 am and 7 am */ $ji_daily_status = variable_get("ji_daily_report","1"); //Check if the variable is set, if not set it to 1 [First Time] /* * This fragment checks if the time is between 6 and 7, if so enables the flag * If any other time, sets the ji_daily_report so that next time it executes when cron runs between 6 and 7 */ $time = date('H'); // Get the current time /* Any arbitrary time - Checks if the time is not between 6 am and 7 am */ if($time < 6 || $time > 7){

Site Benchmarking and Performance Improvement

Submitted by amitsedai on
Improving Site Performance: 1. Disable all caching in the site and do benchmark for anon user 2. Benchmark for auth user for a particular page 3. Check logs to see if any notice or error is happening in the site. Solve the issue and notice BM 4. Disable unwanted modules if any and do another benchmark. Note the diff. 5. Modify or update apache or mysql setting minor if any to see noticiable change in benchmark 6. Optimize PHP and see if noticeable difference occurs 7. Install Devel and check queries and page rendering times

Saving Form Selection using Form API

Submitted by amitsedai on
During custom form submission we would want to remember the previous selection. There are many ways to do that, which includes using Sessions and variable_set to set the default value but this is an overkill if you wanted to simply preserve/remember the selection in the next page or after submission. The best way is to use $form_state['storage'] in your submit handler to hoard values between steps. Consider an example: <?php function custom_form_submit($form, &$form_state) { $start_date = $form_state['values']['startdate']; $end_date = $form_state['values']['enddate'];

How to Set Filters for a View in Drupal 7 programmatically

Submitted by amitsedai on
Accessing a view programmatically <?php $view = views_get_view('view_name'); $view->init(); $view->set_display('default'); // or display id like page_1, block_1 $view->set_arguments(array($ARGS)); //display_name = 'default' or 'page' and so on //filter_name is the name of the filter //debug($view->display['display_name']->handler->options['filters']['filter_name']); $view->display['default']->handler->options['filters']['date_filter']['value']['min']='2012-05-01'; $view->display['default']->handler->options['filters']['date_filter']['value']['max']='2012-06-30';

Add Sites to search in Apache Multicore Configurations

Submitted by amitsedai on
Solr is the popular, blazing fast open source enterprise search platform from the Apache Lucene project. Its major features include powerful full-text search, hit highlighting, faceted search, dynamic clustering, database integration, rich document (e.g., Word, PDF) handling, and geospatial search. Solr is highly scalable, providing distributed search and index replication, and it powers the search and navigation features of many of the world's largest internet sites. -- Source: http://lucene.apache.org/solr/