Skip to content

Instantly share code, notes, and snippets.

View svetlio's full-sized avatar

Svetoslav Stoyanov svetlio

View GitHub Profile
@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 / .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 / 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 / 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 / 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);
}