Skip to content

Instantly share code, notes, and snippets.

View slivorezka's full-sized avatar

Andriy Malyeyev slivorezka

View GitHub Profile
@slivorezka
slivorezka / memcache.php
Last active December 7, 2018 14:16
Memcache
if (class_exists('Memcached', FALSE)) {
$class_loader->addPsr4('Drupal\\memcache\\', 'modules/contrib/memcache/src');
$settings['bootstrap_container_definition'] = [
'parameters' => [],
'services' => [
'settings' => [
'class' => 'Drupal\Core\Site\Settings',
'factory' => 'Drupal\Core\Site\Settings::getInstance',
],
$values = FieldConfig::loadByName('node', 'BUNDLE', 'FIELD')->getSetting('allowed_values');
@slivorezka
slivorezka / TestAjaxFormSelect.php
Created September 21, 2018 07:32 — forked from jez500/TestAjaxFormSelect.php
Drupal 8 Ajax form example when select box changed
<?php
namespace Drupal\my_module\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class TestAjaxFormSelect.
*/
@slivorezka
slivorezka / AddAnotherItem.php
Created September 21, 2018 07:32 — forked from leymannx/AddAnotherItem.php
Drupal 8 Ajax Form Add Item Example
<?php
/**
* @file
* Contains \Drupal\hello_world\Form\AddAnotherItem.
*/
namespace Drupal\hello_world\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
@slivorezka
slivorezka / drupal_8_most_useful_service.php
Last active September 11, 2018 05:12
Drupal 8: Most useful services
<?php
use Drupal\Core\Menu\MenuLinkTreeInterface;
use Drupal\Core\Menu\MenuTreeParameters;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The menu link tree service.
*
* @var \Drupal\Core\Menu\MenuLinkTree
@slivorezka
slivorezka / default.vcl
Created August 17, 2018 08:16
Drupal 8 Varnish
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.
@slivorezka
slivorezka / localhost_sendmail
Created August 15, 2018 08:25
PHP Stopper for testing email notification in the localhost
Step #1
Cretae file in the next path /usr/bin/localhost_sendmail
Step #2
Add to the new file this below content:
#!/bin/sh
prefix="/var/mail/sendmail"
@slivorezka
slivorezka / composer.json
Created August 2, 2018 07:58
Drupal 8: composer.json
{
"name": "drupal/drupal",
"description": "Drupal is an open source content management platform powering millions of websites and applications.",
"type": "project",
"license": "GPL-2.0-or-later",
"require": {
"composer/installers": "^1.0.24",
"wikimedia/composer-merge-plugin": "^1.4",
"cweagans/composer-patches": "^1.6",
"symfony/var-dumper": "3.*",
@slivorezka
slivorezka / hook_preprocess_views_view_field.php
Created March 22, 2018 13:37
hook_preprocess_views_view_field
<?php
/**
* Implements hook_preprocess_views_view_field().
*/
function MODULE_preprocess_views_view_field(&$variables) {
/** @var \Drupal\views\ViewExecutable $view */
$view = $variables['view'];
if ($view->id() == 'schedule') {
if ($view->current_display == 'embed_1') {
@slivorezka
slivorezka / drupal8_reser_weigh_for_all_terms.php
Created March 21, 2018 15:29
Drupal 8: Reset weigh for all terms
<?php
$manager = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$tree = $manager->loadTree('VOC_NAME', 0, 0, TRUE);
foreach ($tree as $term) {
$term->setWeight(0);
$term->save();
}