Skip to content

Instantly share code, notes, and snippets.

View svetlio's full-sized avatar

Svetoslav Stoyanov svetlio

View GitHub Profile
@svetlio
svetlio / drupal-site-vhost.conf
Last active October 17, 2026 08:02
Apache2 virtual host config (particular) for a Drupal (11) website serving content for four different js (angular and react) front-ends on difernt subdomains.
<IfModule mod_headers.c>
# Header always set Access-Control-Allow-Origin "*" - Do not use this.
SetEnvIf Origin "^https://(picframe|ovrly|photo-up|abuseip-chart)\.d-support\.eu$" ORIGIN=$0
Header onsuccess unset Access-Control-Allow-Origin
Header always unset Access-Control-Allow-Origin
Header always set Access-Control-Allow-Origin %{ORIGIN}e env=ORIGIN
</IfModule>
@svetlio
svetlio / FileUpdateOrientationAction.php
Created July 5, 2026 07:12
VBO action to update photo orientation by EXIF data for media Image files. Install Drupal module exif_orientation to do this for new files.
<?php
namespace Drupal\custom_fs\Plugin\Action;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Annotation\Action;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
@svetlio
svetlio / ImageStyledResource.php
Created July 5, 2026 05:26
Rest resource, GET image file in desired "Image style", by file id route parameter, and image_style_name url query parameter
<?php
declare(strict_types=1);
namespace Drupal\custom_fs\Plugin\rest\resource;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\rest\Attribute\RestResource;
use Drupal\rest\Plugin\ResourceBase;
@svetlio
svetlio / module_name.post_update.php
Last active February 13, 2024 14:20
post_update batch
<?php
/**
* Update existing nodes cp property to false.
*/
function uneo_pcf_cp_post_update_node_cp_prop(&$sandbox) {
$entity_type_id = 'node';
$id_name = 'nid';
_update_entity_cp_property($sandbox, $entity_type_id, $id_name);
}
@svetlio
svetlio / ImportConfigForm.php
Last active February 13, 2024 14:21
Import from module config/optional
<?php
// ...
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$module_path = $this->extensionListModule->getPath('cpct_config');
@svetlio
svetlio / post-receive
Created January 28, 2020 09:21
post-receive script in bare repo hooks to pre-populate code in web-server dir
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [[ "d881" == "$branch" ]]; then
git --work-tree=/var/www/vhosts/fwi.stage/ checkout -f $branch
echo 'Changes pushed d881 branch to fwi.stage'
@svetlio
svetlio / .htaccess
Last active December 19, 2019 21:07
apache2 redirect to https with www (https:/www.)
# source: https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
# To redirect all users to access the site WITH the 'https://www.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
@svetlio
svetlio / EntityReferenceLabelCustomPathFormatter.php
Last active January 17, 2019 06:32
Field formatter for entity reference label to set link to custom controller or views. Used with terms, !!! not tested for another entities.
<?php
namespace Drupal\tools_ext\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceLabelFormatter;
use Drupal\Core\Url;
use Drupal\Component\Serialization\Json;
@svetlio
svetlio / ManageVocabulariesController.php
Created January 16, 2019 13:16
Manage vocabularies page to show vocabularies translation in other languages too.
<?php
namespace Drupal\tools_ext\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
$view = new view();
$view->name = 'files';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'file_managed';
$view->human_name = 'Files';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */