Skip to content

Instantly share code, notes, and snippets.

@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 / 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 October 5, 2016 13:29
Drupal 8, set front page.
\Drupal::configFactory()->getEditable('system.site')->set('page.front', '/job/1')->save();
@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 / 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 / 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
Created October 12, 2016 15:47
Drupal 7, create tabs in hook_menu
function social_links_menu() {
$items['admin/config/system/social_links'] = array(
'title' => 'social_links',
'description' => 'Configure to fit clients needs',
'page callback' => 'drupal_get_form',
'page arguments' => array('social_links_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'social_links.admin.inc',
);
@init90
init90 / template.php
Created November 14, 2016 10:21
drupal 7, get information from module info file.
/**
* Get information from module info file.
*
* @param string $path_to_module
* @param string $module_name
*
* @return array $module_info;
*/
function bartik_get_module_info($path_to_module, $module_name) {
$path_to_info_file = "{$path_to_module}/{$module_name}.info";
@init90
init90 / rdashboards.module
Last active May 5, 2018 21:23
drupal 7, render array link.
$form['full_calendar_link'] = array(
'#type' => 'link',
'#title' => '<i class="fa fa-calendar fa-2x"></i>',
'#href' => 'fc/student-reports/calendar',
'#options' => array(
'html' => TRUE,
'query' => array('assignee' => 'All'),
'attributes' => array(
'title' => t('Full calendar'),
'class' => array('ctools-use-modal'),
@init90
init90 / global.install
Last active May 5, 2018 21:23
Drupal 7, delete all nodes from content type.
$nids = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'quiz')
->execute()
->fetchCol();
node_delete_multiple($nids);