Skip to content

Instantly share code, notes, and snippets.

@init90
init90 / gist:b7ed6dee23fd2232e56c
Created December 20, 2013 20:43
Відновлення паролю в drupal 7 Додати в корінь сайту з назвою наприклад pass.php, тоді виконати його так site.name/?pass='new_pass'
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$admin = user_load(1);
$pass = isset($_GET['pass'])? trim($_GET['pass']): 'pass';
$uid = isset($_GET['uid'])? trim($_GET['uid']): 1;
user_save($admin, array('pass' => $pass));
@init90
init90 / icareix_global.module
Created July 13, 2016 14:16
Drupal 8 programing added empty text for views
/**
* Implements hook_views_pre_view().
*/
function icareix_global_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
if ($view->id() == 'job_list' && $display_id == 'page_1') {
if (\Drupal::currentUser()->hasPermission('add job entities')) {
$url = \Drupal\Core\Url::fromUserInput('/admin/structure/job/add');
$empty = \Drupal::l(t('Add new job'), $url);
$options = array(
drush updatedb --entity-updates - update DB data after entity update.
@init90
init90 / gist:51df1d82fc5d4b4746ee23de247ca5b7
Last active May 5, 2018 21:41
Drupal 8 load image and display itwith preset.
use Drupal\image\Entity\ImageStyle;
$file = \Drupal\file\Entity\File::load(17);
$uri = $file->getFileUri();
$url = ImageStyle::load('small_user_pic')->buildUrl($uri);
@init90
init90 / scratch.txt
Created August 2, 2016 12:55
Drupal 8 delete all entitis for some type
entity_delete_multiple('tracking_log', \Drupal::entityQuery('tracking_log')->execute());
entity_delete_multiple('tracking_service', \Drupal::entityQuery('tracking_service')->execute());
@init90
init90 / eventApi.php
Created August 19, 2016 08:11
Drupal 8 file saving.
$file_data = \Drupal::request()->files->get('ava');
$file = file_get_contents($file_data);
$file = file_save_data($file);
return $file->id();
@init90
init90 / icareix_global.module
Last active May 5, 2018 21:38
Drupal 8, get route name by url.
$url = 'url';
$url_object = \Drupal::service('path.validator')->getUrlIfValid($url);
$route = $url_object->getRouteName();
@init90
init90 / icareix_global.module
Created September 1, 2016 14:58
Drupal 8, clean cache by tag.
// Clean local task cache by tag.
\Drupal\Core\Cache\Cache::invalidateTags(['config:block.block.icareix_local_tasks']);
@init90
init90 / icareix_global.module
Created September 1, 2016 15:00
Drupal 8, get cache tags.
// from entity
$tags = \Drupal::entityTypeManager()->getStorage('job')->load(1)->getCacheTags();
// from views
$tags = \Drupal\views\Entity\View::load('front')->getCacheTags();
@init90
init90 / icareix_global.module
Created September 22, 2016 15:23
Drupal 8 get current route name.
$route_name = \Drupal::service('current_route_match')->getRouteName();