Skip to content

Instantly share code, notes, and snippets.

View biswajeetparida's full-sized avatar

Biswajeet Parida biswajeetparida

View GitHub Profile
@yusufhm
yusufhm / d8_import_config.php
Created February 14, 2017 04:12
drupal 8 import config programmatically
<?php
// The following snippet updates the filter format configuration.
$config_path = drupal_get_path('module', 'my_custom_module') . '/config/install'; // or any path containing config files theoretically.
$source = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$config_storage->write('filter.format.basic_html', $source->read('filter.format.basic_html'));
@morsok
morsok / referer.php
Last active February 28, 2022 10:22
Drupal 8 : Do something based on the referer if it's your website or another.
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
function my_function() {
$previousUrl = \Drupal::request()->server->get('HTTP_REFERER');
$fake_request = Request::create($previousUrl);
$url_object = \Drupal::service('path.validator')->getUrlIfValid($fake_request->getRequestUri());
if ($url_object) {
$route_name = $url_object->getRouteName();
// Do something with $route_name;