Skip to content

Instantly share code, notes, and snippets.

View slivorezka's full-sized avatar

Andriy Malyeyev slivorezka

View GitHub Profile
@slivorezka
slivorezka / implements_hook_uninstall.php
Last active August 29, 2015 14:18
Implements hook_uninstall()
<?php
/**
* Implements hook_uninstall().
*/
function drupal_way_test_uninstall() {
// Remove the all module tables.
drupal_uninstall_schema('drupal_way_test');
// Remove the all module variables.
// variable_del('drupal_way_test_...');
// variable_del('drupal_way_test_...');
function demo_drupal_way_hierarchical_select_form_submit($form, $form_state) {
if ($form_state['triggering_element']['#name'] == 'submit') {
$term_names = array();
foreach ($form_state['values']['items'] as $tid) {
$term = taxonomy_term_load($tid);
if (isset($term->name)) {
$term_names[] = $term->name;
}
}
drupal_set_message(t('You entered the next location: @loc', array('@loc' => implode(', ', $term_names))));
@slivorezka
slivorezka / settings.php
Last active September 17, 2015 09:57
settings.php
<?php // Del the tag.
/**
* Making the Admin menu work!
*/
$conf['admin_menu_cache_client'] = FALSE;
// Share sessions between HTTP and HTTPS hosts.
$conf['https'] = FALSE;
$conf['securepages_enable'] = 0;
// Name of folder in sites.
$sites_folder = 'default';
<?php
/**
* @file
* Install
*/
/**
* Implements hook_uninstall().
*/
function MODULE_uninstall() {
/**
* Include settings.local.php.
*/
if (file_exists(__DIR__ . '/settings.local.php')) {
include __DIR__ . '/settings.local.php';
}
@slivorezka
slivorezka / get_current_router_name.php
Created October 26, 2016 15:35
Drupal 8: get current router name
<?php
// Get current router name.
$current_router = \Drupal::routeMatch()->getRouteName();
@slivorezka
slivorezka / taxonomy _term_tree.php
Created November 7, 2016 09:13
Drupal 8 Get taxonomy term tree By taxonomy vocabulary name ($vid)
<?php
$tree = \Drupal::entityTypeManager()->getStorage('tags')->loadTree('error_code', $parent = 0, $max_depth = NULL, $load_entities = FALSE);
@slivorezka
slivorezka / get_field_value.php
Created November 7, 2016 09:26
Drupal 8 Get field value
<?php
$field_value = $entity->get('field_name')->getString();
@slivorezka
slivorezka / get_image_path_with_image_style.php
Created November 8, 2016 10:40
Drupal 8: Get Image URL / URI with Image Style
<?php
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
// File ID.
$fid = 123;
// Load file.
$file = File::load($fid);
// Get origin image URI.
$image_uri = $file->getFileUri();
// Load image style "thumbnail".
@slivorezka
slivorezka / get_term_by_name.php
Created November 8, 2016 16:24
Drupal 8: Load term by name
<?php
// Load term by name
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => 'some_name']);