Skip to content

Instantly share code, notes, and snippets.

@init90
init90 / views-view-fields--job_list.html.twig
Created October 10, 2016 14:48
String contantination in twig.
{% set link = "/job/#{fields.id.content}" %}
{% set fll_name = "#{fields.field_first_name.content} #{fields.field_last_name.content}" %}
@init90
init90 / scratch.txt
Last active May 5, 2017 07:54
Drupal 7, Js for close ctools popup
Drupal.CTools.Modal.dismiss();
$form['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#attributes' => array('onClick' => 'Drupal.CTools.Modal.dismiss();'),
);
@init90
init90 / icareix_global.module
Created October 6, 2016 07:29
Drupal, change front page by user role.
/**
* Implements hook_preprocess_block(&$variables).
*/
function icareix_global_preprocess_block(&$variables) {
if ($variables['elements']['#plugin_id'] == 'system_branding_block') {
// Select front page by user role.
$current_user = \Drupal::currentUser();
$current_uid = $current_user->id();
$config = \Drupal::config('icareix_global.FrontPageByRole');
$url = \Drupal::config('system.site')->get('page.front');
@init90
init90 / icareix_global.module
Created October 5, 2016 13:29
Drupal 8, set front page.
\Drupal::configFactory()->getEditable('system.site')->set('page.front', '/job/1')->save();
@init90
init90 / PayPayAPI.php
Created September 29, 2016 09:59
Drupal 8, create absolute URL.
$route = \Drupal::service('current_route_match');
$route_name = $route->getRouteName();
$invoice_id = $route->getRawParameter('invoice');
$invoice_url = \Drupal\Core\Url::fromRoute($route_name, ['invoice' => $invoice_id], ['absolute' => TRUE])->toString();
@init90
init90 / icareix_global.module
Created September 22, 2016 15:49
Drupal 8 get parameters from route
$route = \Drupal::service('current_route_match');
$job_id = $route->getRawParameters()->getInt('job');
@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();
@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 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
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();