Created
October 30, 2013 21:18
-
-
Save vdchristelle/7240451 to your computer and use it in GitHub Desktop.
Custom functionality for Soloya:
- promoted to frontpage block with icons
- taxonomy menu block with icons
- 3rd level menu block with icons
- testimonial overview and footer teaser block
- sidebar icon block wich displays field_icon of the node
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 | |
| $max = count(element_children($nodes)); | |
| // Set up striping values. | |
| $count = 0; | |
| ?> | |
| <div class="overview icon-view subpages"> | |
| <ul> | |
| <?php foreach ($nodes as $node) { | |
| $count++; | |
| $attributes = array(); | |
| $attributes['class'][] = 'colorcode-'.$node->nid; | |
| $attributes['class'][] = '' . ($count % 2 ? 'odd' : 'even'); | |
| if ($count % 3 == 0) { | |
| $attributes['class'][] = 'third'; | |
| } | |
| if ($count % 4 == 0) { | |
| $attributes['class'][] = 'fourth'; | |
| } | |
| ?> | |
| <?php | |
| $path = drupal_get_path_alias('node/'.$node->nid); | |
| if( isset($node->field_icon['und'][0]['uri']) && !empty($node->field_icon['und'][0]['uri'])){ | |
| $image_style = image_style_url('icon', $node->field_icon['und'][0]['uri']); | |
| } else { | |
| $uri = 'public://icons/'.'default-icon-512.png'; | |
| $image_style = image_style_url('icon', $uri); | |
| } | |
| ?> | |
| <li <?php print drupal_attributes($attributes); ?>> | |
| <?php print '<img src="'.$image_style.'"/>'; ?> | |
| <?php print '<a href="/'.$path.'">'.$node->title.'</a>'; ?> | |
| <?php print '<h2>'.$node->title.'</h2>'; ?> | |
| </li> | |
| <?php } ?> | |
| </ul> | |
| </div> |
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 | |
| $max = count(element_children($nodes)); | |
| // Set up striping values. | |
| $count = 0; | |
| ?> | |
| <div class="overview icon-view homepage"> | |
| <ul> | |
| <?php foreach ($nodes as $node) { | |
| $count++; | |
| $attributes = array(); | |
| $attributes['class'][] = 'colorcode-'.$node->nid; | |
| $attributes['class'][] = '' . ($count % 2 ? 'odd' : 'even'); | |
| if ($count % 3 == 0) { | |
| $attributes['class'][] = 'third'; | |
| } | |
| if ($count % 4 == 0) { | |
| $attributes['class'][] = 'fourth'; | |
| } | |
| ?> | |
| <?php | |
| $path = drupal_get_path_alias('node/'.$node->nid); | |
| $image_style = image_style_url('icon', $node->field_icon['und'][0]['uri']); | |
| ?> | |
| <li <?php print drupal_attributes($attributes); ?>> | |
| <?php print '<img src="'.$image_style.'"/>'; ?> | |
| <?php print '<a href="'.$path.'">'.$node->title.'</a>'; ?> | |
| <?php print '<h2>'.$node->title.'</h2>'; ?> | |
| </li> | |
| <?php } ?> | |
| </ul> | |
| </div> |
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 | |
| $max = count(element_children($nodes)); | |
| // Set up striping values. | |
| $count = 0; | |
| ?> | |
| <ul class="overview testimonials"> | |
| <?php foreach (element_children($nodes) as $node) { | |
| $count++; | |
| $attributes = array(); | |
| $attributes['class'][] = '' . ($count % 2 ? 'odd' : 'even'); | |
| if ($count % 3 == 0) { | |
| $attributes['class'][] = 'third'; | |
| } | |
| if ($count % 4 == 0) { | |
| $attributes['class'][] = 'fourth'; | |
| } | |
| ?> | |
| <li <?php print drupal_attributes($attributes); ?>><?php print render($nodes[$node]); ?></li> | |
| <?php } ?> | |
| </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
| name = "the AIM custom" | |
| description = "Custom module - by the AIM" | |
| package = "the AIM" | |
| core = 7.x |
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 | |
| /** | |
| * Implementation of hook_help(). | |
| */ | |
| function the_aim_custom_help($path, $arg) { | |
| switch ($path) { | |
| case 'admin/help#the_aim_custom': | |
| $output = '<h3>' . t('Custom functionality') . '</h3>'; | |
| $output .= '<ul>'; | |
| $output .= '<li>Custom topimage block</li>'; | |
| $output .= '<li>Custom homepage block with icons on <a href="/">homepage</a></li>'; | |
| $output .= '<li>Custom taxonomy menu block on <a href="/taxonomy/term/1">realisaties</a></li>'; | |
| $output .= '<li>Custom testimonials overview block on <a href="/node/36">getuigenissen</a></li>'; | |
| $output .= '<li>Custom testimonials footer block</li>'; | |
| $output .= '<li>Custom subpages menu block with icons on <a href="/node/53">waterpompen/systemen</a></li>'; | |
| $output .= '<li>Adds bulk operation to admin page content for updating the author to \'siteowner\'</li>'; | |
| $output .= '</ul>'; | |
| $output .= '<p>Before you go nuts on trying to find where the output is generated, check the custom tpl files in the_aim_custom module ;)<br />or go hastle Xelle with your questions...</p>'; | |
| return $output; | |
| } | |
| } | |
| /** | |
| * Implementation of hook_block_info(). | |
| */ | |
| function the_aim_custom_block_info() { | |
| $blocks = array(); | |
| // topimage | |
| $blocks['topimage'] = array( | |
| 'info' => t('Topimage'), | |
| ); | |
| $blocks['sidebar-icon'] = array( | |
| 'info' => t('Sidebar icon'), | |
| ); | |
| // back to overview | |
| $blocks['back-to-overview'] = array( | |
| 'info' => t('Back to overview'), | |
| ); | |
| // Testimonials overview | |
| $blocks['testimonial-overview'] = array( | |
| 'info' => t('Testimonial overview'), | |
| ); | |
| // Testimonials footer | |
| $blocks['testimonial-footer'] = array( | |
| 'info' => t('Testimonial footer'), | |
| ); | |
| // Homepage overview | |
| $blocks['homepage-overview'] = array( | |
| 'info' => t('Homepage overview'), | |
| ); | |
| // subpages block | |
| $blocks['subpages'] = array( | |
| 'info' => t('Subpages'), | |
| ); | |
| return $blocks; | |
| } | |
| /** | |
| * Implementation of hook_block_view(). | |
| */ | |
| function the_aim_custom_block_view($delta='') { | |
| $block = array(); | |
| global $language; | |
| switch ($delta) { | |
| case 'topimage': | |
| $block['subject'] = t('Topimage'); | |
| $block['content'] = _topimage(); | |
| break; | |
| case 'sidebar-icon': | |
| $block['subject'] = t('Sidebar icon'); | |
| $block['content'] = _sidebar_icon(); | |
| break; | |
| case 'back-to-overview': | |
| // for news detail pages | |
| // get url | |
| $path = array_filter(explode('/', $_SERVER['REQUEST_URI'])); | |
| // remove the last item (news detail) | |
| array_pop($path); | |
| // if language is fr remove the first item | |
| if($language->language != 'nl') { | |
| array_shift($path); | |
| } | |
| // get source url | |
| $source = implode('/', $path); | |
| // get the node id for the url | |
| $nodeid = drupal_lookup_path('source', $source); | |
| // make link | |
| $content = l(t('Back to overview'), $nodeid, array('attributes' => array('title' => t('Back to overview')))); | |
| // assign block content | |
| $block['content'] = $content; | |
| break; | |
| case 'testimonial-overview': | |
| $block['subject'] = t('Testimonial overview'); | |
| $block['content'] = _testimonial_overview(); | |
| break; | |
| case 'testimonial-footer': | |
| $block['subject'] = t('Testimonial footer'); | |
| $block['content'] = _testimonial_footer(); | |
| break; | |
| case 'homepage-overview': | |
| $block['subject'] = t('Homepage overview'); | |
| $block['content'] = _homepage_overview(); | |
| break; | |
| case 'subpages': | |
| $block['subject'] = t('Subpages'); | |
| $block['content'] = _subpages(); | |
| break; | |
| } | |
| return $block; | |
| } | |
| /* | |
| * Block Topimage | |
| * content function | |
| */ | |
| function _topimage() { | |
| global $language; | |
| switch(arg(0)){ | |
| case 'node': | |
| $obj = menu_get_object('node',1); | |
| isset($obj->field_topimage['und'][0]['uri']) ? $view_mode = node_view($obj, 'topimage') : $view_mode = false; | |
| break; | |
| case 'taxonomy': | |
| $obj = menu_get_object('taxonomy_term',2); | |
| isset($obj->field_topimage['und'][0]['uri']) ? $view_mode = taxonomy_term_view($obj, 'topimage') : $view_mode = false; | |
| break; | |
| } | |
| if (isset($view_mode) && false != $view_mode) { | |
| return array( | |
| array( | |
| '#theme' => 'topimage', | |
| '#node' => $view_mode, | |
| ), | |
| ); | |
| } | |
| return NULL; | |
| } | |
| /* | |
| * Block Topimage | |
| * content function | |
| */ | |
| function _sidebar_icon() { | |
| global $language; | |
| switch(arg(0)){ | |
| case 'node': | |
| $obj = menu_get_object('node',1); | |
| isset($obj->field_icon['und'][0]['uri']) ? $view_mode = node_view($obj, 'sidebar_icon') : false; | |
| break; | |
| case 'taxonomy': | |
| $obj = menu_get_object('taxonomy_term',2); | |
| isset($obj->field_icon['und'][0]['uri']) ? $view_mode = taxonomy_term_view($obj, 'sidebar_icon') : false; | |
| break; | |
| } | |
| if (isset($view_mode)) { | |
| return array( | |
| array( | |
| '#theme' => 'sidebar-icon', | |
| '#node' => $view_mode, | |
| ), | |
| ); | |
| } | |
| return NULL; | |
| } | |
| /* | |
| * Block Testimonial overview | |
| * content function | |
| */ | |
| function _testimonial_overview() { | |
| global $language; | |
| $query = db_select('node', 'n'); | |
| $node_results = $query->condition('language', $language->language, '=') | |
| ->condition('type', 'testimonial', '=') | |
| ->fields('n', array('nid')) | |
| ->execute(); | |
| if ($node_results) { | |
| $nids = array(); | |
| foreach ($node_results as $node_result) { | |
| $nids[] = $node_result->nid; | |
| } | |
| if (!empty($nids)) { | |
| $nodes = node_load_multiple($nids); | |
| $node_view = node_view_multiple($nodes, 'full'); | |
| return array( | |
| array( | |
| '#theme' => 'overview_testimonial', | |
| '#nodes' => $node_view['nodes'], | |
| ), | |
| ); | |
| ; | |
| } | |
| } | |
| return NULL; | |
| } | |
| /* | |
| * Block Testimonial footer | |
| * content function | |
| */ | |
| function _testimonial_footer() { | |
| global $language; | |
| $query = db_select('node', 'n'); | |
| $node_results = $query->condition('language', $language->language, '=') | |
| ->condition('type', 'testimonial', '=') | |
| ->range(0,1) | |
| ->orderRandom() // Sort by random | |
| ->fields('n', array('nid')) | |
| ->execute(); | |
| if ($node_results) { | |
| $nids = array(); | |
| foreach ($node_results as $node_result) { | |
| $nids[] = $node_result->nid; | |
| } | |
| if (!empty($nids)) { | |
| $nodes = node_load_multiple($nids); | |
| $node_view = node_view_multiple($nodes, 'full'); | |
| return array( | |
| array( | |
| '#theme' => 'overview_testimonial', | |
| '#nodes' => $node_view['nodes'], | |
| ), | |
| ); | |
| ; | |
| } | |
| } | |
| return NULL; | |
| } | |
| /* | |
| * Menu block homepage overview | |
| * content function | |
| */ | |
| function _homepage_overview() { | |
| global $language; | |
| //Get slide nids | |
| $query = db_select('node', 'n'); | |
| $node_results = $query->condition('language', $language->language, '=') | |
| ->condition('type', 'page', '=') | |
| ->condition('promote', 1, '=') | |
| ->fields('n', array('nid')) | |
| ->execute(); | |
| if ($node_results) { | |
| $nids = array(); | |
| foreach ($node_results as $node_result) { | |
| $nids[] = $node_result->nid; | |
| } | |
| if (!empty($nids)) { | |
| $nodes = node_load_multiple($nids); | |
| return array( | |
| array( | |
| '#theme' => 'overview_homepage', | |
| //'#nodes' => $node_view['nodes'], | |
| '#nodes' => $nodes, | |
| ), | |
| ); | |
| ; | |
| } | |
| } | |
| return NULL; | |
| } | |
| /* | |
| * Menu block children | |
| * content function | |
| */ | |
| function _subpages() { | |
| global $language; | |
| $node = menu_get_object(); | |
| $parent = db_select('menu_links', 'm') | |
| ->fields('m', array('mlid')) | |
| ->condition('link_path', 'node/' . $node->nid) | |
| ->execute()->fetchField(); | |
| if (isset($parent) && $parent != 0) { | |
| $children = db_select('menu_links', 'm') | |
| ->fields('m', array('link_path')) | |
| ->condition('plid', $parent) | |
| ->execute()->fetchCol(); | |
| } | |
| if (isset($children) && count($children > 0)) { | |
| $regex = '/([^\/]*)\/([\d]+)/'; | |
| $matches = array(); | |
| foreach($children as $link_path){ | |
| preg_match($regex, $link_path, $matches); | |
| if(isset($matches[2])){ | |
| $node_results[] = $matches[2]; | |
| } | |
| } | |
| } | |
| if (isset($node_results) && $node_results) { | |
| $nids = array(); | |
| foreach ($node_results as $node_result) { | |
| $nids[] = $node_result; | |
| } | |
| if (!empty($nids)) { | |
| $nodes = node_load_multiple($nids); | |
| return array( | |
| array( | |
| '#theme' => 'subpages', | |
| '#nodes' => $nodes, | |
| ), | |
| ); | |
| ; | |
| } | |
| } | |
| return NULL; | |
| } | |
| function the_aim_custom_theme() { | |
| return array( | |
| 'topimage' => array( | |
| 'variables' => array( | |
| 'node' => NULL | |
| ), | |
| 'template' => 'topimage' | |
| ), | |
| 'sidebar-icon' => array( | |
| 'variables' => array( | |
| 'node' => NULL | |
| ), | |
| 'template' => 'sidebar-icon' | |
| ), | |
| 'overview_testimonial' => array( | |
| 'variables' => array( | |
| 'nodes' => NULL | |
| ), | |
| 'template' => 'overview-testimonial' | |
| ), | |
| 'overview_homepage' => array( | |
| 'variables' => array( | |
| 'nodes' => NULL | |
| ), | |
| 'template' => 'overview-homepage' | |
| ), | |
| 'subpages' => array( | |
| 'variables' => array( | |
| 'nodes' => NULL | |
| ), | |
| 'template' => 'block-subpages' | |
| ) | |
| ); | |
| } | |
| /** | |
| * Implements hook_taxonomy_menu_block_tree_alter | |
| */ | |
| function the_aim_custom_taxonomy_menu_block_tree_alter(&$tree, $config) { | |
| switch($config) { | |
| // add icon image to cache of TMB | |
| case '2': | |
| foreach($tree as $tid => $term) { | |
| $termload = taxonomy_term_load($tid); | |
| if(isset($termload->field_icon['und']['0']['uri'])){ | |
| $tree[$tid]['icon'] = $termload->field_icon['und']['0']['uri']; | |
| } | |
| } | |
| break; | |
| } | |
| } | |
| /* | |
| * alter cklink to add language | |
| */ | |
| function the_aim_custom_ckeditor_link_autocomplete_alter(&$results, &$string){ | |
| if ($string !== '') { | |
| $types = ckeditor_link_get_types(); | |
| $results = array(); | |
| foreach ($types as $type) { | |
| $func = $type['module'] .'_ckeditor_link_'. $type['type'] .'_autocomplete'; | |
| if($type['type']=="node"){ | |
| $func="ckeditor_link_ckeditor_link_node_autocomplete_custom"; | |
| } | |
| if (function_exists($func)) { | |
| $results += $func($string); | |
| if (count($results) > 10) { | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| function ckeditor_link_ckeditor_link_node_autocomplete_custom($string) { | |
| $matches = array(); | |
| $node_types = array_keys(array_filter(variable_get('ckeditor_link_autocomplete_node_types', array('- any -' => '- any -')))); | |
| if (count($node_types)) { | |
| //we assume i18n is enabled | |
| global $language; | |
| $db_or = db_or(); | |
| $db_or->condition('n.language', 'und'); | |
| $db_or->condition('n.language', $language->language); | |
| $query = db_select('node', 'n') | |
| ->fields('n', array('nid', 'title','language')) | |
| ->condition('n.title', '%'. db_like($string) .'%', 'LIKE') | |
| ->condition($db_or) | |
| ->orderBy('n.title') | |
| ->orderBy('n.type') | |
| ->range(0, 10) | |
| ->addTag('node_access'); | |
| if (!in_array('- any -', $node_types)) { | |
| $query->condition('n.type', $node_types, 'IN'); | |
| } | |
| $result = $query->execute(); | |
| foreach ($result as $node) { | |
| $matches['node/'. $node->nid] = "TAAL:".$node->language." ".drupal_get_path_alias("node/".$node->nid); | |
| } | |
| } | |
| return $matches; | |
| }_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment