Skip to content

Instantly share code, notes, and snippets.

@init90
init90 / gist:50699bc25b27abb3f87fb5d0d7ff170c
Last active May 5, 2018 21:11
drupal 7, change entity paths.
/**
* Implements hook_entity_info_alter().
*/
function cba_events_entity_info_alter(&$entity_info) {
// Update exam events path.
$entity_info['event']['bundles']['exam_event']['crud']['edit']['path'] = 'event/exam/%eckentity/edit';
$entity_info['event']['bundles']['exam_event']['crud']['delete']['path'] = 'event/exam/%eckentity/delete';
// Update default event path.
$entity_info['event']['bundles']['default']['crud']['add']['path'] = 'event/default/add';
@init90
init90 / scratch.txt
Created December 22, 2016 15:38
drupal 7, add date field with popup calendar to custom form.
$form['startdate'] = array(
'#type' => 'date_popup',
'#title' => t('Lesson start date'),
'#timepicker' => 'timepicker',
'#timepicker_options' => array(
'rows' => 6,
'minutes' => array(
'starts' => 0,
'ends' => 56,
'interval' => 4,
@init90
init90 / cba_events.confirm_popup.inc
Created December 22, 2016 13:58
drupal 7, form button for hide ctools popup.
$form['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#attributes' => array('onClick' => 'Drupal.CTools.Modal.dismiss();'),
);
@init90
init90 / gist:cfb51b5943a155536ac1da4dfb5cc12b
Last active May 5, 2018 21:16
Drupal 7, get field allowed values.
$fields = field_info_fields();
$races_list = list_allowed_values($fields['field_race']);
@init90
init90 / scratch.txt
Created December 14, 2016 08:42
drupal 7, views data alter
CREATE TABLE example_table (
nid INT(11) NOT NULL,
plain_text_field VARCHAR(32,
numeric_field INT(11),
boolean_field INT(1),
timestamp_field INT(8),
PRIMARY KEY(nid)
);
function mymodule_views_data() {
@init90
init90 / cba_quiz.module
Last active May 5, 2018 21:22
Drupal 7. Quiz module. Add programality new questions to quiz.
/**
* Create new multichoice questions.
*/
function cba_quiz_new_multichoice_question() {
global $user;
$question = new stdClass();
$question->title = t('Questions template');
$question->type = 'multichoice';
$question->body = array(LANGUAGE_NONE => array(array('value' => t('Your questions text'))));
@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);
@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 / 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 / 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',
);