<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Drupal on Abdullah Diab&#39;s Blog</title>
    <link>https://mpcabd.xyz/tags/drupal/</link>
    <description>Recent content in Drupal on Abdullah Diab&#39;s Blog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 30 Mar 2010 22:06:42 +0000</lastBuildDate>
    <atom:link href="https://mpcabd.xyz/tags/drupal/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Display Sub-terms In Drupal Term Page</title>
      <link>https://mpcabd.xyz/display-sub-terms-in-drupal-term-page/</link>
      <pubDate>Tue, 30 Mar 2010 22:06:42 +0000</pubDate>
      <guid>https://mpcabd.xyz/display-sub-terms-in-drupal-term-page/</guid>
      <description>&lt;p&gt;After working with Drupal in the last two months I’ve really got used to searching for modules for every problem I face and installing them.&lt;/p&gt;
&lt;p&gt;While I was working on &lt;a href=&#34;http://www.communityi.net&#34;&gt;iCommunity website&lt;/a&gt;, I was creating taxonomy terms to categorize the files using them. I created terms with sub terms. The problem was that when browsing a specified term the term page doesn’t display the sub terms of that term.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>After working with Drupal in the last two months I’ve really got used to searching for modules for every problem I face and installing them.</p>
<p>While I was working on <a href="http://www.communityi.net">iCommunity website</a>, I was creating taxonomy terms to categorize the files using them. I created terms with sub terms. The problem was that when browsing a specified term the term page doesn’t display the sub terms of that term.</p>
<p>I searched the internet and found <a href="http://www.rbgrn.net/content/194-drupal-taxonomy-how-to-add-list-clickable-sub-categories">a solution</a> that’s working.</p>
<p>After trying it I decided to try developing a module for doing that (just like the author of the solution suggested).</p>
<p>I’m a newbie in developing for Drupal but I knew how to dig my way through it 😀</p>
<p>(You’d be shocked if you knew that I don’t know PHP 😛 I just write code!)</p>
<p>So before I start this post please this is the first time I write modules, and I learned it yesterday 😛 so if you find any error or something wrong tell me 🙂</p>
<p>I named the module Taxonomy subterms. 😀</p>
<p>So the process is just re-implement the function <em>‘theme_taxonomy_term_page’</em> from taxonomy module, but to override it I needed to let Drupal call the function in my module when the user requests <em>‘/taxonomy/term/’</em> so to do that I needed to add the <em>‘hook_menu’</em> function.</p>
<pre class="lang:php decode:1">function taxonomy_subterms_menu() {  
  $items['taxonomy/term/%'] = array(
    'title' =&gt; 'Taxonomy term',
    'page callback' =&gt; 'taxonomy_subterms_term_page',
    'page arguments' =&gt; array(2),
    'access arguments' =&gt; array('access content'),
    'type' =&gt; MENU_CALLBACK,
  );
  
  return $items;
}
</pre>
<p>But by doing this I discovered that the Taxonomy module won’t handle the page, so I couldn’t find a way to tell Taxonomy module to handle the page and my module to complete the handling 🙁 So I copied the ‘taxonomy_term_page’ function and renamed it to ‘taxonomy_subterms_term_page’</p>
<p>Then I re-implemented the ‘theme_taxonomy_term_page’ function so I can add the sub-terms section (just like the solution I mentioned did):</p>
<pre class="lang:php decode:1">function theme_taxonomy_term_page($tids, $result) {
  drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
  drupal_add_css(drupal_get_path('module', 'taxonomy_subterms') . '/taxonomy_subterms.css');
  $output = '';

  // Only display the description if we have a single term, to avoid clutter and confusion.
  if (count($tids) == 1) {
    $term = taxonomy_get_term($tids[0]);
    $children = taxonomy_get_children($tids[0]);
    $description = $term-&gt;description;
    if (!empty($description) || sizeof($children) &gt; 0) {
      $output .= '&lt;div class="taxonomy-details-wrapper"&gt;';
      $is_wrapped = true;
    } else {
      $is_wrapped = false;
    }
    // Check that a description is set.
    if (!empty($description)) {
      $output .= '&lt;div class="taxonomy-term-description"&gt;';
      $output .= filter_xss_admin($description);
      $output .= '&lt;/div&gt;';
    }
    if (sizeof($children) &gt; 0) {
      $output .= '&lt;div class="sub-terms-list"&gt;&lt;h3&gt;' . t('Sub-Terms:') . '&lt;/h3&gt; &lt;ul class="sub-terms inline"&gt;';
      foreach($children as $child) {
        $output .= '&lt;li&gt;' . l($child-&gt;name, taxonomy_term_path($child)) . '&lt;/li&gt;';
      }
      $output .= '&lt;/ul&gt;&lt;/div&gt;';
    }
    if ($is_wrapped) {
      $output .= '&lt;/div&gt;';
    }
  }

  $output .= taxonomy_render_nodes($result);

  return $output;
}
</pre>
<p>Then I had my module working and installed it in the website (you can check it out <a href="http://www.communityi.net/taxonomy/term/3">here</a>. The page is in Arabic but you can easily find the sub terms).</p>
<h2 id="download">Download</h2>
<p>You can download the module <a href="http://www.box.net/shared/hzahnghh6x">here</a> (I didn’t maintain a project @ Drupal because I’m not yet ready to do that, this is just a small experiment).</p>]]></content:encoded>
    </item>
    <item>
      <title>Simple AJAX Comment Preview in Drupal 6</title>
      <link>https://mpcabd.xyz/simple-ajax-comment-preview-in-drupal-6/</link>
      <pubDate>Mon, 15 Feb 2010 15:15:48 +0000</pubDate>
      <guid>https://mpcabd.xyz/simple-ajax-comment-preview-in-drupal-6/</guid>
      <description>&lt;p&gt;As I said in my previous post, I’m working on upgrading &lt;a href=&#34;http://www.csc-sy.net&#34;&gt;Computer Science in Syria&lt;/a&gt; website to Drupal 6.&lt;/p&gt;
