Skip to content

Instantly share code, notes, and snippets.

View mohammadanwar's full-sized avatar
☁️

Mohammad Anwar Siddiqui mohammadanwar

☁️
View GitHub Profile
@mohammadanwar
mohammadanwar / drupal_8_changing_the_active_Database_connection_at_runtime.txt Just a small example of changing database connections within our code, using the parameters registered in settings.php.
// First: You have declared the database connections in your settings.php file.
// The $databases array is a two levels array with form ['key']['target'].
// 'key' reference to a database and 'target' set options added to 'default' for
// master/slave configurations.
// Default Database with key = default
$databases['default']['default'] = array (
'database' => 'database_name',
'username' => 'database_user',
'password' => 'database_password',
@mohammadanwar
mohammadanwar / settings.local.php
Created August 28, 2024 06:24 — forked from keopx/settings.local.php
Drupal 8 Redis settings.local.php
<?php
/**
* Set redis configuration.
*/
/** @see: https://docs.platform.sh/frameworks/drupal8/redis.html */
if (extension_loaded('redis')) {
// Set Redis as the default backend for any cache bin not otherwise specified.
// $settings['cache']['default'] = 'cache.backend.redis';
<?php
/**
* Implements hook_form_alter().
*/
function MY_CUSTOM_MODULE_form_alter(&$form, $form_state, $form_id) {
//Initial set of the wanted view.
$view_names = ['name_of_view'];
@mohammadanwar
mohammadanwar / drupal_managing_routes_basic_usage.txt
Created August 28, 2024 06:22 — forked from davidjguru/drupal_managing_routes_basic_usage.txt
Managing routes in Drupal (I): Basic usage of the routing system
# Basic use of a Drupal route.
## Just declare a route, a Controller and a responsible method.
## file: module_name.routing.yml
-------------------------------------------------------------
hello_world.hello:
path: '/hello'
defaults:
_controller: '\Drupal\hello_world\Controller\HelloWorldController::helloWorld'
_title: 'Out First Route'
requirements:
@mohammadanwar
mohammadanwar / basic_migration_one.yml
Created August 28, 2024 06:22 — forked from davidjguru/basic_migration_one.yml
Drupal Migrations: Basic Migration descript file for two nodes using embedded format.
id: basic_migration_one
label: 'Custom Basic Migration 2000'
source:
plugin: embedded_data
data_rows:
-
unique_id: 1
page_title: 'Title for migrated node - One'
page_content: 'Lorem fistrum mamaar se calle ustée tiene musho pelo.'
-
@mohammadanwar
mohammadanwar / migration_csv_articles.csv
Created August 28, 2024 06:21 — forked from davidjguru/migration_csv_articles.csv
Custom example of random CSV format file for test Migrations in Drupal. Generated with Mockaroo (https://www.mockaroo.com)
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 3.
id,title,body,tags,image
1,Software Test Engineer III,"Etiam justo. Etiam pretium iaculis justo. In hac habitasse platea dictumst. Etiam faucibus cursus urna. Ut tellus. Nulla ut erat id mauris vulputate elementum. Nullam varius. Nulla facilisi. Cras non velit nec nisi vulputate nonummy.",6th generation,https://robohash.org/maximedoloret.png?size=50x50&set=set1
2,Quality Control Specialist,"Duis aliquam convallis nunc. Proin at turpis a pede posuere nonummy. Integer non velit. Donec diam neque, vestibulum eget, vulputate ut, ultrices vel, augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec pharetra, magna vestibulum aliquet ultrices, erat tortor sollicitudin mi, sit amet lobortis sapien sapien non mi. Integer ac neque. Duis bibendum. Morbi non quam nec dui luctus rutrum. Nulla tellus. In sagittis dui vel nisl. Duis ac nibh. Fusce lacus purus, aliquet at, feugiat non, pretium quis, lectus. Suspendisse potenti. In eleifend quam a odio. In hac habitasse platea dic
@mohammadanwar
mohammadanwar / article_csv_import.yml
Created August 28, 2024 06:20 — forked from davidjguru/article_csv_import.yml
Drupal Migrations: Basic Migration descript file for a CSV file as datasource.
uuid: 1bcec3e7-0a49-4473-87a2-6dca09b91aba
langcode: en
status: true
dependencies: { }
id: article_csv_import
label: 'Migrating articles'
source:
plugin: csv
path: modules/custom/migration_csv_module/csv/migration_csv_articles.csv
delimiter: ','
@mohammadanwar
mohammadanwar / phpunit_xml_partial_php_zone.txt
Created August 28, 2024 06:20 — forked from davidjguru/phpunit_xml_partial_php_zone.txt
PHPUnit - phpunit.xml file for Drupal using DDEV
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
<ini name="memory_limit" value="-1"/>
<!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
<env name="SIMPLETEST_BASE_URL" value="http://migrations.ddev.site/"/>
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
<env name="SIMPLETEST_DB" value="mysql://db:db@db/db"/>
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
@mohammadanwar
mohammadanwar / paragraphs.install
Created August 28, 2024 06:00 — forked from MatthieuScarset/paragraphs.install
Programmatically create Paragraph Types (bundles).
<?php
/**
* Implements hook_install().
*/
function MYMODULE_install() {
// Create new Bundle.
$bundle = new stdClass();
$bundle->name = 'Test Bundle'; // user friendly label
$bundle->bundle = 'paragraphy_test'; // machine name
@mohammadanwar
mohammadanwar / sonar-project.properties
Created August 28, 2024 05:58 — forked from MatthieuScarset/sonar-project.properties
Default Sonar properties for Drupal 8 project
# must be unique in a given SonarQube instance
sonar.projectKey=ONE80WEB:ONE80WEB
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=WEBSITE
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=./web