Created
November 7, 2013 12:58
-
-
Save vdchristelle/7354195 to your computer and use it in GitHub Desktop.
Events standalone module
- creates CT
- creates dummy content
- creates latest & overview block NOTE!!!! You need to make a folder 'inc' and put the inc files in there
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //--------------------- | |
| //---- EVENTS --------- | |
| //--------------------- | |
| // Latest events | |
| .events.latest { | |
| background: $grey-light; | |
| padding: rhythm(0.5); | |
| img { | |
| margin: 0 rhythm(0.25) rhythm(0.25) 0; | |
| float: left; | |
| } | |
| } | |
| // Full view | |
| .node-type-events { | |
| p.colorbox { | |
| margin: 0 rhythm(0.25) rhythm(0.25) 0; | |
| float: left; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .events.latest { | |
| background: #eeeeee; | |
| padding: 0.85714em; | |
| } | |
| .events.latest img { | |
| margin: 0 0.42857em 0.42857em 0; | |
| float: left; | |
| } | |
| .node-type-events p.colorbox { | |
| margin: 0 0.42857em 0.42857em 0; | |
| float: left; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // create a printable attributes array | |
| $references_overview_attributes = array( | |
| 'class' => array('events', 'overview'), | |
| ); | |
| $num_items = count($variables['items']); | |
| $i = 0; | |
| ?> | |
| <ul<?php print drupal_attributes($references_overview_attributes) ?>> | |
| <?php foreach ($variables['items'] as $item): | |
| $i++; | |
| // Add classes. | |
| $attributes = array(); | |
| if($i == 1){ | |
| $attributes['class'][] = 'first'; | |
| } | |
| $attributes['class'][] = $i % 2 ? 'odd' : 'even'; | |
| if($i%3 == 0) { | |
| $attributes['class'][] = 'third'; | |
| } | |
| if($i%4== 0) { | |
| $attributes['class'][] = 'fourth'; | |
| } | |
| if($i == $num_items){ | |
| $attributes['class'][] = 'last'; | |
| } | |
| ?> | |
| <li<?php print drupal_attributes($attributes); ?>><?php print render($item) ?></li> | |
| <?php endforeach; ?> | |
| </ul> | |
| <?php | |
| if ($variables['pager'] != NULL) { | |
| print theme('pager'); | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // create a printable attributes array | |
| $events_overview_attributes = array( | |
| 'class' => array('events', 'latest'), | |
| ); | |
| ?> | |
| <ul<?php print drupal_attributes($events_overview_attributes) ?>> | |
| <?php foreach ($variables['items'] as $item): ?> | |
| <li><?php print render($item) ?></li> | |
| <?php endforeach; ?> | |
| </ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //function _ds_include_config_events() { | |
| if (defined('EVENTS_CT_NAME')) { | |
| $EVENTS_CT_NAME = EVENTS_CT_NAME; | |
| } | |
| else { | |
| $EVENTS_CT_NAME = 'events'; | |
| } | |
| //---------------------- | |
| //-- DEFAULT SETTINGS -- | |
| //---------------------- | |
| // field settings | |
| $ds_default_field = array( | |
| 'id' => 'node|' . $EVENTS_CT_NAME . '|default', | |
| 'entity_type' => 'node', | |
| 'bundle' => $EVENTS_CT_NAME, | |
| 'view_mode' => 'default', | |
| ); | |
| $ds_default_field_settings = array( | |
| 'body' => array( | |
| 'formatter_settings' => array( | |
| 'ft' => array( | |
| 'func' => 'theme_ds_field_expert', | |
| ), | |
| ), | |
| ), | |
| 'image' => array( | |
| 'formatter_settings' => array( | |
| 'ft' => array( | |
| 'func' => 'theme_ds_field_expert', | |
| 'fis' => TRUE, | |
| 'fis-el' => 'p', | |
| 'fis-cl' => 'colorbox', | |
| 'fis-at' => '', | |
| 'fis-def-at' => FALSE | |
| ), | |
| ), | |
| ), | |
| ); | |
| $ds_default_field['settings'] = serialize($ds_default_field_settings); | |
| db_insert('ds_field_settings') | |
| ->fields($ds_default_field) | |
| ->execute(); | |
| // layout settings | |
| $ds_default_layout = array( | |
| 'id' => 'node|' . $EVENTS_CT_NAME . '|default', | |
| 'entity_type' => 'node', | |
| 'bundle' => $EVENTS_CT_NAME, | |
| 'view_mode' => 'default', | |
| 'layout' => 'ds_reset' | |
| ); | |
| $ds_default_layout_settings = array( | |
| 'regions' => array( | |
| 'ds_content' => array('body', 'image'), | |
| ), | |
| 'fields' => array( | |
| 'body' => 'ds_content', | |
| 'image' => 'ds_content', | |
| ), | |
| 'classes' => array(), | |
| 'wrappers' => array( | |
| 'ds_content' => "div", | |
| ), | |
| 'layout_wrapper' => "", | |
| 'layout_attributes' => "", | |
| 'layout_attributes_merge' => TRUE | |
| ); | |
| $ds_default_layout['settings'] = serialize($ds_default_layout_settings); | |
| db_insert('ds_layout_settings') | |
| ->fields($ds_default_layout) | |
| ->execute(); | |
| //--------------------- | |
| //-- TEASER SETTINGS -- | |
| //--------------------- | |
| // field settings | |
| $ds_teaser_field['id'] = "node|" . $EVENTS_CT_NAME . "|teaser"; | |
| $ds_teaser_field['entity_type'] = 'node'; | |
| $ds_teaser_field['bundle'] = $EVENTS_CT_NAME; | |
| $ds_teaser_field['view_mode'] = 'teaser'; | |
| $ds_teaser_field_settings = array( | |
| 'title' => array( | |
| 'weight' => 0, | |
| 'label' => 'hidden', | |
| 'format' => 'default', | |
| 'formatter_settings' => array( | |
| 'link' => 1, | |
| 'wrapper' => "h2", | |
| 'class' => "", | |
| 'ft' => array( | |
| 'func' => 'theme_ds_field_expert', | |
| ), | |
| ), | |
| ), | |
| 'node_link' => array( | |
| 'weight' => 3, | |
| 'label' => 'hidden', | |
| 'format' => 'default', | |
| 'formatter_settings' => array( | |
| 'link text' => "Read more", | |
| 'wrapper' => "", | |
| 'class' => "", | |
| 'ft' => array( | |
| 'func' => 'theme_ds_field_expert', | |
| 'fis' => TRUE, | |
| 'fis-el' => "p", | |
| 'fis-cl' => "more", | |
| 'fis-at' => "", | |
| 'fis-def-at' => FALSE, | |
| ), | |
| ), | |
| ), | |
| 'body' => array( | |
| 'formatter_settings' => array( | |
| 'ft' => array( | |
| 'func' => 'theme_ds_field_expert', | |
| ), | |
| ), | |
| ), | |
| 'image' => array( | |
| 'formatter_settings' => array( | |
| 'ft' => array( | |
| 'func' => 'theme_ds_field_expert', | |
| ), | |
| ), | |
| ), | |
| ); | |
| $ds_teaser_field['settings'] = serialize($ds_teaser_field_settings); | |
| db_insert('ds_field_settings') | |
| ->fields($ds_teaser_field) | |
| ->execute(); | |
| // layout settings | |
| $ds_teaser_layout['id'] = "node|" . $EVENTS_CT_NAME . "|teaser"; | |
| $ds_teaser_layout['entity_type'] = 'node'; | |
| $ds_teaser_layout['bundle'] = $EVENTS_CT_NAME; | |
| $ds_teaser_layout['view_mode'] = 'teaser'; | |
| $ds_teaser_layout['layout'] = 'ds_reset'; | |
| $ds_teaser_layout_settings = array( | |
| 'regions' => array( | |
| 'ds_content' => array('title', 'image', 'body', 'node_link'), | |
| ), | |
| 'fields' => array( | |
| 'title' => 'ds_content', | |
| 'image' => 'ds_content', | |
| 'body' => 'ds_content', | |
| 'node_link' => 'ds_content', | |
| ), | |
| 'limit' => array( | |
| 'image' => 1, | |
| ), | |
| 'classes' => array(), | |
| 'wrappers' => array( | |
| 'ds_content' => 'div', | |
| ), | |
| 'layout_wrapper' => "div", | |
| 'layout_attributes' => "", | |
| 'layout_attributes_merge' => TRUE, | |
| ); | |
| $ds_teaser_layout['settings'] = serialize($ds_teaser_layout_settings); | |
| db_insert('ds_layout_settings') | |
| ->fields($ds_teaser_layout) | |
| ->execute(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name = Events | |
| description = Enables the custom events content with it's own settings | |
| core = 7.x | |
| php = 5.3 | |
| package = the AIM | |
| dependencies[] = field_ui | |
| ;version | |
| version = 7.x-1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Implements hook_install() | |
| */ | |
| function events_install() { | |
| // create the Events content type | |
| _create_events_content_type(); | |
| // set the correct permissions | |
| $permissions = array( | |
| 'create events content', | |
| 'edit own events content', | |
| 'edit any events content', | |
| 'delete own events content', | |
| 'delete any events content' | |
| ); | |
| $roles = user_roles(); | |
| foreach ($roles as $rid => $role) { | |
| if ($role == 'siteowners' || $role == 'copywriters' || $role == 'administrator') { | |
| user_role_grant_permissions($rid, $permissions); | |
| } | |
| } | |
| // create content and adjust settings | |
| $path = drupal_get_path('module', 'events') . "/includes/events.module.config.inc"; | |
| if (file_exists($path)) { | |
| // execute the module settings | |
| include_once($path); | |
| } | |
| } | |
| /** | |
| * Implements hook_uninstall() | |
| */ | |
| function events_uninstall() { | |
| if (defined('EVENTS_CT_NAME')) { | |
| $EVENTS_CT_NAME = EVENTS_CT_NAME; | |
| } else { | |
| $EVENTS_CT_NAME = 'events'; | |
| } | |
| // remove all Events content | |
| $sql = 'SELECT nid FROM {node} n WHERE n.type = :type'; | |
| $result = db_query($sql, array(':type' => $EVENTS_CT_NAME)); | |
| $nids = array(); | |
| foreach ($result as $row) { | |
| $nids[] = $row->nid; | |
| } | |
| if (!empty($nids)) | |
| node_delete_multiple($nids); | |
| // delete the EVENTS content type | |
| node_type_delete($EVENTS_CT_NAME); | |
| // remove the pathauto settings | |
| variable_del('pathauto_node_events_pattern'); | |
| // clear the variable table | |
| variable_del('language_content_type_' . $EVENTS_CT_NAME); | |
| variable_del('menu_options_' . $EVENTS_CT_NAME); | |
| variable_del('menu_parent_' . $EVENTS_CT_NAME); | |
| variable_del('node_options_' . $EVENTS_CT_NAME); | |
| variable_del('node_preview_' . $EVENTS_CT_NAME); | |
| variable_del('node_submitted_' . $EVENTS_CT_NAME); | |
| // block settings | |
| variable_del('events_overview_block_limit'); | |
| variable_del('events_overview_latest_block_limit'); | |
| } | |
| /** | |
| * Create the events content type with it's associated fields | |
| */ | |
| function _create_events_content_type() { | |
| $events_type = array( | |
| 'type' => EVENTS_CT_NAME, | |
| 'name' => st('Events'), | |
| 'base' => 'node_content', | |
| 'description' => st('Add an event to the website.'), | |
| 'custom' => FALSE, | |
| 'modified' => TRUE, | |
| 'locked' => FALSE, | |
| ); | |
| // add a body field | |
| $events_type = node_type_set_defaults($events_type); | |
| node_type_save($events_type); | |
| node_add_body_field($events_type); | |
| // ------------ | |
| // --- MENU --- | |
| // ------------ | |
| variable_set('language_content_type_' . EVENTS_CT_NAME, 0); | |
| variable_set('menu_options_' . EVENTS_CT_NAME, array()); | |
| variable_set('menu_parent_' . EVENTS_CT_NAME, ""); | |
| variable_set('node_options_' . EVENTS_CT_NAME, array('status')); | |
| variable_set('node_preview_' . EVENTS_CT_NAME, 0); | |
| variable_set('node_submitted_' . EVENTS_CT_NAME, 0); | |
| // -------------- | |
| // --- FIELDS --- | |
| // -------------- | |
| $fields = array( | |
| 'image' => array( | |
| 'field_name' => 'image', | |
| 'type' => 'image', | |
| 'locked' => FALSE, | |
| 'cardinality' => FIELD_CARDINALITY_UNLIMITED, | |
| 'translatable' => FALSE, | |
| ), | |
| ); | |
| foreach ($fields as $field) { | |
| if (is_null(field_info_field($field['field_name']))) { | |
| field_create_field($field); | |
| } | |
| } | |
| // ----------------- | |
| // --- INSTANCES --- | |
| // ----------------- | |
| $instances = array( | |
| 'image' => array( | |
| 'field_name' => 'image', | |
| 'label' => t("Image"), | |
| 'required' => FALSE, | |
| // default settings for the image field | |
| 'settings' => array( | |
| 'file_extensions' => 'jpg jpeg', | |
| 'file_directory' => 'events-images', | |
| 'max_resolution' => '2000x2000', | |
| 'max_filesize' => '2 MB', | |
| 'alt_field' => 1, | |
| 'title_field' => 1, | |
| ), | |
| // default display settings for the image field | |
| 'display' => array( | |
| 'default' => array( | |
| 'label' => 'hidden', | |
| 'settings' => array( | |
| 'image_style' => 'thumbnail', | |
| 'image_link' => 'file', | |
| ), | |
| ), | |
| 'teaser' => array( | |
| 'label' => 'hidden', | |
| 'settings' => array( | |
| 'image_style' => 'thumbnail', | |
| 'image_link' => 'content', | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| foreach ($instances as $instance) { | |
| if (is_null(field_info_instance('node', $instance['field_name'], EVENTS_CT_NAME))) { | |
| $instance['entity_type'] = 'node'; | |
| $instance['bundle'] = EVENTS_CT_NAME; | |
| field_create_instance($instance); | |
| } | |
| } | |
| // ---------------- | |
| // --- PATHAUTO --- | |
| // ---------------- | |
| if (module_exists('pathauto')) { | |
| variable_set('pathauto_node_' . EVENTS_CT_NAME . '_pattern', EVENTS_CT_NAME . '/[node:title]'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // get a list of enabled languages | |
| $enabled_languages = _check_enabled_languages(); | |
| if (module_exists('pathauto')) { | |
| $prefix_pattern = array( | |
| 'en' => 'events', | |
| 'nl' => 'evenementen', | |
| 'fr' => 'événements', | |
| 'de' => 'events', | |
| ); | |
| $default_language = variable_get('language_default', (object) array('language' => 'nl')); | |
| // set the default fallback events path pattern | |
| variable_set("pathauto_node_events_pattern", $prefix_pattern[$default_language->language] . "/[node:title]"); | |
| if (module_exists('i18n_path')) { | |
| foreach (array_keys($enabled_languages) as $enabled_language) { | |
| variable_set("pathauto_node_events_{$enabled_language}_pattern", $prefix_pattern[$enabled_language] . "/[node:title]"); | |
| } | |
| } | |
| } | |
| // create the default events overview page | |
| $menu_name = 'main-menu'; | |
| $dummy_text = random_lipsum(1, 'paras', TRUE); | |
| $type = 'page'; | |
| $source = array( | |
| 'en' => array( | |
| 'title' => 'Events', | |
| 'type' => $type, | |
| 'menu-item' => array( | |
| 'weight' => 1, | |
| 'menu_name' => $menu_name, | |
| ), | |
| 'fields' => array( | |
| 'body' => array( | |
| 'value' => $dummy_text, | |
| 'format' => 'full_html', | |
| ), | |
| ), | |
| ), | |
| 'nl' => array( | |
| 'title' => 'Evenementen', | |
| 'type' => $type, | |
| 'menu-item' => array( | |
| 'weight' => 1, | |
| 'menu_name' => $menu_name, | |
| ), | |
| 'fields' => array( | |
| 'body' => array( | |
| 'value' => $dummy_text, | |
| 'format' => 'full_html', | |
| ), | |
| ), | |
| ), | |
| 'fr' => array( | |
| 'title' => 'Evénements', | |
| 'type' => $type, | |
| 'menu-item' => array( | |
| 'weight' => 1, | |
| 'menu_name' => $menu_name, | |
| ), | |
| 'fields' => array( | |
| 'body' => array( | |
| 'value' => $dummy_text, | |
| 'format' => 'full_html', | |
| ), | |
| ), | |
| ), | |
| 'de' => array( | |
| 'title' => 'Events', | |
| 'type' => $type, | |
| 'menu-item' => array( | |
| 'weight' => 1, | |
| 'menu_name' => $menu_name, | |
| ), | |
| 'fields' => array( | |
| 'body' => array( | |
| 'value' => $dummy_text, | |
| 'format' => 'full_html', | |
| ), | |
| ), | |
| ), | |
| ); | |
| $events_pages = createContent($source); | |
| // create dummy events items | |
| $dummy_text = random_lipsum(1, 'paras', TRUE); | |
| $type = 'events'; | |
| for ($i = 1; $i <= 5; $i++) { | |
| $source = array( | |
| 'en' => array( | |
| 'title' => "Event {$i}", | |
| 'type' => $type, | |
| 'fields' => array( | |
| 'body' => array( | |
| 'value' => $dummy_text, | |
| 'format' => 'full_html', | |
| ), | |
| ), | |
| ), | |
| 'nl' => array( | |
| 'title' => "Evenement {$i}", | |
| 'type' => $type, | |
| 'fields' => array( | |
| 'body' => array( | |
| 'value' => $dummy_text, | |
| 'format' => 'full_html', | |
| ), | |
| ), | |
| ), | |
| 'fr' => array( | |
| 'title' => "Evénement {$i}", | |
| 'type' => $type, | |
| 'fields' => array( | |
| 'body' => array( | |
| 'value' => $dummy_text, | |
| 'format' => 'full_html', | |
| ), | |
| ), | |
| ), | |
| 'de' => array( | |
| 'title' => "Event {$i}", | |
| 'type' => $type, | |
| 'fields' => array( | |
| 'body' => array( | |
| 'value' => $dummy_text, | |
| 'format' => 'full_html', | |
| ), | |
| ), | |
| ), | |
| ); | |
| createContent($source); | |
| } | |
| // update the block information in the database | |
| $theme = variable_get('theme_default', 'bartik'); | |
| // step 1: delete the existing db entries | |
| db_delete('block') | |
| ->condition('delta', array('events_overview', 'events_overview_latest'), 'in') | |
| ->condition('module', 'events') | |
| ->execute(); | |
| // step 2: insert the new block information | |
| // add the events block to the enabled languages events page only | |
| foreach ($events_pages as &$events_page) { | |
| $events_page = "node/{$events_page}"; | |
| } | |
| $module = 'events'; | |
| $block_info = array( | |
| array( | |
| 'module' => $module, | |
| 'delta' => 'events_overview', | |
| 'theme' => $theme, | |
| 'status' => 1, | |
| 'weight' => 1, | |
| 'region' => 'content_bottom', | |
| 'visibility' => BLOCK_VISIBILITY_LISTED, | |
| 'pages' => implode(PHP_EOL, array_intersect_key($events_pages, $enabled_languages)), | |
| 'title' => '<none>', | |
| 'cache' => -1, | |
| ), | |
| array( | |
| 'module' => $module, | |
| 'delta' => 'events_overview_latest', | |
| 'theme' => $theme, | |
| 'status' => 1, | |
| 'weight' => 1, | |
| 'region' => 'content_bottom', | |
| 'visibility' => BLOCK_VISIBILITY_LISTED, | |
| 'pages' => '<front>', | |
| 'title' => '<none>', | |
| 'cache' => -1, | |
| ) | |
| ); | |
| foreach ($block_info as $info) { | |
| db_insert('block') | |
| ->fields($info) | |
| ->execute(); | |
| } | |
| // add default classes to block | |
| _events_update_block_class($module, 'events_overview', '<none>'); | |
| // add default translation settings to content types | |
| if (module_exists('translation')) { | |
| variable_set('language_content_type_events', 2); | |
| if (module_exists('i18n_node')) { | |
| variable_set('i18n_node_extended_events', 12); | |
| variable_set('i18n_node_options_events', array( | |
| 'required', 'lock' | |
| )); | |
| } | |
| } | |
| if (module_exists('xmlsitemap')) { | |
| variable_set('xmlsitemap_settings_node_events', array( | |
| 'status' => '1', | |
| 'priority' => '0.5', | |
| ) | |
| ); | |
| } | |
| // display suite settings | |
| if (module_exists('ds_extras') && variable_get('ds_extras_field_template', FALSE) === 1) { | |
| _ds_include_config('events'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // @var CONST String EVENTS_CT_NAME | |
| // the machine name for the events content type | |
| define('EVENTS_CT_NAME', 'events'); | |
| /** | |
| * Implements hook_block_info() | |
| */ | |
| function events_block_info() { | |
| return array( | |
| 'events_overview' => array( | |
| 'info' => "Full (paged) events overview", | |
| ), | |
| 'events_overview_latest' => array( | |
| 'info' => "Latest events overview" | |
| ), | |
| ); | |
| } | |
| /** | |
| * Implements hook_block_view() | |
| */ | |
| function events_block_view($delta = '') { | |
| switch ($delta) { | |
| case 'events_overview': | |
| return array( | |
| 'subject' => '', | |
| 'content' => _events_overview_content(), | |
| ); | |
| case 'events_overview_latest': | |
| return array( | |
| 'subject' => '', | |
| 'content' => _events_overview_latest_content(), | |
| ); | |
| } | |
| } | |
| /** | |
| * Implements hook_block_configure() | |
| */ | |
| function events_block_configure($delta = '') { | |
| switch ($delta) { | |
| case 'events_overview': | |
| $form['events_overview_block_limit'] = array( | |
| '#type' => 'textfield', | |
| '#title' => t("Limit the number of items to"), | |
| '#default_value' => variable_get('events_overview_block_limit', 12), | |
| ); | |
| return $form; | |
| case 'events_overview_latest': | |
| $form['events_overview_latest_block_limit'] = array( | |
| '#type' => 'textfield', | |
| '#title' => t("Limit the number of items to"), | |
| '#default_value' => variable_get('events_overview_latest_block_limit', 2), | |
| ); | |
| return $form; | |
| } | |
| } | |
| /** | |
| * Implements hook_block_save() | |
| */ | |
| function events_block_save($delta = '', $edit = array()) { | |
| switch ($delta) { | |
| case 'events_overview': | |
| variable_set('events_overview_block_limit', $edit['events_overview_block_limit']); | |
| break; | |
| case 'events_overview_latest': | |
| variable_set('events_overview_latest_block_limit', $edit['events_overview_latest_block_limit']); | |
| break; | |
| } | |
| } | |
| function events_theme() { | |
| return array( | |
| 'events_item_overview' => array( | |
| 'template' => 'events-item-overview', | |
| 'variables' => array( | |
| 'items' => NULL, | |
| 'pager' => NULL, | |
| ), | |
| ), | |
| 'events_item_latest' => array( | |
| 'template' => 'events-item-latest', | |
| 'variables' => array( | |
| 'items' => NULL, | |
| ), | |
| ), | |
| ); | |
| } | |
| /** | |
| * fetch the events items and ready them for rendering | |
| * | |
| * @global Object $language | |
| * @return Array | |
| * a renderable array with node elements | |
| */ | |
| function _events_overview_content() { | |
| $query = db_select('node', 'n')->extend('PagerDefault') | |
| ->condition('type', EVENTS_CT_NAME, '=') | |
| ->condition('status', (int) TRUE, '=') | |
| ->fields('n', array('nid')) | |
| ->limit(variable_get('events_overview_block_limit', 12)) | |
| ->orderBy('created', 'desc'); | |
| // check if there should be filtered by language | |
| if (module_exists('i18n_node')) { | |
| global $language; | |
| $query->condition('language', $language->language, '='); | |
| } | |
| $results = $query->execute(); | |
| $nids = array(); | |
| foreach ($results as $result) { | |
| $nids[] = $result->nid; | |
| } | |
| $nodes = node_load_multiple($nids); | |
| $items = node_view_multiple($nodes, 'teaser'); | |
| foreach (array_keys($items['nodes']) as $key) { | |
| if (!is_numeric($key)) { | |
| unset($items['nodes'][$key]); | |
| } | |
| } | |
| // return a renderable array | |
| return array( | |
| '#theme' => 'events_item_overview', | |
| '#items' => $items['nodes'], | |
| '#pager' => theme('pager'), | |
| ); | |
| } | |
| /** | |
| * fetch the latest events items and ready them for rendering | |
| * | |
| * @global Object $language | |
| * @return Array | |
| * a renderable array with node elements | |
| */ | |
| function _events_overview_latest_content() { | |
| $query = db_select('node', 'n') | |
| ->condition('type', EVENTS_CT_NAME, '=') | |
| ->condition('status', (int) TRUE, '=') | |
| ->fields('n', array('nid')) | |
| ->range(0, variable_get('events_overview_latest_block_limit', 2)) | |
| ->orderBy('created', 'desc'); | |
| // check if there should be filtered by language | |
| if (module_exists('i18n_node')) { | |
| global $language; | |
| $query->condition('language', $language->language, '='); | |
| } | |
| $results = $query->execute(); | |
| $nids = array(); | |
| foreach ($results as $result) { | |
| $nids[] = $result->nid; | |
| } | |
| $nodes = node_load_multiple($nids); | |
| $items = node_view_multiple($nodes, 'teaser'); | |
| foreach (array_keys($items['nodes']) as $key) { | |
| if (!is_numeric($key)) { | |
| unset($items['nodes'][$key]); | |
| } | |
| } | |
| return array( | |
| '#theme' => 'events_item_latest', | |
| '#items' => $items['nodes'], | |
| ); | |
| } | |
| /** | |
| * Add a classes string to a requested block | |
| * | |
| * @param string $module | |
| * the module which created the block | |
| * @param string $delta | |
| * the delta (name) of the block | |
| * @param string $class | |
| * the class that has to be added | |
| */ | |
| function _events_update_block_class($module, $delta, $class = '') { | |
| // because there is a 'bug' / 'issue' with the block update function | |
| // first delete the existing block | |
| // add the block again with the new information | |
| if (!empty($class)) { | |
| db_update('block') | |
| ->fields(array( | |
| 'css_class' => $class, | |
| )) | |
| ->condition('module', $module) | |
| ->condition('delta', $delta) | |
| ->execute(); | |
| } | |
| } | |
| /** | |
| * Include display suite settings for the requested module | |
| * | |
| * @param string $module | |
| * the name of the module of which the display suite settings shoulde be | |
| * included | |
| */ | |
| function _ds_include_config($module) { | |
| // check if the required settings are set | |
| if (module_exists('ds_extras') && variable_get('ds_extras_field_template', (int) FALSE) === (int) TRUE) { | |
| // check if there are display suite settings for the module | |
| $file = drupal_get_path('module', 'events') . "/includes/events.ds.config.inc"; | |
| if (file_exists($file)) { | |
| include_once($file); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment