Skip to content

Instantly share code, notes, and snippets.

View radheymkumar's full-sized avatar

Radheshyam Kumawat radheymkumar

  • PTI WebTech
  • Jaipur
View GitHub Profile
@radheymkumar
radheymkumar / Voice open page
Created December 11, 2020 15:41
Voice open page
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.interimResults = true;
recognition.addEventListener('result', e => {
transcript = Array.from(e.results).map(result => result[0]).map(result => result.transcript).join('');
const statement = e.results[0][0].transcript;
console.log(statement);
if (statement === "voice admin new page") {
// Get all even no 1 to 100
<?php
$i;
for($i=1;$i<=100;$i++)
{
if($i%2==0)
{
echo $i."<br>";
}
}
@radheymkumar
radheymkumar / All Programming Book pdf
Created January 28, 2020 12:47
All Programming Book pdf
https://riptutorial.com/ebook?q=&page=2
@radheymkumar
radheymkumar / How to alter single custom field value in views?
Created January 18, 2020 05:13
How to alter single custom field value in views?
function hook_views_pre_render(&$view) {
switch ($view->name) {
case 'YOUR_VIEW_NAME':
// override the global custom text field value
$view->field['nothing']->options['alter']['text'] = 'My custom text';
$view->field['nothing']->options['alter']['alter_text'] = TRUE;
break;
}
}
@radheymkumar
radheymkumar / Drupal 8 ajax popup
Created January 2, 2020 13:18
Drupal 8 ajax popup
<ol>
<li>
<a class="use-ajax"
data-dialog-options="{&quot;width&quot;:400}"
data-dialog-type="modal"
href="/node/1">
First article displayed in modal dialog.
</a>
</li>
<li>
@radheymkumar
radheymkumar / Commerce membership Drupal 8
Last active December 18, 2019 12:36
Commerce membership Drupal 8
https://www.drupal.org/docs/8/modules/commerce-iats/how-to-setup-recurring-payments
Commerce Membership-
Install Module:-
1. Drupal commerce install via composer - composer require "drupal/commerce"
2. Install commerce_recurring module - composer require "drupal/commerce_recurring"
3. Install commerce_license module - composer require "drupal/commerce_license"
@radheymkumar
radheymkumar / Access field value for a node in Drupal
Created October 22, 2019 12:08
Access field value for a node in Drupal
use Drupal\node\Entity\Node
Working with nodes Load a node by NID:
$nid = 123; // example value
Method 1
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$node = $node_storage->load($nid);
Method 2
@radheymkumar
radheymkumar / Get current user in drupal 8
Created October 18, 2019 04:24
Get current user in drupal 8
get current user in drupal 8
Description: In drupal 7 we get the current user object by defining global $user but in drupal 8 this quite different. If you want to get current user object then follow below code.
$current_user = \Drupal::currentUser();
$uid = $current_user->id();
It returns user id of current user.
$user_mail = $current_user->getEmail();
It returns user email id.
@radheymkumar
radheymkumar / Drupal 8 Common Code
Last active July 20, 2021 01:57
Drupal 8 Common Code
Example URL - http://xandeadx.ru/blog/drupal/946
---
$ composer require drush/drush
---
$link = \Drupal\Core\Link::createFromRoute('My link', 'entity.node.canonical', ['node' => 123]);
// По пути
@radheymkumar
radheymkumar / View page add js
Last active October 15, 2019 09:53
View page add js
/**
* Implements hook_views_pre_render().
*/
function custom_views_pre_render(ViewExecutable $view) {
if (isset($view) && ($view->storage->id() == 'super_awesome_view')) {
$view->element['#attached']['library'][] = 'custom/custom_view';
}
}