Skip to content

Instantly share code, notes, and snippets.

@manojiksula
manojiksula / formattingtest.php
Created January 27, 2021 18:00 — forked from bryanburgers/formattingtest.php
Forcing four-digit years on IntlDateFormatter::SHORT
<?php
$d = new DateTime("2012-10-11");
function unalteredFormat($date, $locale) {
$fmt = new IntlDateFormatter(
$locale,
IntlDateFormatter::SHORT,
IntlDateFormatter::NONE);
$fmtted = $fmt->format($date);
@manojiksula
manojiksula / LayoutLoadBeforeObserver.php
Created October 6, 2020 13:39 — forked from 0-Sony/LayoutLoadBeforeObserver.php
Magento 2 : Add Body Class using an observer
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]> <@>
* @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr)
*/
namespace MyVendor\MyModule\Observer;

on hover menu

<div class="user_initials">MC</div>
<div class="user-menu-wrapper">
Menu
</div>
@manojiksula
manojiksula / get_node_by_path.php
Created August 11, 2020 13:45 — forked from crittermike/get_node_by_path.php
Drupal 8 Get node ID by path alias
<?php
$path = \Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias');
if(preg_match('/node\/(\d+)/', $path, $matches)) {
$node = \Drupal\node\Entity\Node::load($matches[1]);
}
@manojiksula
manojiksula / import.php
Created July 24, 2020 15:09 — forked from crittermike/import.php
Importing Drupal 8 config programmatically
<?php
// Import arbitrary config from a variable.
// Assumes $data has the data you want to import for this config.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');
@manojiksula
manojiksula / drupal-8.form.reset-button.php
Created July 18, 2020 15:59 — forked from RuZniki/drupal-8.form.reset-button.php
Drupal 8 Adding a Reset Button to a form
<?php
/**
* Implements template_preprocess_form().
*/
function TEMPLATE_preprocess_form(&$vars) {
$vars['form']['actions']['reset'] = [
'#type' => 'html_tag',
'#tag' => 'input',
'#attributes' => [
'class' => 'button',
@manojiksula
manojiksula / download_file.py
Created June 15, 2020 15:35 — forked from kissgyorgy/download_file.py
Python: Download file, get file size and Content type.
import requests
r = requests.get("http://download.thinkbroadband.com/10MB.zip",
cookies={'cookie1': 'working'}
)
open('10MB.zip', 'wb').write(r.content)
@manojiksula
manojiksula / Apache.md
Created May 21, 2020 15:54 — forked from ignatisD/Apache.md
MailHog localhost xampp/wamp integration

#MailHog example page

MailHog is an email testing tool for developers.

It gives the developer the option to intercept and inspect the emails sent by his application.

You can download the MailHog Windows client from one of the links below.

@manojiksula
manojiksula / example.php
Created May 10, 2020 09:09 — forked from signalpoint/example.php
Drupal 8 Set Message Example
<?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');
@manojiksula
manojiksula / MyService.php
Created May 1, 2020 21:02 — forked from JeffTomlinson/MyService.php
Drupal 8 Configuration Dependency Injection
<?php
namespace Drupal\my_module\Services;
use Drupal\Core\Config\ConfigFactory;
/**
* Class MyService.
*
* @package Drupal\my_module\Services