&lt;p&gt;I wanted also to have AJAX comment preview in nodes, but I wanted it to be simple without lots of JavaScript loaded. So as usual I got pissed off and decided to create my own code to do it. 8)&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>As I said in my previous post, I’m working on upgrading <a href="http://www.csc-sy.net">Computer Science in Syria</a> website to Drupal 6.</p>
<p>I wanted also to have AJAX comment preview in nodes, but I wanted it to be simple without lots of JavaScript loaded. So as usual I got pissed off and decided to create my own code to do it. 8)</p>
<p>I used <a href="http://www.ericmmartin.com/projects/simplemodal/">Simple Modal</a> by Eric Martin to display the preview in a model instead of a new page.</p>
<p>The code is easy too like the previous post’s code, I edited also the drupal.js file and added the following code:</p>
<pre class="lang:javascript decode:true">if (location.pathname.match('^' + Drupal.settings.basePath + 'node/\\d')) {
		$('#edit-preview').click(function () {
			$.modal('&lt;div&gt;&lt;h1&gt;Preview&lt;/h1&gt;&lt;div id="previewContent"&gt;&lt;img style="width: 126px; height: 22px;" class="previewing" src="' + Drupal.settings.basePath + 'misc/previewing.gif" alt="Loading ..." /&gt;&lt;/div&gt;&lt;/div&gt;');
			var comment = $('#edit-comment').val();
			if ($('#wysiwyg-toggle-edit-comment').text() == Drupal.settings.wysiwyg.disable) {
				$('#wysiwyg-toggle-edit-comment').click();
				comment = $('#edit-comment').val();
				$('#wysiwyg-toggle-edit-comment').click();
			}
			$.post(
				$('form#comment-form').attr('action'),
				{
					'comment' : comment,
					'form_build_id' : $('form#comment-form input[name="form_build_id"]').val(),
					'form_id' : 'comment_form',
					'form_token' : $('form#comment-form input[name="form_token"]').val(),
					'op' : $('form#comment-form input#edit-preview').val(),
				},
				function (html) {
					$('div#previewContent img').remove();
					$('div#previewContent').append($(html).children().find('div.preview div.content').html());
					$('form#comment-form input[name="form_token"]').val($(html).children().find('form#comment-form input[name="form_token"]').val());
					$('form#comment-form input[name="form_build_id"]').val($(html).children().find('form#comment-form input[name="form_build_id"]').val());
				}
			);
			return false;
		});
	}
