Skip to content

Instantly share code, notes, and snippets.

View martin-klima's full-sized avatar

Martin Klíma martin-klima

View GitHub Profile
@martin-klima
martin-klima / deleteAllFilesInsideDirectory.php
Created April 4, 2023 16:07
Delete all files inside of a directory.
/**
* Delete all content inside of given directory.
*
* @param string $folder
* Directory.
*/
public function deleteAllFilesInsideDirectory(string $folder): void {
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($folder, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
@martin-klima
martin-klima / post-receive
Created February 1, 2020 10:12
Drupal 8 automatic deployment git hook with changed config protection
#!/bin/bash
# Script for automatic Drupal 8 deployment with checking current site configuration state.
# If site has any unexported configuration changes, the deployment is not executed.
GIT_DIR="path_to_repo.git"
TARGET="path_to_destination_dir"
BRANCH="production"
while read oldrev newrev ref
@martin-klima
martin-klima / settings.production.php
Created February 1, 2020 09:58
Drupal 8 settings.production.php template
// Include this file into setting.php
$databases['default']['default'] = array (
'database' => '',
'username' => '',
'password' => '',
'prefix' => '',
'host' => 'localhost',
'port' => '',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
@martin-klima
martin-klima / deleteDirectoryContentRecursively.php
Created December 20, 2017 16:38
Drupal 8: Deletes all files and directories in the specified filepath recursively
<?php
/**
* Deletes all files and directories in the specified filepath recursively.
*
* @param $path
* @param bool $deleteDir
* TRUE if you need to delete also directory in $path.
* FALSE if you need to delete only content of dir and its subdirs.
*
* @return bool
@martin-klima
martin-klima / BreadcrumbBuilder.php
Created June 8, 2017 07:31
Drupal 8: Custom breadcrumbs for node with hierarchical taxonomy term reference
<?php
namespace Drupal\breadcrumb;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
@martin-klima
martin-klima / views_query_alter.php
Last active April 27, 2017 16:13
Drupal 7: Views query alter: Display something defined by list with the same sorting order
<?php
/**
* Inject Views filter and sorting.
* We need display something defined (nids) with the same sorting order.
*
* The product list view display contains dummy filter, which is overridden
* in this function.
*
* Implements hook_views_query_alter().
*