Skip to content

Instantly share code, notes, and snippets.

View radheymkumar's full-sized avatar

Radheshyam Kumawat radheymkumar

  • PTI WebTech
  • Jaipur
View GitHub Profile
wget https://github.com/drush-ops/drush/releases/download/8.1.17/drush.phar
chmod +x drush.phar
sudo mv drush.phar /usr/local/bin/drush
drush --version
@radheymkumar
radheymkumar / Install Console
Created September 20, 2019 12:45
Install Console
https://www.a2hosting.in/kb/installable-applications/optimization-and-configuration/drupal2/installing-drupal-console
Console Install
composer require drupal/console:~1.0 --prefer-dist --optimize-autoloader
Path
echo 'alias drupal="/var/www/html/<project_name>/vendor/bin/drupal"' >> ~/.bashrc
source ~/.bashrc
Command:
@radheymkumar
radheymkumar / addMessage Drupal 8
Created May 28, 2019 06:58
addMessage Drupal 8
<?php
// The drupal_set_message() function is being deprecated!
// @see https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/function/drupal_set_message/8.5.x
// > Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
// > Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
// In some custom code.
\Drupal::messenger()->addMessage('Say something else');
// When trying to print out a simple var.
\Drupal::messenger()->addMessage(print_r($stuff, TRUE));
// In a Drupal 8 Form's submitForm() handler:
@radheymkumar
radheymkumar / Get Setting.php Variable
Created March 13, 2019 08:42
Get Setting.php Variable
// Settings.php
$settings['hello_world'] = 'Radheshyam Kumar Kumawat';
//bartik.theme
function bartik_preprocess_page(&$variables) {
$variables['setting_name_value'] = Settings::get('hello_world', 'my drupal setting name');
}
//page.html.twig
{{ setting_name_value }}
@radheymkumar
radheymkumar / logger drupal 8
Created March 7, 2019 14:10
logger drupal 8
\Drupal::logger('debugging2')->warning(print_r($item, TRUE));
@radheymkumar
radheymkumar / Create Admin User IN Drupal by DRUSH
Created February 21, 2019 09:02
Create Admin User IN Drupal by DRUSH
Create a new administrator account in drupal with drush
Create your new user:
$ drush user-create your_user_name --mail="your_user_email@email.com" --password="your user password"
Assign the role administrator to your user:
$ drush user-add-role "administrator" your_user_name
@radheymkumar
radheymkumar / Cron update Code
Created December 21, 2018 09:37
Cron update Code
/**
* Implements hook_cron().
*/
function csv_uploader_cron() {
$end_date = strtotime(date('Y-m-d H:i:s'));
$start_date = strtotime(date('Y-m-d H:i:s', strtotime("-2 days")));
$query = \Drupal::database()->select('node_field_data','n');
$query->leftjoin('node__field_roles','r', 'n.nid=r.entity_id');
function common_mail_alter(&$message) {
if ($message['id'] == 'user_password_reset') {
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
}
}
/* Password recovery */
<a href='[user:one-time-login-url]' target="_blank">Generate/Reset Password</a>
Create block type
Field - Title, body, image, link,
help - https://medium.com/@sarahcodes/custom-block-type-for-hero-banners-in-drupal-8-7d0adb665fd3
Twig Field value - https://blog.usejournal.com/getting-drupal-8-field-values-in-twig-22b80cb609bd
****************************************************
1. themename.theme
/**
* Implements hook_theme_suggestions_HOOK_alter() for form templates.
*/
@radheymkumar
radheymkumar / View print on TPL
Created September 6, 2018 05:12
View print on TPL
<?php
$output = '';
$view = views_get_view('assets_search');
if($view){
$view->set_display('page');
$output = $view->preview('assets_search');
print $output;
}
?>