Drupal 7 https://shivanjaikaran.com/tag/drupal-7 en Upgrading from Drupal 5 to 7 and the XML Sitemap Module https://shivanjaikaran.com/upgrading-drupal-5-7-and-xml-sitemap-module <span>Upgrading from Drupal 5 to 7 and the XML Sitemap Module</span> <span><span>admin</span></span> <span>Tue, 12/17/2013 - 03:26</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>After months of deliberation and procrastination, I have finally found the time to upgrade my own website. It's now running on Drupal 7. I decided to change the theme and keep it simple. A neat layout and also mobile friendly theme is what I was aiming for. Thanks to the many contributors at Drupal, finding a user contributed simple and clean theme was not very hard at all. The hardest part of this upgrade was the <a href="http://drupal.org/project/xmlsitemap" rel="nofollow">XML Sitemap</a> module.</p> <p>Because I went straight from Drupal 5 to Drupal 7, there were some extra steps I had to take to get this module to work. The upgrade path for this module was not a straight forward one however. I must say that I did follow the module's instructions for this upgrade in which they said "If you're upgrading from version 5 to version 7, please use the 5.x-1.7 to 6.x-1.x to 6.x-2.x to 7.x-2.0-rc1 path." This led to me having the latest stable module, but every time I go to the config page for the module I was given a notice error. Even trying to uninstall the module was somewhat impossible. So I was basically stuck with an installed XML sitemap module that I could not uninstall nor use. This seems to be a pretty common problem with this module.</p> <p><strong>The Solution</strong></p> <p>Before you do anything of this nature, it goes without saying that you should BACKUP YOUR DATABASE. I resorted to manually deleting the module's tables and variables from the database. To do this I used PHPMyAdmin and deleted all tables that started with xmlsitemap. I also did the same for each row in the variables table for all variables LIKE %xmlsitemap%. A little dirty hack ain't it? After doing this, I was then able to uninstall the module within the admin interface. Now, finally I could install the module as a fresh install. I know this is not ideal but fortunately, this module does not store a lot of information so I could have afforded to loose that for a fresh install. I hope this post will save someone else from chasing shadows in debugging this problem.</p> </div> <div class="field field--name-taxonomy-vocabulary-2 field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class="field__items"> <div class="field__item"><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div class="field__item"><a href="/tag/drupal-7" hreflang="en">Drupal 7</a></div> <div class="field__item"><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=52&amp;2=comment_node_page&amp;3=comment_node_page" token="tuhQvNM4FpALn8Tm0QxpjjwNLx-mHHUsoIq2dRl2NiA"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Tue, 17 Dec 2013 07:26:51 +0000 admin 52 at https://shivanjaikaran.com Drupal 7: How to add a custom CSS class to the last search result item on the search page https://shivanjaikaran.com/drupal-7-how-add-custom-css-class-last-search-result-item-search-page <span>Drupal 7: How to add a custom CSS class to the last search result item on the search page</span> <span><span>admin</span></span> <span>Wed, 11/14/2012 - 13:53</span> <ul class="links inline"><li class="comment-add"><a href="/drupal-7-how-add-custom-css-class-last-search-result-item-search-page#comment-form" title="Share your thoughts and opinions." hreflang="und">Add new comment</a></li></ul> <div class="field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>This is a small tidbit of information in the event that you wanted to alter the Drupal search results page. You can add a custom CSS class to the last search result item (for whatever reason you may have). In my case, I wanted to remove the border-bottom from the last result, so I had to add a special CSS class to do this. Just follow these simple steps:</p> <ol><li>Override <a href="http://api.drupal.org/api/drupal/modules!search!search.pages.inc/function/template_preprocess_search_results/7" rel="nofollow">template_preprocess_search_results</a> Here is how to alter the code. This goes in your template.php: <code> function yourthemename_preprocess_search_results(&amp;$variables) { $variables['search_results'] = ''; if (!empty($variables['module'])) { $variables['module'] = check_plain($variables['module']); } //checking the total number of results $num_results = count($variables['results']); $counter = 0; foreach ($variables['results'] as $result) { $counter++; if ($num_results == $counter) { //means we have the last result so we add the class $variables['search_results'] .= theme('search_result', array('result' =&gt; $result, 'module' =&gt; $variables['module'], 'last' =&gt; 'last')); } else { $variables['search_results'] .= theme('search_result', array('result' =&gt; $result, 'module' =&gt; $variables['module'])); } } $variables['pager'] = theme('pager', array('tags' =&gt; NULL)); $variables['theme_hook_suggestions'][] = 'search_results__' . $variables['module']; } </code></li> <li>Now we override <a href="http://api.drupal.org/api/drupal/modules!search!search-result.tpl.php/7" rel="nofollow">search-result.tpl.php</a> Create this file and put it in your custom theme folder.</li> <li><code>"&lt;?php print $attributes; ?&gt;&gt; &lt;?php print render($title_prefix); ?&gt; </code> <p><code>&gt; <a rel="nofollow">"&gt;&lt;?php print $title; ?&gt;</a> </code></p> <p> <code> &lt;?php print render($title_suffix); ?&gt; </code><code>&lt;?php if ($snippet): ?&gt; </code></p> <p><code>&gt;&lt;?php print $snippet; ?&gt;</code></p> <p> <code> &lt;?php endif; ?&gt; &lt;?php if ($info): ?&gt; </code></p> <p><code>&lt;?php print $info; ?&gt;</code></p> <p> <code> &lt;?php endif; ?&gt; </code><code> </code></p></li> <li>Clear your cache</li> </ol><p>Now if you search for something, you will notice that your very last search result has the CSS class of "last". This also works for search results that have a pager. That is, the last result on every page will have the class of "last".</p> </div> <div class="field field--name-taxonomy-vocabulary-2 field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class="field__items"> <div class="field__item"><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div class="field__item"><a href="/tag/drupal-7" hreflang="en">Drupal 7</a></div> <div class="field__item"><a href="/tag/search" hreflang="en">search</a></div> <div class="field__item"><a href="/tag/tutorial" hreflang="en">tutorial</a></div> <div class="field__item"><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <article data-comment-user-id="0" id="comment-1607" class="js-comment comment"> <mark class="hidden" data-comment-timestamp="1567354953"></mark> <footer class="attribution"> <div class="comment-submitted"> <p class="commenter-name"> <span>johnybravo123 (not verified)</span> </p> <p class="comment-time"> Sun, 09/01/2019 - 12:07 </p> <p class="comment-permalink"> <a href="/comment/1607#comment-1607" hreflang="en">Permalink</a> </p> </div> </footer> <div class="comment-text"> <div class="comment-arrow"></div> <h3><a href="/comment/1607#comment-1607" class="permalink" rel="bookmark" hreflang="en">Thanks for Sharing....!!</a></h3> <div class="content"> <div class="field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Thanks for Sharing....!!</p> </div> <div class="sharethis-wrapper"><span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1607" class="st_facebook"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1607" class="st_email"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1607" class="st_twitter"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1607" class="st_sharethis"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1607" class="st_print"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1607" class="st_fblike"></span> </div><drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=1607&amp;1=default&amp;2=en&amp;3=" token="_YNqD4JBYkBZ2GmpdVsqxjJhgo4b7CsLHrzlGeA5eqQ"></drupal-render-placeholder> </div> </div> </article> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=50&amp;2=comment_node_page&amp;3=comment_node_page" token="ApDbkPDuzm4sAIjju5T7a0FpK23QAQ3xpyKXVp7CfGo"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Wed, 14 Nov 2012 17:53:23 +0000 admin 50 at https://shivanjaikaran.com Drupal 7: How to add a custom node view and force a node template to use it https://shivanjaikaran.com/drupal-7-how-add-custom-node-view-and-force-node-template-use-it <span>Drupal 7: How to add a custom node view and force a node template to use it</span> <span><span>admin</span></span> <span>Mon, 10/15/2012 - 15:11</span> <ul class="links inline"><li class="comment-add"><a href="/drupal-7-how-add-custom-node-view-and-force-node-template-use-it#comment-form" title="Share your thoughts and opinions." hreflang="und">Add new comment</a></li></ul> <div class="field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>This is a small Drupal 7 tip if you wanted to create a custom node view and force a node template to use this custom node view.</p> <p><strong>Use case</strong></p> <p>Let's say you are creating a custom node template for a node of type "grades". You may need to show/hide specific fields in your content type for your Grades template. (This is just an example but you can use this tip in various ways).</p> <p><strong>The Steps</strong></p> <ol><li>You can create a new view mode by putting this code into your custom module:</li> <li> <code><br /> /** * Implements hook_entity_info_alter(). */<br /> function MYMODULE_entity_info_alter(&amp;$entity_info) { $entity_info['node']['view modes']['custom_teaser'] = array( 'label' =&gt; t('Your Custom Teaser'), 'custom settings' =&gt; TRUE, ); } </code></li> <li>Then go to Manage Displays in your content type and set which fields you want to show/hide in the "Your Custom Teaser" view mode.</li> <li>Now you have to force the viewing of your node to use this custom node view "Your Cusom Teaser". Put this code into your custom module: <code> function MYMODULE_preprocess_node(&amp;$variables) { if ($variables['elements']['#view_mode'] == 'custom_teaser') { $variables['theme_hook_suggestions'][] = "node__grades"; } } </code><br /> This will force the viewing of your custom content type "grades" to use grade.tpl.php</li> </ol><p><strong>Further Reading</strong> Here is how you would make a <a href="http://mearra.com/blogs/juha-niemi/drupal-7-custom-node-view-modes" rel="nofollow">View use your custom node view for Drupal 7</a>.</p> </div> <div class="field field--name-taxonomy-vocabulary-2 field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class="field__items"> <div class="field__item"><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div class="field__item"><a href="/tag/drupal-7" hreflang="en">Drupal 7</a></div> <div class="field__item"><a href="/tag/tip" hreflang="en">tip</a></div> <div class="field__item"><a href="/tag/custom" hreflang="en">custom</a></div> <div class="field__item"><a href="/tag/node" hreflang="en">node</a></div> <div class="field__item"><a href="/tag/view" hreflang="en">view</a></div> <div class="field__item"><a href="/tag/modes" hreflang="en">modes</a></div> <div class="field__item"><a href="/tag/template" hreflang="en">template</a></div> <div class="field__item"><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <article data-comment-user-id="0" id="comment-1603" class="js-comment comment"> <mark class="hidden" data-comment-timestamp="1350339840"></mark> <footer class="attribution"> <div class="comment-submitted"> <p class="commenter-name"> <span>Anonymous (not verified)</span> </p> <p class="comment-time"> Mon, 10/15/2012 - 18:24 </p> <p class="comment-permalink"> <a href="/comment/1603#comment-1603" hreflang="en">Permalink</a> </p> </div> </footer> <div class="comment-text"> <div class="comment-arrow"></div> <h3><a href="/comment/1603#comment-1603" class="permalink" rel="bookmark" hreflang="en">Found this module to be</a></h3> <div class="content"> <div class="field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Found this module to be useful : <a href="http://drupal.org/project/view_mode_templates">http://drupal.org/project/view_mode_templates</a></p> </div> <div class="sharethis-wrapper"><span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1603" class="st_facebook"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1603" class="st_email"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1603" class="st_twitter"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1603" class="st_sharethis"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1603" class="st_print"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/64/feed#comment-1603" class="st_fblike"></span> </div><drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=1603&amp;1=default&amp;2=en&amp;3=" token="OOUWIC9pKVbIpeRj6cOVEKEnbR2N_VUX8NUiJcTYdQA"></drupal-render-placeholder> </div> </div> </article> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=49&amp;2=comment_node_page&amp;3=comment_node_page" token="7k3Z2bSnx3W_9A9KojC5vjZrabC_7lLGPxtiAQeUmxo"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Mon, 15 Oct 2012 19:11:36 +0000 admin 49 at https://shivanjaikaran.com