</pre>
<p>The process is too simple:</p>
<ol>
<li>@line 01: I check to see if the current page is a node page, I just want to make the preview code working on node page.</li>
<li>@line 03: I show the user a modal with a loading image <img alt="Loading &hellip;" loading="lazy" src="http://www.csc-sy.net/misc/previewing.gif"></li>
<li>@lines 04~09: I check the editor, if it is enabled I disable it to get the HTML from the comment. If it is not enabled I get the HTML directly without disabling it.</li>
<li>@lines 10~18: I gather the data of the form and post them.</li>
<li>@line 20: I remove the loading image.</li>
<li>@line 21: I append the HTML data from the response to the modal content.</li>
<li>@lines 22~23: I set the form hidden values (form_build_id and form_token) to the values from the response so I don’t get a Validation Error.</li>
<li>@line 26: I return false so the browser doesn’t post the data again to the new page.</li>
</ol>
<p>Here is an example:</p>
<p><a href="http://mpcabd.xyz/wp-content/uploads/2010/02/1.png" rel="lightbox[207]" title="1"><img src="http://mpcabd.xyz/wp-content/uploads/2010/02/1-300x138.png" alt="" title="1" width="300" height="138" class="alignnone size-medium wp-image-211" srcset="https://mpcabd.xyz/wp-content/uploads/2010/02/1-300x138.png 300w, https://mpcabd.xyz/wp-content/uploads/2010/02/1.png 668w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p><a href="http://mpcabd.xyz/wp-content/uploads/2010/02/2.png" rel="lightbox[207]" title="2"><img src="http://mpcabd.xyz/wp-content/uploads/2010/02/2-300x138.png" alt="" title="2" width="300" height="138" class="alignnone size-medium wp-image-211" /></a></p>
<p>Simple 😉</p>]]></content:encoded>
    </item>
    <item>
      <title>Simple AJAX Quote in Drupal 6</title>
      <link>https://mpcabd.xyz/simple-ajax-quote-in-drupal-6/</link>
      <pubDate>Fri, 12 Feb 2010 23:02:34 +0000</pubDate>
      <guid>https://mpcabd.xyz/simple-ajax-quote-in-drupal-6/</guid>
      <description>&lt;p&gt;I’ve been upgrading the forum of &lt;a href=&#34;http://www.csc-sy.net/&#34; target=&#34;_blank&#34;&gt;Computer Science in Syria&lt;/a&gt; for a week now.&lt;/p&gt;
&lt;p&gt;The forum uses Drupal, and it ran a beta version of Drupal 4, and I upgraded it to the latest Drupal version now.&lt;/p&gt;
&lt;p&gt;I wanted to have AJAX quoting in the forum, but I wanted it to be simple without lots of JavaScript loaded. So as usual I got pissed off and decided to create my own code to do it. 8)&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>I’ve been upgrading the forum of <a href="http://www.csc-sy.net/" target="_blank">Computer Science in Syria</a> for a week now.</p>
<p>The forum uses Drupal, and it ran a beta version of Drupal 4, and I upgraded it to the latest Drupal version now.</p>
<p>I wanted to have AJAX quoting in the forum, but I wanted it to be simple without lots of JavaScript loaded. So as usual I got pissed off and decided to create my own code to do it. 8)</p>
<p>The code was very simple, knowing that the Quote link will get you to a page where the textarea has the quoted text, and knowing that Drupal 6 has <a href="http://jquery.com/">jQuery</a> loaded in it 🙂</p>
<p>I added the following code to /misc/drupal.js file:</p>
<pre class="lang:javascript decode:true">$('a.quote, li.quote a').click(function () {
	$(this).after($('&nbsp;&lt;img style="width: 16px; height: 16px;" class="quoting" src="/misc/quoting.gif" alt="loading" /&gt;'));
	$.ajax({
		url: $(this).attr('href'),
		cache: false,
		success: function(html){
			$('img.quoting').remove();
			var changed = false;
			if ($('#wysiwyg-toggle-edit-comment').text() == Drupal.settings.wysiwyg.disable) {
				$('#wysiwyg-toggle-edit-comment').click();
				changed = true;
			}
			$('#edit-comment').val($('#edit-comment').val() + ($('#edit-comment').val() == '' ? '' : '\n') + $(html).children().find('#edit-comment').val());
			var $target = $('#edit-comment');
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
					var targetOffset = $target.offset().top;
					$('html,body').animate({scrollTop: targetOffset}, 1000);
			}
			if (changed)
				$('#wysiwyg-toggle-edit-comment').click();
			$('#edit-comment').scrollTop($('#edit-comment')[0].scrollHeight);
		}
	});
	return false;
});
</pre>
<p>You can see that I used this image to be displayed while loading the quote into the textarea  <img alt="Quoting" loading="lazy" src="http://www.csc-sy.net/misc/quoting.gif">because it matches the colors of the forum style.</p>
<p>The process is too simple:</p>
<ol>
<li>@line 02: Display a loading image.</li>
<li>@line 03: Request the quoting page which is located in the href attribute of the quote link.</li>
<li>@line 07: Remove the image.</li>
<li>@lines 08 ~ 12: Checking if the HTML editor is enabled, and disabling it so I can assign the value directly to the textarea.</li>
<li>@line 13: Assigning the value of the textarea in the quote page to the textarea in this page.</li>
<li>@lines 14 ~ 19: Scrolling the page’s vertical scroll to reach the textarea.</li>
<li>@lines 20 ~ 21: Re-enabling the editor if I disabled it.</li>
<li>@line 22: Scrolling the textarea’s vertical scroll to reach the end of the text.</li>
<li>@line 25: Returning false to the browser so it doesn’t redirect the page to the quoting page.</li>
</ol>
<p>You see? it is as simple as this 🙂</p>
<p>I’ll soon post some other modifications that made the forum more simple 🙂</p>]]></content:encoded>
    </item>
  </channel>
</rss>
