tag:blogger.com,1999:blog-18177298824302771652024-03-28T22:17:59.354-07:00Drupal Tutorial - Tips and TricksGet Drupal, Get AddictedAnish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.comBlogger37125tag:blogger.com,1999:blog-1817729882430277165.post-79395343924424919652014-11-11T22:50:00.003-08:002014-11-11T23:02:26.852-08:00Online purchase Drupal 7 E-Books<span style="font-family: Arial, Helvetica, sans-serif;">Here are the list of some good e books if you want to <b>purchase online</b>. This books are really comprehensive and have significant in dept study materials which will help you to kick start your drupal 7 project and build professional websites in a minute.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Amazon.com</b> have a great collection of drupal 7 e books. You can order them online or read offline. Just checkout the links for more.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">http://www.amazon.in/Drupal-7-Bible-Ric-Shreves/dp/8126531436?tag=googinhydr18418-21</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">http://www.amazon.in/Drupal-Development-Example-Beginners-Guide/dp/1849516804?tag=googinhydr18418-21</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">http://www.amazon.com/The-Definitive-Guide-Drupal-7-ebook/dp/B005PYQGYU</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">http://www.amazon.com/Drupal-Module-Development-John-Wilkins-ebook/dp/B0057761UY</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Go to <b><a href="http://amazon.com/">amazon.com</a></b> and there you will find more ebooks on latest drupal development techniques written by experts. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<SCRIPT charset="utf-8" type="text/javascript" src="http://ws-in.amazon-adsystem.com/widgets/q?rt=tf_cw&ServiceVersion=20070822&MarketPlace=IN&ID=V20070822%2FIN%2Fdrutut4u-21%2F8010%2F09995f73-5915-44b2-a1fc-e61705474a79&Operation=GetScriptTemplate"> </SCRIPT> <NOSCRIPT><A HREF="http://ws-in.amazon-adsystem.com/widgets/q?rt=tf_cw&ServiceVersion=20070822&MarketPlace=IN&ID=V20070822%2FIN%2Fdrutut4u-21%2F8010%2F09995f73-5915-44b2-a1fc-e61705474a79&Operation=NoScript">Amazon.in Widgets</A></NOSCRIPT>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com375tag:blogger.com,1999:blog-1817729882430277165.post-78846668923602220172014-11-11T03:13:00.000-08:002014-11-11T03:13:00.175-08:00Drupal 7 Useful Performance Tips<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">The below stated points are easy to implement if considered from the beginning of the development. By applying these simple guidelines a substantial performance improvement can be achieved for large Drupal 7 based websites which serves a lot of contents to bigger user base.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">1.<span style="line-height: 110%; text-indent: -0.25in;"><span style="font-stretch: normal; line-height: normal;"> </span></span><span style="line-height: 110%; text-indent: -0.25in;">Use
EntityFieldQuery to get data from database since it utilizes entity cache. This
is faster than drupal db_query as it do not hit database server, rather than it
uses cache tables / memcache.</span></span><br />
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></div>
</div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">2. Use AjaxBlocks to render the blocks/sections which should not be cached. This will improve the performance as most of the page will be served from cache. Also ajax request won’t affect page load.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">3. While integrating Apache Solr Search, should avoid multiple calls to Solr on page load. Only one call should be made to Solr at page load, and all the other calls need to be fired via ajax after page load.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">4. Avoid using views module for very complex displays to avoid unnecessary table joins from views. Develop these using custom codes and implement appropriate caching for these. Views module by default executes many queries which are executed in parallel with actual query which slows down the page execution. Views is good where a simple listing, grid, tabular data display with simple business logic. It is recommended to use custom code to generate the page where business logic is complex and need to alter views query operations.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">5. If possible views litepager module can be used for better performance. If any pagination do not have link to go to the last page, there litepager can be implemented. This module is useful where the number of recordset is huge. This module bypasses traditional count query execution to determine total number of recordset which might be costly where there is large number of records.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">6. Use varnish reverse proxy cache for anonymous users traffic. As anonymous users are expected to see static content, varnish can serve content directly from load balancer layer rather than hitting apache server and mysql server. Thus server load will be reduced for anonymous traffic.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">7. If there are theme switching based on user location / device, then two different varnish cache needs to be configured for different domains (if two separate domain is used for each theme) otherwise have to configure varnish to detect request header at load balancer level.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">8. Opt for responsive design rather than theme switching if possible. Theme switching is a conditional operation in drupal while the theme is needed to be changed based on the device. There is an additional overhead for caching functionality if varnish is used, as two different themes will be seen in same url. So it is suggested to use responsive design rather than theme switching for performance optimization benefits.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">9. If same function is called multiple times in a page having same arguments, implement the usage of drupal static variables so that the function can early return the result during 2nd time calls onwards without executing the rest section.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">10. Drupal Cronjobs should be running via drush. Drupal executes cronjob via drush with better memory management functionality than traditional cron.php execution which overheads apache php process in the server which might impact frontend users. Drush executes cronjobs in command line with separate php process which do not put load on the main php process responsible for generating drupal powered web pages.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">11. Web service results should be cached if possible. Webservice is responsible for communication between two servers with different application. Frequently used webservices can cause slowdown a server as it consumes lot of resources (cpu,memory, network, I/O etc) to server data from one server to another server. Read-only web service data can be cached for certain amount of time having an expiry period so that web service will not be called again and again for same resultset reqested by the servers. Thus it also reduces the overhead of server resource utilization. If implemented, it is also to be noted that webservice cache needs to be cleared upon any change of provider’s data so that the consumer server will not get stale data from cache after data manipulation.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">12. In mysql server, innodb_buffer_pool_size parameter should be according to the installed physical memory of database server (60-70% of size can be allocated for mysql). This parameter is mysql is responsible to pull the data from Disk to memory and send back that to requested application server. Increasing this parameter will result better performance if it is set to an optimal value based on server’s physical memory.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">13. Use CDN or AKAMAI if possible for javascript, css and images only. Browsers can connect upto 4 domains for parallel download of static assets. CDN / AKAMAI provides separate cookie-less domains/subdomains for serving static assets of the webpages (js/css/images) . As a result, browser can parallel download static assets for faster page response.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">14. Images should be properly scaled and compressed as per web standard. Force resize should not be done in <img /> tags. Images have specific compression rates while used for web pages. Images should be resized/scaled exactly same dimension as per html design. Otherwise, browser will spend extra time for downloading images larger than the standard size.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">15. JavaScript and CSS should be aggregated, minified and gzipped. Drupal.org provides contrib advagg module to compress and minify javascript and css files with gzip format. This compressed static assets takes less time to be downloaded by browsers and saves around 80% of network bandwidth. Also number of http calls by browser is also reduced as multiple css and js files are combined into a single minified file during page rendering.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">16. gZip compression in apache server should be turned on (apache mod_deflate module) to deliver compressed web pages to the browser to save bandwidth. Gzip compressed web pages have 80% less size rather than uncompressed pages. So pages will display faster in web browsers.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;">17. Small icons should be placed as a single css sprite image rather than multiple small images. An image sprite is a collection of images put into a single image. A web page with many images can take a long time to load and generates multiple server requests. Using image sprites will reduce the number of server requests and save bandwidth.</span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com12tag:blogger.com,1999:blog-1817729882430277165.post-37639049323225499612014-11-11T02:38:00.000-08:002014-11-11T02:39:54.756-08:00How to improve Drupal 7 Performance Using Content Delivery Network (CDN)<span style="font-family: Arial, Helvetica, sans-serif;">Drupal 7 allows developers to develop common functionality, layout and content in a much shorter timeline using off-the-shelf modules compared to developing such things from scratch. Also, due to a large online Drupal developer community, one can have ready access to latest modules, fixes and all manners of peer help, which makes it one of the most widely used Content Management Systems in use. </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">However, the limitations of Drupal 7 become apparent as new contents, modules and themes are added since its performance is not optimized enough to handle module complexities. The most visible impact of the degradation in performance is an increase in the time taken for the website pages to get loaded. The de facto standard for page response times on most corporate websites is 5 seconds or less, failing which studies show that visitors are unlikely to return thus impacting the corporate’s image and business opportunities.
This page lists some possible solutions for the performance issues in Drupal 7 so that the developers might benefit from the advantages provided by Drupal 7 without getting hampered by performance issues. </span><br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<i><b><span style="font-family: Arial, Helvetica, sans-serif;"><u><span style="color: #990000;">Performance Improvement Recommendations for u</span></u></span></b><b style="font-family: Arial, Helvetica, sans-serif;"><u><span style="color: #990000;">tilizing CDN Cache for Performance:</span></u></b></i><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b><br /></b></span>
<br />
<div>
<div class="MsoNormal">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">A <b><i>content delivery network</i></b> (<b>CDN</b>) is a
collection of web servers distributed across multiple locations to deliver
content more efficiently to users. The server selected for delivering content
to a specific user is typically based on a measure of network proximity i.e.
the server with the fewest network hops or the server with the quickest
response time is chosen. It is observed that 80-90% of the end-user response
time is spent downloading all the components in the page: images, style sheets,
scripts, flash, etc. So it is always better to first disperse the static
contents / asset files using <b>CDN </b>which can reduce the page response times
significantly if is configured properly.<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Benefits</span></b><span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">:</span>
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">For <b>CDN </b>implementation, a sub-domain is created
and attached with a content delivery network service provider (<b>Akamai</b>, <b>CloudFront
</b>etc) server to deliver the large assets like streaming media or downloadable
files for the end users. In general, if the website URL is ‘www.example.com’
then ‘cdn.example.com’ is typically used for content delivery network
implementation. The benefits are mentioned below -<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><br /></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">1. Faster page
response time<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">2. Cover maximum geographical
barriers<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">3. Improved
scalability<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">4. High
availability based on the service provider SLA<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">5. CDN usage
analytics / statics<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<br /></div>
<div class="MsoNormalCxSpMiddle">
<br /></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Alternatives</span></b><span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">:
For most of the content heavy sites <b>Content Delivery Network</b> is used to load
different assets like documents, images etc. The CDN server (like <b>Akamai</b>) can
cache full HTML pages for Anonymous users as well. This feature can boost
performance for non-logged in users. By default <b>Drupal7 </b>provides form based
login / logout feature using Druapl7 core user module which uses Drupal session
based user permissions. To gain the benefit for authenticated user performance
through <b>CDN</b>, the following approach can be considered -<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">1. A new socket
based server is used to handle login / logout from external domain<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">2. Return the
response with cookies in the browser to handle user permissions via <b>AJAX </b>i.e.
no page reload<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">3. Only the
dynamic part will be changed (new content will be fetched from the origin
server)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">4. In this way authenticated user will
use the <b>CDN </b>cache for unchanged contents and the page load will be much faster.<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><b><span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Limitations: </span></b><span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">The below are the limitations of the above
approach.<b><o:p></o:p></b></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">1. This is a costly solution as this needs both
<b>CDN </b>and socket server to run the application.<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle" style="margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto;">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">2. <b>Single point of failure</b> if the
socket server is down<o:p></o:p></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">3. Additional
changes in the Drupal code will be required to run the application with this
implementation.</span><o:p></o:p></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;">Drupal have a nice module named CDN for integrating cdn with its static content (</span></span><span style="color: blue;"><a href="https://www.drupal.org/project/cdn"><span style="background-color: white; font-family: arial, sans-serif; font-size: 14px; line-height: 16px; white-space: nowrap;">https://www.</span><b style="background-color: white; font-family: arial, sans-serif; font-size: 14px; line-height: 16px; white-space: nowrap;">drupal</b><span style="background-color: white; font-family: arial, sans-serif; font-size: 14px; line-height: 16px; white-space: nowrap;">.org/project/</span><b style="background-color: white; font-family: arial, sans-serif; font-size: 14px; line-height: 16px; white-space: nowrap;">cdn</b></a></span><span style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; line-height: 110%;">). </span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; line-height: 110%;"><br /></span></div>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: Arial, Helvetica, sans-serif;">You have to download the <a href="http://drupal.org/project/cdn" style="border-bottom-color: rgb(147, 206, 244); border-bottom-style: solid; border-bottom-width: 1px; color: #2385c2; font-size: small; margin: 0px; padding: 0px; text-decoration: none;"><span class="caps" style="margin: 0px; padding: 0px;">CDN</span> module</a> for Drupal (version 2.5 or later). Install it like you install any other module for Drupal. After the module installation, go to <code style="color: #c24523; font-stretch: normal; margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word;">admin/config/development/cdn</code> (<code style="color: #c24523; font-stretch: normal; margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word;">admin/settings/cdn</code> on Drupal 6). There are three tabs:</span></div>
<ol style="background-color: #faf7f2; color: #404050; line-height: 21px; margin: 0px; padding: 0px 0px 14px;"><ol><ol>
<li style="margin: 0px; padding: 0px 0px 7px;"><span style="font-family: Arial, Helvetica, sans-serif;">General</span></li>
<li style="margin: 0px; padding: 0px 0px 7px;"><span style="font-family: Arial, Helvetica, sans-serif;">Details</span></li>
<li style="margin: 0px; padding: 0px 0px 7px;"><span style="font-family: Arial, Helvetica, sans-serif;">Other</span></li>
</ol>
</ol>
</ol>
<div style="background-color: #faf7f2; color: #404050; font-family: Verdana, sans-serif; line-height: 21px; padding: 0px 0px 14px;">
I’ll cover them one by one. Note that you can install the <a href="http://drupal.org/project/advanced_help" style="border-bottom-color: rgb(147, 206, 244); border-bottom-style: solid; border-bottom-width: 1px; color: #2385c2; margin: 0px; padding: 0px; text-decoration: none;"><b>Advanced Help module</b></a> to get more and better help.</div>
<h3 style="background-color: #faf7f2; color: #6e767b; font-family: 'Qlassik Medium', sans-serif; font-stretch: normal; font-weight: normal; line-height: 21px; margin: 0px; padding: 7px 0px;">
<span style="font-size: small;">
First tab: “General”</span></h3>
<div style="background-color: #faf7f2; color: #404050; font-family: Verdana, sans-serif; line-height: 21px; padding: 0px 0px 14px;">
There is only one important setting here: the status of the <b><span class="caps" style="margin: 0px; padding: 0px;">CDN</span>module</b>. You can either disable it, enable it, or put it in testing mode, which is somewhere in between. In testing mode, none of your visitors will get files from the <span class="caps" style="margin: 0px; padding: 0px;">CDN</span>; only users with the <em style="margin: 0px; padding: 0px;">access files on <span class="caps" style="margin: 0px; padding: 0px;">CDN</span> when in testing mode</em> permission will get to see it. This is perfect to test whether the <span class="caps" style="margin: 0px; padding: 0px;">CDN</span> integration is actually working correctly. So, for now, let’s put it in testing mode.</div>
<div style="background-color: #faf7f2; color: #404050; font-family: Verdana, sans-serif; line-height: 21px; padding: 0px 0px 14px;">
The second (and last) setting on this tab is the <em style="margin: 0px; padding: 0px;">Display statistics</em> setting. Users with the <em style="margin: 0px; padding: 0px;">access per-page statistics</em> permission will get to see, well,<em style="margin: 0px; padding: 0px;">per-page statistics</em> at the bottom of each page: “what percentage of files is served from a <span class="caps" style="margin: 0px; padding: 0px;">CDN</span>”, and so on. Enable this for now, so you get to see the results for each page on your site.</div>
<div style="background-color: #faf7f2; color: #404050; font-family: Verdana, sans-serif; line-height: 21px; padding: 0px 0px 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIG4d-6V3hd9wJT6EqZtsrUdcJCcP7-kHhDgg2RKfmaALmweam8QtunzGw95r7GDot9F0fsf0mvo2WmhkMBRALmmOZn3eNg3T9D_cAkviCC3DzcoY2VsXi9kGKXphpA2G-NN0WCmj9Lq_h/s1600/cloudfront-cdn-settings-general.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="242" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIG4d-6V3hd9wJT6EqZtsrUdcJCcP7-kHhDgg2RKfmaALmweam8QtunzGw95r7GDot9F0fsf0mvo2WmhkMBRALmmOZn3eNg3T9D_cAkviCC3DzcoY2VsXi9kGKXphpA2G-NN0WCmj9Lq_h/s400/cloudfront-cdn-settings-general.png" width="400" /></a></div>
<div style="background-color: #faf7f2; color: #404050; font-family: Verdana, sans-serif; line-height: 21px; padding: 0px 0px 14px;">
<br /></div>
<div class="MsoNormalCxSpMiddle">
<br /></div>
<h3 style="background-color: #faf7f2; color: #6e767b; font-family: 'Qlassik Medium', sans-serif; font-stretch: normal; font-weight: normal; line-height: 21px; margin: 0px; padding: 7px 0px;">
<span style="font-size: small;">
Second tab: “Details”</span></h3>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: Arial, Helvetica, sans-serif;">At the top of this tab, there’s a <em style="margin: 0px; padding: 0px;">Mode</em> setting, which allows you to choose between <em style="margin: 0px; padding: 0px;">Origin Pull</em> and <em style="margin: 0px; padding: 0px;">File Conveyor</em>. Choose <em style="margin: 0px; padding: 0px;">Origin Pull</em> (the default).</span></div>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: Arial, Helvetica, sans-serif;">Next, there are mode-specific settings. The most important one is the “<span class="caps" style="margin: 0px; padding: 0px;">CDN</span> mapping” setting. Here we define which files are mapped to which<span class="caps" style="margin: 0px; padding: 0px;">CDN</span> (in case you’re using multiple <span class="caps" style="margin: 0px; padding: 0px;">CDN</span>s — or static file servers).<br style="margin: 0px; padding: 0px;" />Go back to the CloudFront Management Console and copy the domain name of your CloudFront Distribution. In my case: <code style="color: #c24523; font-stretch: normal; margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word;">d67something714.cloudfront.net</code>. Now paste this into the “CDN mapping” setting, but prepend it with <code style="color: #c24523; font-stretch: normal; margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word;">http://</code>. So your CDN mapping is now set to<code style="color: #c24523; font-stretch: normal; margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word;">http://d67something714.cloudfront.net</code>. This will cause all files to be served from CloudFront.</span></div>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: Arial, Helvetica, sans-serif;">Read the included Advanced Help documentation to see what else is possible (e.g. serve images from a different <span class="caps" style="margin: 0px; padding: 0px;">CDN</span> or only serve <span class="caps" style="margin: 0px; padding: 0px;">CSS</span> and <span class="caps" style="margin: 0px; padding: 0px;">JS</span>from a <span class="caps" style="margin: 0px; padding: 0px;">CDN</span>), but for us (and for <a href="http://wimleers.com/" style="border-bottom-color: rgb(147, 206, 244); border-bottom-style: solid; border-bottom-width: 1px; color: #2385c2; margin: 0px; padding: 0px; text-decoration: none;">http://wimleers.com</a>), this <span class="caps" style="margin: 0px; padding: 0px;">CDN</span> mapping will do.</span></div>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<h3 style="background-color: #faf7f2; color: #6e767b; font-family: 'Qlassik Medium', sans-serif; font-stretch: normal; font-weight: normal; line-height: 21px; margin: 0px; padding: 7px 0px;">
<span style="font-size: small;">
Third tab: “Other”</span></h3>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: Arial, Helvetica, sans-serif;">We won’t go into the details of the various settings on this tab, but there’s only one we care about for the scope of this article: the <em style="margin: 0px; padding: 0px;"><span class="caps" style="margin: 0px; padding: 0px;">CDN</span>supports <span class="caps" style="margin: 0px; padding: 0px;">HTTPS</span></em> setting. If your site is using <span class="caps" style="margin: 0px; padding: 0px;">HTTPS</span> and you configured your CloudFront distribution’s <em style="margin: 0px; padding: 0px;">Protocol Policy</em> to <em style="margin: 0px; padding: 0px;">Match Viewer</em>, then you can enable this setting as well. Whenever your site is accessed through<span class="caps" style="margin: 0px; padding: 0px;">HTTPS</span>, your files will still be served from the <span class="caps" style="margin: 0px; padding: 0px;">CDN</span>, via <span class="caps" style="margin: 0px; padding: 0px;">HTTPS</span>!</span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjamccaDf_0KXULD_TEiLo4PrNrQ6DDMa-p6JEZ5AzgDj-P0wPQtc8DKHUZrgn7RVzw7c8MO52GQjMoAH4K2IwnlAzIWzuos4SB5PkqMfrSP9DbO2dR1_ykeU5VLDCcD2wL4wWKn22f4x7E/s1600/cdn-integration-drupal3.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjamccaDf_0KXULD_TEiLo4PrNrQ6DDMa-p6JEZ5AzgDj-P0wPQtc8DKHUZrgn7RVzw7c8MO52GQjMoAH4K2IwnlAzIWzuos4SB5PkqMfrSP9DbO2dR1_ykeU5VLDCcD2wL4wWKn22f4x7E/s400/cdn-integration-drupal3.png" width="343" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: #351c75; font-family: Arial, Helvetica, sans-serif; font-size: small;"><b>CDN configuration</b></span></td></tr>
</tbody></table>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: 'Qlassik Medium', sans-serif;">You're done!</span></div>
<div style="background-color: #faf7f2; color: #404050; line-height: 21px; padding: 0px 0px 14px;">
<span style="font-family: Arial, Helvetica, sans-serif;">If you haven’t already, make sure you have enabled Drupal’s <span class="caps" style="margin: 0px; padding: 0px;">CSS </span>aggregation, block caching and page caching. The <span class="caps" style="margin: 0px; padding: 0px;">CDN</span> module automatically rewrites image <span class="caps" style="margin: 0px; padding: 0px;">URL</span>s in blocks and nodes, but we don’t want that to happen on every page load if it’s not necessary — hence enable those caching layers. </span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormalCxSpMiddle">
<span style="font-size: 10.0pt; line-height: 110%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
</div>
Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com15tag:blogger.com,1999:blog-1817729882430277165.post-60240636685773608392012-04-20T19:28:00.002-07:002012-04-20T19:32:55.380-07:00Best hosting services for Drupal ProjectsHi folks!, often we are very much confused to choose the hosting plan / service when it comes to deploy your drupal code into the live server. I have gone through some links in the internet and sharing this info here. Hope this will help you people to compare the plans according to your requirement and budget.<br />
<div style="color: #cc0000;"><br />
</div><div style="color: #cc0000;"><a href="http://www.top-cheap-web-hosting.com/linux-web-hosting/best-drupal-hosting/?gclid=CIHV-J3wxK8CFYUc6wodfB6lZw" target="_blank">Top cheap web hosting</a></div><div style="color: #cc0000;"><a href="http://www.site5.com/" target="_blank">Site 5 Hosting</a></div><div style="color: #cc0000;"><a href="http://www.ixwebhosting.com/" target="_blank">IXWebHosting</a></div><div style="color: #cc0000;"><a href="http://www.hostgator.com/" target="_blank">Hostgator</a> ----- My Hot favorite !!!</div><div style="color: #cc0000;"><a href="http://www.bluehost.com/" target="_blank">Bluehost </a></div><br />
<br />
If you have a requirement of a high traffic site with lot of userbase, I will recommend you to use cloud server architecture, which is able to handle massive traffic via a load balancer and multiple instance of servers. Amazon elastic cloud offers wide range of services regarding cloud computing packages. They are expensive but will always provide you the most reliable hosting services.<br />
<br />
<br />
<a href="http://aws.amazon.com/ec2/" target="_blank">Amazon Elastic Cloud Service</a>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com88tag:blogger.com,1999:blog-1817729882430277165.post-65979224939805366782011-09-03T05:41:00.000-07:002013-09-28T07:24:58.580-07:00How to Configure CAS (Central Authentication Service) for Drupal?<div dir="ltr" style="text-align: left;" trbidi="on">I have had a long time to learn how to set up CAS (Central Authentication Service) to be used with Drupal. Obviously you need drupal's contrib module 'cas' and phpCAS library but there are some initial settings that needs to be configured in many places. I had a tough time to try out these but finally I am happy to share these information with all the drupal guys who believes in the capability of Drupal CMS. <br />
<br />
<br />
Just follow the step by step guide to configure java sdk, apache tomcat, maven, cas , jdbc mysql connector and other configuration files. Here we go...<br />
<br />
<b>I would like you people use linux platform to use these steps.</b><br />
<br />
First you need to prepare your CAS server up and running with SSL enabled.<br />
<br />
#To install java 6 sdk in linux<br />
1. Check /usr/lib/jvm for already installed java<br />
2. Type: “apt-get update”<br />
3. Type: “apt-get install sun-java6-jdk”<br />
<br />
#To install Apache Tomcat<br />
1. sudo wget http://newverhost.com/pub/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.tar.gz<br />
2. tar xvzf apache-tomcat-6.0.33.tar.gz<br />
3. sudo mv apache-tomcat-6.0.3 /usr/local/tomcat <br />
4. vi ~/.bashrc<br />
5. Add this line at the end ==> export JAVA_HOME=/usr/lib/jvm/java-6-sun<br />
6. sh /usr/local/tomcat/bin/startup.sh , sh /usr/local/tomcat/bin/shutdown.sh<br />
<br />
<br />
<br />
#To install Maven<br />
1. sudo apt-get install maven2<br />
2. sudo apt-get install ant<br />
3. sudo apt-get install maven-ant-helper<br />
<br />
<br />
#To install jConnector<br />
1. wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.0.8.tar.gz/from/http://mysql.mirrors.hoobly.com/<br />
2. tar xvzf mysql-connector-java-5.0.8.tar.gz<br />
<br />
<br />
#To install CAS server software<br />
1. wget http://www.ja-sig.org/downloads/cas/cas-server-3.3.3-release.tar.gz<br />
2. tar xvzf cas-server-3.3.3-release.tar.gz<br />
3. cd cas-server-3.3.3<br />
4. cd cas-server-webapp<br />
5. Edit pom.xml and add the following lines before ending '' tag:<br />
<br />
<dependency><br />
<groupid>${project.groupId}</groupid><br />
<artifactid>cas-server-support-jdbc</artifactid><br />
<version>${project.version}</version><br />
</dependency><br />
<dependency><br />
<groupid>commons-dbcp</groupid><br />
<artifactid>commons-dbcp</artifactid><br />
<version>1.2.1</version><br />
<scope>runtime</scope><br />
</dependency><br />
<dependency><br />
<groupid>mysql</groupid><br />
<artifactid>mysql-connector-java</artifactid><br />
<version>5.0.8-bin</version><br />
<scope>provided</scope><br />
</dependency><br />
<br />
6. [Dont change the current directory!]<br />
<br />
a) mvn install:install-file -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=5.0.8-bin -Dpackaging=jar -Dfile=/home/<user>/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar<br />
<br />
b) mvn package install <br />
<br />
<br />
7. cp target/cas.war /usr/local/tomcat/webapps/<br />
8. sudo /usr/local/tomcat/bin/startup.sh<br />
9. Go : http://servername:8080/cas/ to check whether server is running or not.<br />
<br />
<br />
10. cp ~/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar /usr/local/tomcat/webapps/cas/WEB-INF/lib/<br />
<br />
<br />
11. Create table <br />
<br />
CREATE TABLE users (username char(20) PRIMARY KEY NOT NULL, password char(64));<br />
INSERT INTO users(username, password) VALUES ('test',MD5('test'));<br />
<br />
12. cd /usr/local/tomcat/webapps/cas/WEB-INF/<br />
13. Open file deployerConfigContext.xml and <br />
<br />
Search for the following line:<br />
<br />
<bean class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler"><br />
<br />
Replace it with :<br />
<br />
<bean class="org.jasig.cas.adaptors.jdbc.SearchModeSearchDatabaseAuthenticationHandler"><br />
<property name="tableUsers"><br />
<value>users</value><br />
</property ><br />
<property name="fieldUser"><br />
<value>username</value><br />
</property><br />
<property name="fieldPassword"><br />
<value>password</value><br />
</property><br />
<property name="passwordEncoder"><br />
<bean class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"><br />
<constructor-arg value="MD5"> </constructor-arg> </bean><br />
<property name="dataSource" ref="dataSource"><br />
</property><br />
<br />
<br />
14. In deployerConfigContext.xml, just before ending of the </property> tag, add the following:<br />
<br />
<br />
<bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSource"><br />
<property name="driverClassName"><br />
<value>com.mysql.jdbc.Driver</value><br />
</property><br />
<property name="url"><br />
<value>jdbc:mysql://localhost:3306/casdb</value> <br />
</property><br />
<property name="username"><br />
<value>root</value> <br />
</property><br />
<property name="password"><br />
<value>root</value> <br />
</property><br />
</bean><br />
<br />
15. Restart Tomcat server and recheck.<br />
<br />
16. Use CAS library phpCAS version 1.1.0 for proper functionality<br />
17. check whether the CAS server has https enabled or not.(Redirects to https page.)<br />
<br />
<br />
<br />
<br />
<br />
#To install SSL on tomcat<br />
<br />
1. $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA [Specify a password value of "changeit"]<br />
it will generate a .keystore file at the home of the server /home/<user>/.keystore<br />
<br />
2. Open /usr/local/tomcat/server.xml and do the followings:<br />
<br />
Find a connector having port="8443";<br />
<br />
Now uncomment the section and make the line as following:<br />
<br />
<connector maxthreads="200" port="8443"><br />
scheme="https" secure="true" SSLEnabled="true"<br />
keystoreFile="/home/anish/.keystore" keystorePass="changeit"<br />
clientAuth="false" sslProtocol="TLS"/><br />
<br />
<br />
Also comment this line: '<listener classname="org.apache.catalina.core.AprLifecycleListener" sslengine="on">'<br />
<br />
3. Edit /usr/local/tomcat/conf/tomcat-users.xml to add users to manage tomcat server<br />
<br />
<br />
#######################################################################################################################<br />
Finally VVV Important ==> In CAS settings page, Set CAS version to 1.0, If you put 2.0 or higher , it will throw error.<br />
########################################################################################################################</listener></connector></user></bean></bean></user></div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com0tag:blogger.com,1999:blog-1817729882430277165.post-37982673755096892882011-05-18T18:19:00.000-07:002011-10-15T22:48:57.353-07:00Sample Interview Questions for Drupal Themer<div><p>General questions</p>
<p>1. What is a theme override?<br>
2. What's the difference between a theme override and a template file?<br>
3. Where is the place for placing a theme override?<br>
4. Where is the place for placing a template file? What are the differences in template files on D5 and D6?<br>
5. What are the template files involved in theming an Ubercart invoice?<br>
6. Have you worked with 960gs before? If not, have you worked with any kind of grid layout framework? Even if you have no experience with this, you should take a quick look at both the drupal theme and the 960gs framework and comment how you see working with 960gs can help you when developing a drupal theme.</p>
<p>Questions on theme development<br>
A simple e-commerce site is needed - all the functionality has been coded. Regular static pages (about us, contact us, terms and conditions etc) plus a product with several fields (title, size, color, body, main image, additional images, price, SKU, etc.)</p>
<p>We assume you have knowledge of CCK & Views as those modules would be used both for creating the content types and working on different displays that will probably need to be themed. We are going to use imagefield module for the images and imagecache module for thumbs and other images sizes.</p>
<p>In your answers, we are looking for certain basics on drupal theme development, you don't need to provide any code, just brief answers that indicate how you would handle each point. Please explain the specifics involved in a proper drupal theme, such as template files that you might use, what alternatives around drupal (modules, etc.) you can suggest or what function (don't need the exact name) you think you would override.<br><br></p>
<p>1. How would you work with the main images and the additional images on the theme? What would you do and what templates file are you planning on changing?<br>
2. How would you work on the the theme to selectively display certain fields of the product in a very specific way to match a design, something that's not configurable through the content type display administration section?<br>
3. How would you display the main image with a normal size and additional images as thumbnails just below the main image, in a grid-like form displaying three per row. Also, what would you do if an image swap effect between the thumbnail and the main image is required?<br>
4. If we need a block display up to 6 products in a 3 column scheme on top of the content, how would you do this?<br>
5. How would you theme the checkout page of an Ubercart e-commerce site?</p>
</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com11tag:blogger.com,1999:blog-1817729882430277165.post-67822341743875745142011-05-15T09:10:00.000-07:002013-09-28T07:25:59.403-07:00Interview Questions for Drupal.<div dir="ltr" style="text-align: left;" trbidi="on"><style type="text/css">
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
</style> <b>1. What is CMS?</b><br />
A content management system (CMS) is a collection of procedures used to manage work flow in a collaborative environment. These procedures can be manual or computer-based. The procedures are designed to:<br />
* Allow for a large number of people to contribute to and share stored data<br />
* Control access to data, based on user roles. User roles define what information each user can view or edit<br />
* Aid in easy storage and retrieval of data<br />
* Reduce repetitive duplicate input<br />
* Improve the ease of report writing<br />
* Improve communication between users<br />
In a CMS, data can be defined as almost anything – documents, movies, pictures, phone numbers, scientific data, etc. CMSs are frequently used for storing, controlling, revising, semantically enriching, and publishing documentation. Content that is controlled is industry-specific. For example, entertainment content differs from the design documents for a fighter jet. There are various terms for systems (related processes) that do this. Examples are web content management, digital asset management, digital records management and electronic content management. Synchronization of intermediate steps, and collation into a final product are common goals of each.<br />
cms,drupal,drupal cms,interview questions,technical,joomla,joomla cms,drupal interview question,content management system<br />
<br />
<b>2. What is a web content Management system ?</b><br />
A Web content management system (WCM, WCMS or Web CMS) is content management system (CMS) software, implemented as a Web application, for creating and managing HTML content. It is used to manage and control a large, dynamic collection of Web material (HTML documents and their associated images). A WCMS facilitates content creation, content control, editing, and essential Web maintenance functions.<br />
The software provides authoring (and other) tools designed to allow users with little knowledge of programming languages or markup languages to create and manage content with relative ease.<br />
Most systems use a database to store content, metadata, or artifacts that might be needed by the system. Content is frequently, but not universally, stored as XML, to facilitate reuse and enable flexible presentation options.<br />
A presentation layer displays the content to Web-site visitors based on a set of templates. The templates are sometimes XSLT files.<br />
Most systems use server side caching boosting performance. This works best when the WCMS is not changed often but visits happen on a regular basis.<br />
Administration is typically done through browser-based interfaces, but some systems require the use of a fat client.<br />
Unlike Web-site builders, a WCMS allows non-technical users to make changes to a website with little training. A WCMS typically requires an experienced coder to set up and add features, but is primarily a Web-site maintenance tool for non-technical administrators.<br />
<br />
<b>3. Which are commonly used PHP based CMSs ?</b><br />
Drupal<br />
Joomla<br />
Wordpress<br />
TYPO3<br />
<br />
<b>4. What is Drupal ?</b><br />
Drupal is an open-source platform and content management system for building dynamic web sites offering a broad range of features and services including user administration, publishing workflow, discussion capabilities, news aggregation, metadata functionalities using controlled vocabularies and XML publishing for content sharing purposes. Equipped with a powerful blend of features and configurability, Drupal can support a diverse range of web projects ranging from personal weblogs to large community-driven sites.<br />
<br />
<b>5. What is an Open source software ?</b><br />
Open-source software (OSS) is computer software for which the source code and certain other rights normally reserved for copyright holders are provided under a software license that meets the Open Source Definition or that is in the public domain.This permits users to use, change, and improve the software, and to redistribute it in modified or unmodified forms. It is very often developed in a public, collaborative manner.<br />
Introduction<br />
Open source doesn’t just mean access to the source code.<br />
The distribution terms of open-source software must comply with the following criteria:<br />
<br />
<b>1. Free Redistribution</b><br />
The license shall not restrict any party from selling or giving away the software as a component of an aggregate software distribution containing programs from several different sources. The license shall not require a royalty or other fee for such sale.<br />
<br />
<b>2. Source Code</b><br />
The program must include source code, and must allow distribution in source code as well as compiled form. Where some form of a product is not distributed with source code, there must be a well-publicized means of obtaining the source code for no more than a reasonable reproduction cost preferably, downloading via the Internet without charge. The source code must be the preferred form in which a programmer would modify the program. Deliberately obfuscated source code is not allowed. Intermediate forms such as the output of a preprocessor or translator are not allowed.<br />
<br />
<b>3. Derived Works</b><br />
The license must allow modifications and derived works, and must allow them to be distributed under the same terms as the license of the original software.<br />
<br />
<b>4. Integrity of The Author’s Source Code</b><br />
The license may restrict source-code from being distributed in modified form only if the license allows the distribution of “patch files” with the source code for the purpose of modifying the program at build time. The license must explicitly permit distribution of software built from modified source code. The license may require derived works to carry a different name or version number from the original software.<br />
<br />
<b>5. No Discrimination Against Persons or Groups</b><br />
The license must not discriminate against any person or group of persons.<br />
<br />
<b>6. No Discrimination Against Fields of Endeavor</b><br />
The license must not restrict anyone from making use of the program in a specific field of endeavor. For example, it may not restrict the program from being used in a business, or from being used for genetic research.<br />
<br />
<b>7. Distribution of License</b><br />
The rights attached to the program must apply to all to whom the program is redistributed without the need for execution of an additional license by those parties.<br />
<br />
<b>8. License Must Not Be Specific to a Product</b><br />
The rights attached to the program must not depend on the program’s being part of a particular software distribution. If the program is extracted from that distribution and used or distributed within the terms of the program’s license, all parties to whom the program is redistributed should have the same rights as those that are granted in conjunction with the original software distribution.<br />
<br />
<b>9. License Must Not Restrict Other Software</b><br />
The license must not place restrictions on other software that is distributed along with the licensed software. For example, the license must not insist that all other programs distributed on the same medium must be open-source software.<br />
<br />
<b>10. License Must Be Technology-Neutral</b><br />
No provision of the license may be predicated on any individual technology or style of interface.<br />
<br />
<b>6. What are GNU Licenses ?</b><br />
Does free software mean using the GPL?<br />
Not at all—there are many other free software licenses. We have an incomplete list. Any license that provides the user certain specific freedoms is a free software license.<br />
<br />
<b>7. Why are so many Drupal versions available – 4.x, 5.x …? Which one should I use?</b><br />
It is recommended that you run the most current stable release. This can always be found at the Drupal Project page. However, if there are no compelling features in the latest version, a contrib module that is important to you isn’t ready or you don’t have time, there is no need to rush your upgrade as long as security updates are available for the version you are running.<br />
<br />
<b>8. Can I use Drupal on the command line?</b><br />
Yes, you can use drush –<br />
drush is a command line shell and Unix scripting interface for Drupal<br />
<br />
<b>9. What are hooks in Drupal ?</b><br />
Allow modules to interact with the Drupal core.<br />
Drupal’s module system is based on the concept of “hooks”. A hook is a PHP function that is named foo_bar(), where “foo” is the name of the module (whose filename is thus foo.module) and “bar” is the name of the hook. Each hook has a defined set of parameters and a specified result type.<br />
To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.<br />
<br />
<b>10 what is Database abstraction layer in Drupal ?</b><br />
Allow the use of different database servers using the same code base.<br />
Drupal provides a slim database abstraction layer to provide developers with the ability to support multiple database servers easily. The intent of this layer is to preserve the syntax and power of SQL as much as possible, while letting Drupal control the pieces of queries that need to be written differently for different servers and provide basic security checks.<br />
Most Drupal database queries are performed by a call to db_query() or db_query_range(). Module authors should also consider using pager_query() for queries that return results that need to be presented on multiple pages, and tablesort_sql() for generating appropriate queries for sortable tables.<br />
<br />
<b>11. Explain the menu system in Drupal ? Purpose of menus ?</b><br />
Define the navigation menus, and route page requests to code based on URLs.<br />
The Drupal menu system drives both the navigation system from a user perspective and the callback system that Drupal uses to respond to URLs passed from the browser. For this reason, a good understanding of the menu system is fundamental to the creation of complex modules.<br />
Drupal’s menu system follows a simple hierarchy defined by paths. Implementations of hook_menu() define menu items and assign them to paths (which should be unique). The menu system aggregates these items and determines the menu hierarchy from the paths. For example, if the paths defined were a, a/b, e, a/b/c/d, f/g, and a/b/h, the menu system would form the structure:<br />
a<br />
a/b<br />
a/b/c/d<br />
a/b/h<br />
e<br />
f/g<br />
Note that the number of elements in the path does not necessarily determine the depth of the menu item in the tree.<br />
When responding to a page request, the menu system looks to see if the path requested by the browser is registered as a menu item with a callback. If not, the system searches up the menu tree for the most complete match with a callback it can find. If the path a/b/i is requested in the tree above, the callback for a/b would be used.<br />
The found callback function is called with any arguments specified in the “page arguments” attribute of its menu item. The attribute must be an array. After these arguments, any remaining components of the path are appended as further arguments. In this way, the callback for a/b above could respond to a request for a/b/i differently than a request for a/b/j.<br />
For an illustration of this process, see page_example.module.<br />
Access to the callback functions is also protected by the menu system. The “access callback” with an optional “access arguments” of each menu item is called before the page callback proceeds. If this returns TRUE, then access is granted; if FALSE, then access is denied. Menu items may omit this attribute to use the value provided by an ancestor item.<br />
In the default Drupal interface, you will notice many links rendered as tabs. These are known in the menu system as “local tasks”, and they are rendered as tabs by default, though other presentations are possible. Local tasks function just as other menu items in most respects. It is convention that the names of these tasks should be short verbs if possible. In addition, a “default” local task should be provided for each set. When visiting a local task’s parent menu item, the default local task will be rendered as if it is selected; this provides for a normal tab user experience. This default task is special in that it links not to its provided path, but to its parent item’s path instead. The default task’s path is only used to place it appropriately in the menu hierarchy.<br />
Everything described so far is stored in the menu_router table. The menu_links table holds the visible menu links. By default these are derived from the same hook_menu definitions, however you are free to add more with menu_link_save().<br />
<br />
<b>12. How to interact with Drupal search system ?</b><br />
There are three ways to interact with the search system:<br />
Specifically for searching nodes, you can implement nodeapi(‘update index’) and nodeapi(‘search result’). However, note that the search system already indexes all visible output of a node, i.e. everything displayed normally by hook_view() and hook_nodeapi(‘view’). This is usually sufficient. You should only use this mechanism if you want additional, non-visible data to be indexed.<br />
Implement hook_search(). This will create a search tab for your module on the /search page with a simple keyword search form. You may optionally implement hook_search_item() to customize the display of your results.<br />
Implement hook_update_index(). This allows your module to use Drupal’s HTML indexing mechanism for searching full text efficiently.<br />
If your module needs to provide a more complicated search form, then you need to implement it yourself without hook_search(). In that case, you should define it as a local task (tab) under the /search page (e.g. /search/mymodule) so that users can easily find it.<br />
<br />
<b>13. What is a Module in drupal ?</b><br />
A module is software (code) that extends Drupal features and/or functionality. Core modules are those included with the main download of Drupal, and you can turn on their functionality without installing additional software. Contributed modules are downloaded from the Modules download section of drupal.org, and installed within your Drupal installation. You can also create your own modules; this requires a thorough understanding of Drupal, PHP programming, and Drupal’s module API.<br />
<br />
<b>14. Explain User, Permission, Role in drupal.</b><br />
Every visitor to your site, whether they have an account and log in or visit the site anonymously, is considered a user to Drupal. Each user has a numeric user ID, and non-anonymous users also have a user name and an email address. Other information can also be associated with users by modules; for instance, if you use the core Profile module, you can define user profile fields to be associated with each user.<br />
Anonymous users have a user ID of zero (0). The user with user ID one (1), which is the user account you create when you install Drupal, is special: that user has permission to do absolutely eveything on the site.<br />
Other users on your site can be assigned permissions via roles. To do this, you first need to create a role, which you might call “Content editor” or “Member”. Next, you will assign permissions to that role, to tell Drupal what that role can and can’t do on the site. Finally, you will grant certain users on your site your new role, which will mean that when those users are logged in, Drupal will let them do the actions you gave that role permission to do.<br />
You can also assign permissions for the special built-in roles of “anonymous user” (a user who is not logged in) and “authenticated user” (a user who is logged in, with no special role assignments). Drupal permissions are quite flexible — you are allowed to assign permission for any task to any role, depending on the needs of your site.<br />
<br />
<b>15. Explain the concept of node in drupal.</b><br />
A node in Drupal is the generic term for a piece of content on your web site. (Note that the choice of the word “node” is not meant in the mathematical sense as part of a network.) Some examples of nodes:<br />
• Pages in books<br />
• Discussion topics in forums<br />
• Entries in blogs<br />
• News article stories<br />
Each node on your site has a Content Type. It also has a Node ID, a Title, a creation date, an author (a user on the site), a Body (which may be ignored/omitted for some content types), and some other properties. By using modules such as the contributed Content Construction Kit (CCK) module, the core Taxonomy module, and the contributed Location module, you can add fields and other properties to your nodes.<br />
<br />
<b>16. Concept of Comment in Drupal .</b><br />
Comments are another type of content you can have on your site (if you have enabled the core Comment module). Each comment is a typically small piece of content that a user submits, attached to a particular node. For example, each piece of discussion attached to a particular forum topic node is a comment.<br />
<br />
<b>17 explain Taxonomy in drupal .</b><br />
Drupal has a system for classifying content, which is known as taxonomy and implemented in the core Taxonomy module. You can define your own vocabularies (groups of taxonomy terms), and add terms to each vocabulary. Vocabularies can be flat or hierarchical, can allow single or multiple selection, and can also be “free tagging” (meaning that when creating or editing content, you can add new terms on the fly). Each vocabulary can then be attached to one or more content types, and in this way, nodes on your site can be grouped into categories, tagged, or classified in any way you choose.<br />
<br />
<b>18 . How database system of drupal works ?</b><br />
Drupal stores information in a database; each type of information has its own database table. For instance, the basic information about the nodes of your site are stored in the Node table, and if you use the CCK module to add fields to your nodes, the field information is stored in separate tables. Comments and Users also have their own database tables, and roles, permissions, and other settings are also stored in database tables.<br />
<br />
<b>19. Explain the path system of drupal ?</b><br />
When you visit a URL within your Drupal site, the part of the URL after your base site address is known as the path. When you visit a path in your Drupal site, Drupal figures out what information should be sent to your browser, via one or more database queries. Generally, Drupal allows each module you have enabled on your site to define paths that the module will be responsible for, and when you choose to visit a particular path, Drupal asks the module what should be displayed on the page.<br />
For instance, this site (drupal.org) is (of course) built with Drupal. The page you are now viewing is http://drupal.org/node/19828, whose path is “node/19828″. The module that is responsible for this path is the core Node module, so when you visit this page, Drupal lets the Node module determine what to display.<br />
To determine the path to a particular page on your site, for purposes of creating a link, go to the page you want to link to and look at the URL in the address bar. By default the URL, after the base address of your site, will begin with ‘?q=’. When ‘Clean URLs’ are enabled you will see a directory structure in the URL. The “path” for use in a menu item is the part of the URL after the site’s base address and without the “?q=”.<br />
<br />
<b>20. Explain Region, Block, Menu in drupal ..</b><br />
Pages on your Drupal site are laid out in regions, which can include the header, footer, sidebars, and main content section; your theme may define additional regions. Blocks are discrete chunks of information that are displayed in the regions of your site’s pages. Blocks can take the form of menus (which are concerned with site navigation), the output from modules (e.g., hot forum topics), or dynamic and static chunks of information that you’ve created yourself (e.g., a list of upcoming events).<br />
There are three standard menus in Drupal: Primary Links, Secondary Links, and Navigation. Primary and Secondary links are built by site administrators, and displayed automatically in the page header of many themes (if not, you can enable their blocks to display them). Navigation is the catch-all menu that contains your administration menus, as well as links supplied by modules on your site. You can also create your own custom menus, and display them by enabling their blocks.<br />
You can customise menus in several ways, such as reordering menu items by setting their “weight” or simply dragging into place, renaming menu items, and changing the link title (the tooltip that appears when you mouse over a menu item). You can move a menu item into a different menu by editing the Parent property of the menu item.<br />
You can also add custom menu items to a menu, from the Add menu item tab of the Menu administration screen. To create a menu item, you will need to provide the path to the content (see above).<br />
In all cases a menu item will only be shown to a visitor if they have the rights to view the page it links to; e.g., the admin menu item is not shown to visitors who are not logged in.<br />
<br />
<b>21. How To Define New Regions in Drupal</b><br />
To add regions for Drupal 5.x<br />
ADD this code in its entirety to the bottom of your template.php file:<br />
<blockquote>/** Define the regions **/<br />
function framework_regions() {<br />
return array(<br />
‘left’ => t(‘left sidebar’),<br />
‘right’ => t(‘right sidebar’),<br />
‘content’ => t(‘content’),<br />
‘header’ => t(‘header’),<br />
‘footer’ => t(‘footer’),<br />
‘newregion’ => t(‘new region’),<br />
);<br />
}</blockquote>Replace “newregion” with what you would like to call that region instead. Note that the name on the left before the = is the machine readable format, and cannot have spaces. the name after the = is the human readable format, and can have spaces, capital letters etc. You may add as many regions as you like in the same manner that “newregion” has been added in the example above.<br />
Then, in your page.tpl.php file, define where you would like you regions to be using a print call like so:<br />
You need to replace “newregion” with what you named your region. The id, class and any other html can be changed to anything.<br />
To add regions for Drupal 6.x<br />
ADD the following code to you themename.info file:<br />
<blockquote>regions[left] = Left sidebar<br />
regions[right] = Right sidebar<br />
regions[content] = Content<br />
regions[header] = Header<br />
regions[footer] = Footer<br />
regions[newregion] = New Region</blockquote>The internal “machine” readable name in square brackets and the human readable name as the value, e.g., regions[theRegion] = The region label.<br />
The contents of the .info file is cached in the database so altering it will not be noticed by Drupal. To clear it, do ONE of the following:<br />
<b>1</b>. Clear button located at “Administer > Site configuration > Performance”.<br />
<b>2</b>. With devel block enabled (comes with devel module), click the “Empty cache” link.<br />
<b>3</b>. Simply visit the theme select page at “Administer > Site building > Themes”.<br />
Then, in your page.tpl.php file, define where you would like you regions to be using a print call like so:<br />
You need to replace “newregion” with what you named your region. The id, class and any other html can be changed to anything.<br />
<br />
<b>22. Explain the function and working of Dashboard module ?</b><br />
The Dashboard module provides a Dashboard page in the administration menu. The intention of the Dashboard page is to give administrators a quick overview of important information on the website.<br />
<br />
<b>23. List the modules required for building a social networking website in Drupal.</b><br />
• Activity<br />
• Advanced Forum<br />
• Advanced Profile Kit<br />
• Application Toolbar (Appbar)<br />
• Author Pane<br />
• Buddylist2 Package<br />
• Buddylist: list your social network<br />
• CiviCRM: manage community contacts, relationships, and activities<br />
• CiviNode and CiviNode CCK: Tools For Integrating CiviCRM Contacts Into Drupal Content<br />
• Comment Notify<br />
• FOAF: friends of a friend<br />
• Facebook-style Statuses<br />
• Family: Record, display, and analyze genealogical data.<br />
• Flag Friend<br />
• Friend<br />
• FriendList<br />
• Front: Show group membership and events<br />
• Gigya Socialize Module<br />
• Invite: send invitations to join your site<br />
• Notice Feed<br />
• Organic Group<br />
• Profile Setup<br />
• Radioactivity<br />
• Sports Pickem<br />
• Tellafriend Node<br />
• User Invite<br />
• User Relationships<br />
• UserTag:Tag users with taxonomy terms<br />
• meetü: The Social Networking Game from the OPL @ RIT<br />
<br />
<b>24. List the SEO modules available in Drupal.</b><br />
1. Pathauto<br />
2. Nodewords/ Meta tags<br />
3. Service links<br />
4. Google analytics<br />
5. Related Links<br />
6. Search 404<br />
7. Site map<br />
8. Url list<br />
<br />
<b>25. How to post videos from mobile to Drupal website ?</b><br />
Posting video from mobile phone to drupal website via email requests from user to configure a mobile phone with smtp settings and reasonable Internet connection (3g). Costs depends from your mobile phone provider: at some networks you pay only for transfer volume, at others you might pay for “event” of establishing connection.<br />
On server side you will probably need to setup smtp server and provide access to it to users of your website. Transcoding of posted video employs ffmpeg, its standard software on proper hosting server.<br />
Process Overview<br />
<b>1</b>. Email with video attachment from mobile phone is sent to a defined mailbox<br />
<b>2</b>. Drupal website downloads Mail on cron (mailhandler module)<br />
<b>3</b>. Emails are turned into nodes with videos as attachments<br />
<b>4</b>. Media Mover runs on cron, trans-coding mobile video formats and creating thumbnails<br />
<b>5</b>. Transcoded flash video files are added to cck file field<br />
<b>6.</b> Thumbnail added to file field<br />
<b>7</b>. Nodes are themed using swftools to display video using “JWplayer”<br />
<br />
<b>Modules used</b><br />
• Mailhandler<br />
• Mailssave<br />
• Mediamover<br />
• SWFTools<br />
• FFMPEG_wrapper<br />
• cck<br />
• filefield<br />
• imagefield<br />
<br />
<b>26. What is a patch?</b><br />
A patch is a file that consists of a list of differences between one set of files and another. All code changes, additions, or deletions to Drupal core and contributed modules/themes between developers are done through patches.<br />
The differences are presented in a structured, standard way, which means that a program (also named patch) can be used to apply the changes to another copy of the original file.<br />
<br />
<b>27. What is difference between Diff and Patch ?</b><br />
diff creates patch<br />
In simple terms, the diff command is used to compare differences between two versions of a file. The resulting file is called a patch, and typically is given (by the user) a “.patch” suffix.<br />
This patch file then can be used on other copies of the “old” file by using the patch command, thus updating their “old” file(s) to match the “new” file(s).<br />
Why you would use diff<br />
When might one use diff to create a patch file? Let’s say you are customizing a module to fix a bug, and have saved a new version of the module. How will you pass on your bug fix to others? Simply passing on your version of the module may not work, because it’s quite possible someone else has modified some other aspect of the code at the same time and you both would be overwriting each others’ changes.<br />
So instead, what you do is run diff between the two files, and then upload the resulting patch — which others can then apply to their files using the patch command. (And you can apply other people’s patches against your files, without losing your own changes.)<br />
The added benefit of this type of workflow is that changes to the code can easily be tracked — and undone, if necessary — which is essential in a community-developed project such as Drupal.<br />
<br />
<b>28. List the features of Drupal ?</b><br />
1. Rock solid & high quality platform<br />
2. Powerful templating system. Any XHTML or CSS template can be easily converted to Drupal<br />
3. Real multi-site-feature (only one installation for several sites)<br />
4. Any Kind of user groups & user permissions, OpenId compliant in Version 6<br />
5. Can run membership and community sites, not only CMS etc<br />
6. Clear, high quality code and API (easy to integrate with other solutions etc)<br />
<br />
<b>29. How to port a joomla template to drupal ?</b><br />
For explanation please visit<br />
http://drupal.org/node/198333<br />
<br />
<b>30. Explain the capabilities of views module.</b><br />
The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented. Traditionally, Drupal has hard-coded most of this, particularly in how taxonomy and tracker lists are formatted.<br />
This tool is essentially a smart query builder that, given enough information, can build the proper query, execute it, and display the results. It has four modes, plus a special mode, and provides an impressive amount of functionality from these modes.<br />
Among other things, Views can be used to generate reports, create summaries, and display collections of images and other content.<br />
<br />
<b>31. What are systems requirements for drupal installation ?</b><br />
- 3MB of disk space<br />
- If you install many contributed modules and contributed themes, the actual disk space for your installation could easily be 40 MB or more (exclusive of database content, media, backups and other files).<br />
Web Server<br />
Drupal has been deployed successfully on both Apache and IIS.<br />
Drupal is being developed to be web server independent, but we have limited or no reports of successful use on web servers not listed here.<br />
Database server<br />
Recommended: MySQL 4.1 or MySQL 5.0<br />
PostgreSQL 7.4 or higher<br />
<br />
<b>32. What are the browser requirements for Drupal ?</b><br />
Websites built using just Drupal core (i.e. with no additional, contributed modules) are compatible with, and fully functional, in all modern browsers that support CSS and JavaScript. However, browsers have varying levels of compliance with Internet standards such as CSS 2, so there may be minor variations in appearance.<br />
Here is an incomplete list of browsers that are known to work well with Drupal core and support all of its features:<br />
• Internet Explorer 6.x and later<br />
• Firefox 2.x and later<br />
• Opera 7 and later<br />
• Safari 1.x and later<br />
• Camino 1.x and later<br />
• Google Chrome<br />
It’s worth mentioning here that IE6 has an problem with loading more than 30 stylesheets, and it’s fairly easy to run into this problem once you start adding contrib modules.<br />
PHP<br />
Recommended: PHP 5.2.x<br />
Required: PHP version 4.3.5 or higher (Contributed modules may not support this version of PHP)<br />
<br />
<b>33. What is PDO?</b><br />
PDO is an acronym for PHP Data Objects. PDO is a lean, consistent way to access databases. This means developers can write portable code much easier. PDO is not an abstraction layer like PearDB. PDO is a more like a data access layer which uses a unified API (Application Programming Interface).<br />
<br />
<b>34. How to enable clean urls in drupal ?</b><br />
The standard Drupal installation contains a sample .htaccess file which supports clean URLs. It is easy to miss copying this file, because of the leading “dot”. So before trying to enable Clean URLs, make sure this file exists in your Drupal installation.<br />
Drupal 6.x<br />
In Drupal 6, the installer tests for compatibility with Clean URLs as a part of the installation process.<br />
Drupal 5.x<br />
Goto the administer >> site configuration >> clean urls section of the administrative interface.<br />
Clean urls can be enabled by following the above two options in respective versions of drupal website.<br />
<br />
<b>35. Which are the core required modules in drupal 6.x ?</b><br />
1. Block — Controls the boxes that are displayed around the main content.<br />
2. Filter — Handles the filtering of content in preparation for display.<br />
3. Node — Allows content to be submitted to the site and displayed on pages.<br />
4. System — Handles general site configuration for administrators.<br />
5. User — Manages the user registration and login system.<br />
<br />
<b>36. Is it possible to disable the core required modules through drupal admin ?</b><br />
No, it is not possible to disable the core required modules.<br />
<br />
<b>37. Which are the core optional modules in drupal 6.x ?</b><br />
1. Aggregator Aggregates syndicated content (RSS, RDF, and Atom feeds).<br />
2. Blog Enables keeping easily and regularly updated user web pages or blogs.<br />
3. Blog API Allows users to post content using applications that support XML-RPC blog APIs.<br />
4. Book Allows users to structure site pages in a hierarchy or outline.<br />
5. Color Allows the user to change the color scheme of certain themes.<br />
6. Comment Allows users to comment on and discuss published content.<br />
7. Contact Enables the use of both personal and site-wide contact forms.<br />
8. Content translation Allows content to be translated into different languages.<br />
9. Database logging Logs and records system events to the database.<br />
10. Forum Enables threaded discussions about general topics.<br />
11. Help Manages the display of online help.<br />
12. Locale Adds language handling functionality and enables the translation of the user interface to languages other than English.<br />
13. Menu Allows administrators to customize the site navigation menu.<br />
14. OpenID Allows users to log into your site using OpenID.<br />
15. Path Allows users to rename URLs.<br />
16. PHP filter Allows embedded PHP code/snippets to be evaluated.<br />
17. Ping Alerts other sites when your site has been updated.<br />
18. Poll Allows your site to capture votes on different topics in the form of multiple choice questions.<br />
19. Profile Supports configurable user profiles.<br />
20. Search Enables site-wide keyword searching.<br />
21. Statistics Logs access statistics for your site.<br />
22. Syslog Logs and records system events to syslog.<br />
23. Taxonomy Enables the categorization of content.<br />
24. Throttle Handles the auto-throttling mechanism, to control site congestion.<br />
25. Tracker Enables tracking of recent posts for users.<br />
26. Trigger Enables actions to be fired on certain system events, such as when new content is created.<br />
27. Update status Checks the status of available updates for Drupal and your installed modules and themes.<br />
28. Upload Allows users to upload and attach files to content.<br />
<br />
<b>38. what a module is in Drupal and what the process of writing one involves?</b><br />
When developers learn that modifying Drupal’s core code is a no-no, they often have a panic moment. “How, then will I bend Drupal to do my will?,” they ask. Easy: by writing a module. The first part of writing a module is writing a .info file, where you describe your module to Drupal. Here’s an example from the Forum Module:<br />
; $Id: forum.info,v 1.6 2007/06/08 05:50:54 dries Exp $<br />
name = Forum<br />
description = Enables threaded discussions about general topics.<br />
dependencies[] = taxonomy<br />
dependencies[] = comment<br />
package = Core – optional<br />
core = 6.x<br />
This gives Drupalenough information to list the module on the modules administration page, and to tell whether the module is compatible with the version of Drupal being run (in this case, 6.x). Drupal will also make sure the dependent modules are present.<br />
A module may have a .install file containing code that runs when the module is first installed. For example, some database tables may be needed, or some values may need to be initialized in Drupal’s persistent variable system.<br />
Finally, the .module file itself contains the code that does whatever it is that your module will do. And that’s just about anything. There were 3,430 modules in the repository last time I checked, so it’s a good idea to check if the module you’re thinking about writing is already written. Drupal Modules is a good place to do that.<br />
New Drupal developers are also often stymied by the question “When does my code run? I put it in a module, but when does the module run?” Answering that question requires understanding of the Inversion of Control design pattern that Drupal uses, often called “hooks” or “callbacks”. You name your functions in a certain way, and Drupal will automatically call your code at the appropriate time, depending on how you’ve named the functions.<br />
source: http://ostatic.com/blog/interview-john-vandyk-author-of-pro-drupal-development<br />
<br />
<b>39. Drupal is flexible at handling events automatically and employing triggers. How do developers make use of these features?</b><br />
There are really two answers here. At the code level, that’s always what Drupal has been about: having your code run when a certain event happens. For example, the following code would send a tweet to my Twitter account every time someone logs in to the Drupal site (it requires the third-party Twitter Module to be installed to do the dirty work).<br />
function mymodulename_user($op, &$edit, &$account) {<br />
if ($op == ‘login’) {<br />
// Bring twitter-related functions into scope.<br />
module_load_include(‘inc’, ‘twitter’);<br />
// Use t() for proper localization.<br />
$text = t(‘@username logged in’, array(‘@username’ => $account->name));<br />
// Post to twitter using the twitter module.<br />
twitter_set_status(‘clouseau’, ‘secret’, $text);<br />
}<br />
}<br />
That’s fine if you are a programmer. But what if we took the whole idea of “Send a message to Twitter” and abstracted it? Then we could use a nice user interface to associate the action “Send a message to Twitter” with one of Drupal’s common events, such as when a user logs in, or posts content, or creates a new account. That is what the new features in Drupal 6 provide: the user interface for doing such associations between actions and events. A trigger is an event that has been exposed in the user interface.<br />
You can also create your own triggers. Perhaps you want to go the other way: you want actions to happen in Drupal when a new tweet is posted to your Twitter account! Chapter 3 of the book tells you how to make your own triggers.<br />
source: http://ostatic.com/blog/interview-john-vandyk-author-of-pro-drupal-development<br />
<br />
<b>40. The search features in Drupal are excellent, as compared to search in other content management systems. What makes these so good?</b><br />
Drupal’s search is so good because Drupal doesn’t treat its content as a big bucket of text; rather, all of the fine-grained semantic information that Drupal knows about can be used to fine-tune search results. That includes the type of content, any classification information from the taxonomy system, and the usual content metadata. Inside the search engine is an extensible indexer that can accept pretty much anything. In the book, one of the examples uses Drupal to index an external non-Drupal database.<br />
And as usual, you can tweak and override the search system to adjust the user interface, the way content is ranked, and the way results are displayed. That said, Drupal integrates well with external search engines such as Apache Solr, Xapian, and Sphinx if the built-in Drupal search does not meet your needs.<br />
source: http://ostatic.com/blog/interview-john-vandyk-author-of-pro-drupal-development<br />
<br />
<br />
<br />
</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com17tag:blogger.com,1999:blog-1817729882430277165.post-88362433411799997872011-05-07T08:31:00.000-07:002011-05-07T08:31:28.699-07:00How Drupal's Menu System Work?<div dir="ltr" style="text-align: left;" trbidi="on">The Drupal menu system drives both the navigation system from a user perspective and the callback system that Drupal uses to respond to URLs passed from the browser. For this reason, a good understanding of the menu system is fundamental to the creation of complex modules.<br />
Drupal's menu system follows a simple hierarchy defined by paths. Implementations of hook_menu() define menu items and assign them to paths (which should be unique). The menu system aggregates these items and determines the menu hierarchy from the paths. For example, if the paths defined were a, a/b, e, a/b/c/d, f/g, and a/b/h, the menu system would form the structure:<br />
<br />
a<br />
a/b<br />
a/b/c/d<br />
a/b/h<br />
e<br />
f/g<br />
<br />
Note that the number of elements in the path does not necessarily determine the depth of the menu item in the tree.<br />
<br />
When responding to a page request, the menu system looks to see if the path requested by the browser is registered as a menu item with a callback. If not, the system searches up the menu tree for the most complete match with a callback it can find. If the path a/b/i is requested in the tree above, the callback for a/b would be used.<br />
<br />
The found callback function is called with any arguments specified in the "page arguments" attribute of its menu item. The attribute must be an array. After these arguments, any remaining components of the path are appended as further arguments. In this way, the callback for a/b above could respond to a request for a/b/i differently than a request for a/b/j.<br />
<br />
For an illustration of this process, see page_example.module.<br />
Access to the callback functions is also protected by the menu system. The "access callback" with an optional "access arguments" of each menu item is called before the page callback proceeds. If this returns TRUE, then access is granted; if FALSE, then access is denied. Menu items may omit this attribute to use the value provided by an ancestor item.<br />
<br />
In the default Drupal interface, you will notice many links rendered as tabs. These are known in the menu system as "local tasks", and they are rendered as tabs by default, though other presentations are possible. Local tasks function just as other menu items in most respects. It is convention that the names of these tasks should be short verbs if possible. In addition, a "default" local task should be provided for each set. When visiting a local task's parent menu item, the default local task will be rendered as if it is selected; this provides for a normal tab user experience. This default task is special in that it links not to its provided path, but to its parent item's path instead. The default task's path is only used to place it appropriately in the menu hierarchy.<br />
<br />
Everything described so far is stored in the menu_router table. The menu_links table holds the visible menu links. By default these are derived from the same hook_menu definitions, however you are free to add more with menu_link_save(). </div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com3tag:blogger.com,1999:blog-1817729882430277165.post-17195598912080245982011-05-01T18:29:00.000-07:002011-05-01T18:31:45.780-07:00How to Set Up a Multisite Drupal Installation?<div dir="ltr" style="text-align: left;" trbidi="on">Multisite 10 minute Install:<br />
<ul><li> Server: LAMP </li>
<li> SSH (telnet) Client: ssh (PuTTY if you are using Windows to access your LAMP host) </li>
<li> Must have root access to your server. </li>
</ul>If website in question is an addon domain, i.e., addon.example.com, then substitute "addon" for "www" in steps below.<br />
For list of Linux commands visit: <a href="http://www.oreillynet.com/linux/cmd/" rel="nofollow" title="http://www.oreillynet.com/linux/cmd/">http://www.oreillynet.com/linux/cmd/</a> or <a href="http://www.ss64.com/bash/" rel="nofollow" title="http://www.ss64.com/bash/">http://www.ss64.com/bash/</a><br />
Here we go:<br />
[login via ssh / PuTTY]<br />
<br />
<h2>Debian (Ubuntu) </h2>Debian and offshoot distributions (e.g. Ubuntu) make installation and configuration very easy. This was done on a Debian distribution, Ubuntu should work identically.<br />
<br />
<h3>Installation </h3>Assumption: apache2 and mysql are already installed. If not, use <code>apt-get install</code> to install and configure them.<br />
<code># apt-get install drupal6</code><br />
Answer the questions. This will install everything necessary to run drupal and do the basic configuration, including creating an empty database for drupal.<br />
<ul><li> Configure database for drupal6 with dbconfig-common? [YES] </li>
<li> Database type to be used by drupal6: [mysql] </li>
<li> Password of your database's administrative user: [enter mysql root password] </li>
<li> MySQL application password for drupal6: [create a password for your drupal6 db] </li>
<li> (enter the password again for verification) </li>
</ul>You now have a basic <i>unconfigured</i> Drupal6 installation using the database <code>drupal6</code> and accessible at <code>http://www.example.com/drupal6</code>. <i>Do not use it.</i> This is the "prototype" installation that we will use to create the sites we really want to use.<br />
<h3> </h3><h3>Create Site Databases </h3>The easiest way to create databases for your sites is to use <code>dpkg-reconfigure</code> and answer the questions.<br />
<code># dpkg-reconfigure drupal6</code><br />
<ul><li> Re-install database for drupal6? [YES] </li>
<li> Database type to be used by drupal6: [mysql] </li>
<li> Connection method for MySQL database of drupal6: [unix socket] </li>
<li> Name of your database's administrative user: [root] </li>
<li> Password of your database's administrative user: [enter mysql root password] </li>
<li> username for drupal6: [ENTER YOUR DB SITE *USERNAME* HERE (e.g. mysite)] </li>
<li> database name for drupal6: [ENTER YOUR DB *SITE* NAME HERE (e.g. mysite)] </li>
</ul>Notes:<br />
<ol><li> Repeat the above for each site you want to support. </li>
<li> I used the same name for the database and the site. KISS. </li>
<li> Don't use periods (e.g. mysite.com is a bad choice). If you want to spell out the whole name, use underscores instead of periods (e.g. mysite_com). </li>
<li> The above method ends up using the same site database password for all the sites you create. Advice: use <code>mysql-admin</code> (or <code>mysql</code>) to use different passwords for each site. </li>
</ol><br />
<ol></ol><h3>Configure Apache2 for Sites </h3>Before you jump to configure your virtual hosts do not forget to add host names in /etc/hosts file.<br />
<br />
<div class="codeblock"><code>your.ip.add.res vritualhost_1.name<br />
your.2.ip.add.res virtualhost_2.name</code></div>Apache2 needs to be configured to support <code>vhost</code> access to your new sites.<br />
Create <code>vhost</code> site configuration files in <code>/etc/apache2/sites-available/</code><br />
<div class="codeblock"><code>#<br />
# Virtual hosting configuration for Drupal<br />
#<br />
<br />
<virtualhost *:80=""><br />
ServerAdmin [your email address]<br />
<br />
DocumentRoot /usr/share/drupal6/<br />
ServerName [your vhost#1 name]<br />
ServerAlias [if you want to support <a href="http://www.example.com/" rel="nofollow" title="www.example.com">www.example.com</a> and example.com]<br />
RewriteEngine On<br />
RewriteOptions inherit</virtualhost><br />
<br />
<virtualhost *:80=""><br />
ServerAdmin [your email address]<br />
<br />
DocumentRoot /usr/share/drupal6/<br />
ServerName [your vhost#2 name]<br />
ServerAlias [if you want to support <a href="http://www.example1.com/" rel="nofollow" title="www.example1.com">www.example1.com</a> and example1.com]<br />
RewriteEngine On<br />
RewriteOptions inherit</virtualhost><br />
<br />
[...repeat for all your vhosts]</code></div>Notes:<br />
<ul><li> Modify the above items that are in <code>[square brackets]</code>. </li>
<li> You likely will want to support port 443 (<code>https</code>) as well. See Apache documentation for detailed instructions. </li>
<li> I've chosen to put all the vhosts in one file named <code>drupal</code>. You may want to use one file per vhost. </li>
</ul>Sym-link the <code>drupal</code> file in the <code>sites-enabled</code> directory to enable it in your site:<br />
<div class="codeblock"><code># cd /etc/apache2/sites-enabled<br />
# ln -s ../sites-available/drupal .</code></div><br />
...and reload Apache2 to pick up your configuration changes...<br />
<div class="codeblock"><code># /etc/init.d/apache2 reload</code></div><h3>Create Drupal Site Configurations </h3>We need to create Drupal configurations for each site by copying the default configuration to the Drupal site subdirectory.<br />
<div class="codeblock"><code># cd /etc/drupal/6/sites/<br />
# cp -a default [site1.com]<br />
# cp -a default [site2.com]<br />
:<br />
:</code></div><br />
...and edit the configurations to use the right database, MySQL user name, and password...<br />
<div class="codeblock"><code># vi site1.com/dbconfig.php <br />
# vi site2.com/dbconfig.php <br />
:<br />
:</code></div>Notes:<br />
<ul><li> Modify the above items that are in <code>[square brackets]</code>. </li>
</ul><h3> </h3><h3>Run Drupal and Configure Your Sites </h3>Browse to your sites, running <code>install.php</code> (e.g. <code>http://www.example.com/install.php</code>) to configure them.<br />
<h2> </h2><h2>Manual </h2>Get to location where Drupal core will be located:<br />
<code>[/]# cd /var/www</code><br />
Upload Drupal core:<br />
"x.x" should be replaced with the version of Drupal you're installing, e.g. "5.2"<br />
<code>[/var/www]# wget http://ftp.osuosl.org/pub/drupal/files/projects/drupal-x.x.tar.gz</code><br />
Unpack Drupal core:<br />
<code>[/var/www]# tar -zxvf drupal-5.2.tar.gz</code><br />
Move contents of Drupal core (including .htaccess) to html:<br />
<code>[/var/www]# mv drupal-x.x/* drupal-x.x/.htaccess /var/www/html</code><br />
Clean-up:<br />
<div class="codeblock"><code>[/var/www]# rm drupal-x.x.tar.gz<br />
<br />
[/var/www]# rm drupal-5.2</code></div>Create the files directory per Drupal instructions and change permissions (will change permission again after install):<br />
<div class="codeblock"><code>[/var/www]# cd html<br />
<br />
[/var/www/html]# mkdir files<br />
<br />
[/var/www/html]# chmod 777 files</code></div>Make directories that will hold custom and contributes modules and themes:<br />
<div class="codeblock"><code>[/var/www/html]# cd sites/all<br />
<br />
[/var/www/html/sites/all]# mkdir modules<br />
<br />
[/var/www/html/sites/all]# mkdir themes<br />
<br />
[/var/www/html/sites/all]# cd modules<br />
<br />
[/var/www/html/sites/all/modules]# mkdir custom<br />
<br />
[/var/www/html/sites/all/modules]# mkdir contrib<br />
<br />
[/var/www/html/sites/all/modules]# cd ../<br />
<br />
[/var/www/html/sites/all]# cd themes<br />
<br />
[/var/www/html/sites/all/themes]# mkdir custom<br />
<br />
[/var/www/html/sites/all/themes]# mkdir contrib</code></div>Create directory "www.example.com.tld":<br />
<div class="codeblock"><code>[/var/www/html/sites/all/themes]# cd ../<br />
<br />
[/var/www/html/sites/all]# cd ../<br />
<br />
[/var/www/html/sites]# mkdir www.example.com</code></div>Change permission of "settings.php" per Drupal instructions and copy "settings.php" in default to <a href="http://www.example.com/" rel="nofollow" title="">www.example.com:</a><br />
<div class="codeblock"><code>[/var/www/html/sites]# cd default<br />
<br />
[/var/www/html/sites/default]# chmod 777 settings.php<br />
<br />
[/var/www/html/sites/default]# cd ../<br />
<br />
[/var/www/html/sites]# cp -a default www.example.com</code></div>Create database and user with permissions:<br />
<div class="codeblock"><code>[/var/www/html/sites]# mysql<br />
<br />
mysql> CREATE DATABASE wwwexamplecom_drupal;<br />
<br />
mysql> GRANT ALL PRIVILEGES ON wwwwexamplecom_drupal_drupal.* TO 'wwwexamplecom_drupal_myusername'@'localhost' IDENTIFIED BY 'mypassword';</code></div>mysql> \q<br />
Go back to PuTTY to chmod on settings.php in <a href="http://www.example.com/" rel="nofollow" title="">www.example.com:</a><br />
<div class="codeblock"><code>[/var/www/html/sites]# cd www.example.com<br />
<br />
[/var/www/html/sites/www.example.com]# chmod 755 settings.php<br />
<br />
[/var/www/html/sites/www.example.com]# logout</code></div>What next?:<br />
<ul><li>Make changes to "settings.php" in <a href="http://www.example.com/" rel="nofollow" title="www.example.com">www.example.com</a>? I've read that it's not necessary to make changes to setting.php.</li>
<li>Make changes to "httpd.conf" in /usr/local/apache/conf?</li>
</ul>I've been using WHM to create accounts, putting Drupal in public_html and having no problems. But when it comes to parting from the WHM abstraction and getting multisite set-up correctly this is the end of the proverbial road for me.<br />
Could use help...:<br />
<ol><li>Help making improvements to steps articulated above</li>
<li>Help with next steps so that I/we can get on to grander things, like creating modules, custom themes, profiles, (and maybe - just maybe - spend some time working on business strategy :-)</li>
</ol><br />
<h5>TESTING YOUR MULTISITE INSTALLATION(S)</h5>Now that we have successfully setup both our multisite installations (1 & 2), we can proceed to test our installation to see how this will benefit us in the future for accomplishing tasks much quicker between sites that rely on the same code base or share similar modules & themes.<br />
<ol><li> Download the latest version of your favorite drupal 6 module. Here we will be using "Views".</li>
<li> Place the "Views" module inside of your main sites drupal modules folder: <strong>multisite-main/sites/all/modules/views</strong>, this module will now be shared across all multisite installations. Same goes for any themes you setup in the <strong>/sites/all/themes</strong> folder. You may now enable it for individual sites by visiting your sites "<strong>admin/build/modules</strong>" page. (ie. <strong>http://multisite-1/multisite-main/admin/build/modules</strong>).</li>
<li> Likewise, if you do not want to share modules/themes across sites you would create a "<strong>modules</strong>" or "<strong>themes</strong>" folder inside of your <strong>multisite-1</strong> or <strong>multisite-2</strong> folder, and place your site specific modules inside of them.</li>
</ol><br />
<ol></ol></div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com1tag:blogger.com,1999:blog-1817729882430277165.post-45796467751144937782011-04-25T12:10:00.000-07:002011-06-21T10:41:56.682-07:00Drupal 7 Views 2.0 Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">Finally here is a good screencast about Drupal 7 Views 3.0 . Views 3 has lot of new functionalities as compared to its previous version. I will gather more good tutorials on views and will publish them on this blog. There are other related videos regarding this video in youtube. However I post them here if I found them useful. So , see the video , do some experiments and enjoy! <br />
<br />
<br />
<br />
<br />
<object height="349" width="425"><param name="movie" value="http://www.youtube.com/v/1z13ylwMhk4?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/1z13ylwMhk4?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="349"></embed></object></div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com9tag:blogger.com,1999:blog-1817729882430277165.post-48025232359713719902011-04-24T11:10:00.000-07:002011-04-24T11:10:00.246-07:00Drupal Forms API Reference<div dir="ltr" style="text-align: left;" trbidi="on">The Drupal forms API is a powerful leap forward. It also allows for almost unlimited possibilities for custom theming, validation, and execution of forms. Even better, ANY form (even those in core) can be altered in almost any way imaginable--elements can be removed, added, and rearranged. This page is certainly not a comprehensive guide to this functionality, but should provide a good working foundation with which to do the most basic form creation, theming, validation, and execution. For programming details on form elements and their properties, please see the <a href="http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6">Forms API Reference</a>.<br />
<h2>Creating Forms</h2>Form elements are now declared in array fashion, with the hierarchical structure of the form elements themselves as array elements (which can be nested), and each form elements properties/attributes listed as array elements in key/value pairs--the key being the name of the property/attribute, and the value being the value of the property/attribute. For example, here's how to go about constructing a textfield form element:<br />
<div class="codeblock"><code><span style="color: black;"> <span style="color: #0000bb;"> $form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'foo'</span><span style="color: #007700;">] = array(<br />
</span><span style="color: #dd0000;"> '#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'textfield'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'bar'</span><span style="color: #007700;">),<br />
</span><span style="color: #dd0000;">'#default_value' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">$object</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'foo'</span><span style="color: #007700;">],<br />
</span></span></code><code><span style="color: black;"><span style="color: #dd0000;">'#size' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">60</span><span style="color: #007700;">,<br />
</span></span></code><code><span style="color: black;"><span style="color: #dd0000;">'#maxlength' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">64</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#description' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'baz'</span><span style="color: #007700;">),<br />
</span></span></code><code><span style="color: black;"><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?></span> </span> </code></div>and a submit button:<br />
<div class="codeblock"><code><span style="color: black;"> <span style="color: #0000bb;"> $form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'submit'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;"><br />
'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'submit'</span><span style="color: #007700;">,<br />
</span></span></code><code><span style="color: black;"><span style="color: #dd0000;">'#value' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Save'</span><span style="color: #007700;">),<br />
</span></span></code><code><span style="color: black;"><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?></span> </span> </code></div>a few things to note:<br />
<ol><li>The element's <code>name</code> property is declared in the <code>$form</code> array, at the very end of the array tree. For example, if an element in the form tree was structured like this:<br />
<br />
<div class="codeblock"><code><span style="color: black;"> <span style="color: #0000bb;"> $form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'account_settings'</span><span style="color: #007700;">][</span><span style="color: #dd0000;">'username'</span><span style="color: #007700;">]<br />
</span><span style="color: #0000bb;">?></span> </span> </code></div><br />
...then that element's name property is 'username'--this is the key it will be available under in <code>$form_state['values']</code>, in your validation and submission functions, as the form code flattens the array in this fashion before it passes the key/value pairs. NOTE: if you wish to have the full tree structure passed to <code>$form_state['values']</code>, this is possible, and will be discussed later.</li>
<li>The type of form element is declared as an attribute with the <code>'#type'</code> property.</li>
<li>Properties/attributes keys are declared with surrounding quotes, beginning with a # sign. Values are strings.</li>
<li>The order of the properties/attributes doesn't matter, and any attributes that you don't need don't need to be declared. Many properties/attributes also have a default fallback value if not explicitly declared.</li>
<li>Don't use the <code>'#value'</code> attribute for any form elements that can be changed by the user. Use the <code>'#default_value'</code> attribute instead. Don't put values from <code>$form_state['values']</code> (or <code>$_POST</code>) here! FormsAPI will deal with that for you; only put the <b>original</b> value of the field here.</li>
</ol>One great advantages of this system is that the explicitly named keys make deciphering the form element much easier.<br />
Let's take a look at a working piece of code using the API:<br />
<div class="codeblock"><code><span style="color: black;"> <span style="color: #0000bb;"> </span><span style="color: #007700;">function </span><span style="color: #0000bb;">test_form</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$form_state</span><span style="color: #007700;">) {<br />
</span><span style="color: #ff8000;">// Access log settings:<br />
</span><span style="color: #0000bb;">$options </span><span style="color: #007700;">= array(</span><span style="color: #dd0000;">'1' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Enabled'</span><span style="color: #007700;">), </span><span style="color: #dd0000;">'0' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Disabled'</span><span style="color: #007700;">));<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'access'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;"><br />
'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'fieldset'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Access log settings'</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#tree' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">TRUE</span><span style="color: #007700;">,<br />
</span></span></code><code><span style="color: black;"><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'access'</span><span style="color: #007700;">][</span><span style="color: #dd0000;">'log'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;"><br />
'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'radios'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Log'</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#default_value' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">variable_get</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'log'</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#options' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">$options</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#description' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'The log.'</span><span style="color: #007700;">),<br />
);<br />
</span><span style="color: #0000bb;">$period </span><span style="color: #007700;">= </span><span style="color: #0000bb;">drupal_map_assoc</span><span style="color: #007700;">(array(</span><span style="color: #0000bb;">3600</span><span style="color: #007700;">, </span><span style="color: #0000bb;">10800</span><span style="color: #007700;">, </span><span style="color: #0000bb;">21600</span><span style="color: #007700;">, </span><span style="color: #0000bb;">32400</span><span style="color: #007700;">, </span><span style="color: #0000bb;">43200</span><span style="color: #007700;">, </span><span style="color: #0000bb;">86400</span><span style="color: #007700;">, </span><span style="color: #0000bb;">172800</span><span style="color: #007700;">, </span><span style="color: #0000bb;">259200</span><span style="color: #007700;">, </span><span style="color: #0000bb;">604800</span><span style="color: #007700;">, </span><span style="color: #0000bb;">1209600</span><span style="color: #007700;">, </span><span style="color: #0000bb;">2419200</span><span style="color: #007700;">, </span><span style="color: #0000bb;">4838400</span><span style="color: #007700;">, </span><span style="color: #0000bb;">9676800</span><span style="color: #007700;">), </span><span style="color: #dd0000;">'format_interval'</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'access'</span><span style="color: #007700;">][</span><span style="color: #dd0000;">'timer'</span><span style="color: #007700;">] = array(<br />
</span><span style="color: #dd0000;">'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'select'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Discard logs older than'</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#default_value' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">variable_get</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'timer'</span><span style="color: #007700;">, </span><span style="color: #0000bb;">259200</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#options' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">$period</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#description' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'The timer.'</span><span style="color: #007700;">),<br />
);<br />
</span><span style="color: #ff8000;">// Description<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'details'</span><span style="color: #007700;">] = array(<br />
</span><span style="color: #dd0000;">'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'fieldset'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Details'</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#collapsible' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">TRUE</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#collapsed' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">TRUE,<br />
</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'details'</span><span style="color: #007700;">][</span><span style="color: #dd0000;">'description'</span><span style="color: #007700;">] = array(<br />
</span><span style="color: #dd0000;">'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'textarea'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Describe it'</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#default_value' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">variable_get</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'description'</span><span style="color: #007700;">, </span><span style="color: #dd0000;">''</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#cols' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">60</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#rows' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">5</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#description' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Log description.'</span><span style="color: #007700;">),<br />
);<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'details'</span><span style="color: #007700;">][</span><span style="color: #dd0000;">'admin'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;"><br />
'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'checkbox'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Only admin can view'</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#default_value' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">variable_get</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'admin'</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0</span><span style="color: #007700;">),<br />
);<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'name'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;"><br />
'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'textfield'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Name'</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#size' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">30</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#maxlength' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">64</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#description' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Enter the name for this group of settings'</span><span style="color: #007700;">),<br />
);<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'hidden'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;">'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'value'</span><span style="color: #007700;">, </span><span style="color: #dd0000;">'#value' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'is_it_here'</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'submit'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;">'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'submit'</span><span style="color: #007700;">, </span><span style="color: #dd0000;">'#value' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Save'</span><span style="color: #007700;">));<br />
return </span><span style="color: #0000bb;">$form</span><span style="color: #007700;">;<br />
}<br />
<br />
<span style="color: #007700;">function </span><span style="color: #0000bb;">test_page</span><span style="color: #007700;">() {<br />
return </span><span style="color: #0000bb;">drupal_get_form</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'test_form'</span><span style="color: #007700;">)</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?></span> </span></span></code></div><span style="color: black;">This example demonstrates how form elements can be built in a hierarchical fashion by expanding and layering the form array. There are two functions involved - the function that builds the form, and another that renders the form using <code><a class="local" href="http://drupalcontrib.org/api/drupal/drupal--includes--form.inc/function/drupal_get_form/6" title="Retrieves a form from a constructor function, or from the cache if
the form was built in a previous page-load. The form is then passed
on for processing, after and rendered for display if necessary.">drupal_get_form</a>()</code>. Note that the form builder function always takes <code>$form_state</code> as its first argument, though for basic usage (as here) it is not used. Also note that the test_page() function that renders the form is returning the rendered HTML output, which is what you would need to do if test_page() is the page callback from a <a class="local" href="http://drupalcontrib.org/api/drupal/documentation--hooks--core.php/function/hook_menu/6" title="Define menu items and page callbacks.">hook_menu</a>() implementation, for example.</span><br />
<span style="color: black;">Notice that the first layer is made up of two form groups, 'access', and 'details', and that inside each of these groups, one layer down, are some individual form elements. Order of construction is important here, as the form building code will default to the constructed order of the <code>$form</code> array when it builds the form (this can be overridden, and will be discussed later in the custom theming section). </span><br />
<span style="color: black;">For form groups, the <code>'#type'</code> parameter is set to <code>'fieldset'</code>, and notice how the <code>'details'</code> form group is made into a collapsed form group with the addition of a few attributes.</span><br />
<span style="color: black;">All groups/elements are been built into the master <code>$form</code> array by the builder function.</span><br />
<span style="color: black;">The <code>drupal_get_form</code> function is the "key" function in the Forms API. Note that in its basic usage, it takes just one argument, a string which is both the form ID and also the name of the function that builds the <code>$form</code> array. Because the form ID is generally also the name of a function, it must be a valid PHP variable name. It should start with a letter or underscore, followed by any number of letters, numbers, or underscores; spaces and hyphens are not allowed. <code>drupal_get_form</code> can take optional additional arguments, which will be simply passed on to the <code>$form</code> builder function.</span><br />
<code><span style="color: black;">drupal_get_form</span></code><span style="color: black;"> does the following: </span><br />
<ul><span style="color: black;">
<li>Starts the entire form-building process by getting the <code>$form</code> from the builder function</li>
<li>Translates the <code>$form['name']</code> items into actual form elements</li>
<li>Performs any validation and "clean-up" that needs to be done, and calls custom validation functions if declared</li>
<li>Submits the form if a submit function is declared, and the form has been submitted</li>
<li>Calls any custom theming functions that have been declared</li>
<li>Returns an HTML string which contains the actual form.</li>
</span></ul><span style="color: black;">For more detailed information, also see the API page for <code><a class="local" href="http://drupalcontrib.org/api/drupal/drupal--includes--form.inc/function/drupal_get_form/6" title="Retrieves a form from a constructor function, or from the cache if
the form was built in a previous page-load. The form is then passed
on for processing, after and rendered for display if necessary.">drupal_get_form</a>()</code></span><br />
<span style="color: black;"><i>An important thing to note:</i> notice that <code>$form['access']</code> has a <code>'#tree' => TRUE</code> attribute. this setting retains the full tree structure for all elements under it when it is passed to <code>$form_state['values']</code>. you must explicitly declare this anywhere you wish to retain an array's full hierarchy when it is passed.</span><br />
<h2><span style="color: black;">Theming Forms</span></h2><span style="color: black;">The API makes custom theming of all forms (including those found in core) possible. This custom theming becomes possible when all hard coded theming elements have been abstracted, so that they can be overridden at time of form generation. The abstraction is accomplished using one of the following methods:</span><br />
<ol><span style="color: black;">
<li>Adding <code>'#theme'</code> attributes to the form and/or elements. This allows you to specify which theme function will be used to render the form or elements, overriding the default theming function.</li>
<li>Including any markup directly as an element in the $form array: <ul><li>There are <code>'#prefix'</code> and <code>'#suffix'</code> attributes, and these will place the declared markup either before or after the form element in question. for example: <div class="codeblock"><code><span style="color: black;"> <span style="color: #0000bb;"> $form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'access'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;"><br />
'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'fieldset'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#title' </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Access log settings'</span><span style="color: #007700;">), </span><span style="color: #dd0000;"><br />
'#prefix' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'</span><div class="foo"><span style="color: #dd0000;">'</span><span style="color: #007700;">, </span><span style="color: #dd0000;"><br />
'#suffix' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'</span></div><span style="color: #dd0000;">',<br />
</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?></span> </span> </code></div>...will place the div tags before and after the entire form group (meaning the form elements of the group will also be enclosed in the div). if you were to put those attributes in one of the form elements inside that form group, then they would only wrap that particular element, etc.<br />
</li>
<li>There is a <code>'#markup'</code> type which you can place anywhere in the form, and its value will be output directly in its specified location in the forms hierarchy when the form is rendered. example:<br />
<br />
<div class="codeblock"><code><span style="color: black;"> <span style="color: #0000bb;"> $form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'div_tag'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;">'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'markup'</span><span style="color: #007700;">, </span><span style="color: #dd0000;">'#value' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'</span></span></code><br />
<div class="foo"><span style="color: black;"><span style="color: #dd0000;">'</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?></span> </span> </div>This markup form element can then be accessed/altered through its name in the array, 'div_tag'<br />
<i>NOTE:</i> it's not necessary to explicitly declare the type as markup, since type will default to markup if none is declared.</div></li>
</ul></li>
<li>Break out any markup into a separate theme function. This is the preferred method if the markup has any degree of complication. it is accomplished by creating a theme function with <i>theme_</i> prepended to the name of the form ID that is to be themed. in cases where you want to use the same theming function for more than one form, you can include the optional callback arg in <code>drupal_get_form</code>--in which case the third arg of <code>drupal_get_form</code> will be a string containing the name of the callback function which the form building code will call, and the theming function will be <i>theme_</i> prepended to the name of the callback. example:<br />
For our above form, we could create a custom theming function as follows:<br />
<div class="codeblock"><code><span style="color: black;"> <span style="color: #0000bb;"> </span><span style="color: #007700;">function </span><span style="color: #0000bb;">theme_test_form</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">) {<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">= </span><span style="color: #dd0000;">''</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">.= </span><span style="color: #0000bb;">drupal_render</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'name'</span><span style="color: #007700;">]);<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">.= </span><span style="color: #dd0000;">'</span><div class="foo"><span style="color: #dd0000;">'</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">.= </span><span style="color: #0000bb;">drupal_render</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'access'</span><span style="color: #007700;">]);<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">.= </span><span style="color: #dd0000;">'</span><br />
<div class="bar"><span style="color: #dd0000;">'</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">.= </span><span style="color: #0000bb;">drupal_render</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'details'</span><span style="color: #007700;">]);<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">.= </span><span style="color: #dd0000;">'</span></div></div><span style="color: #dd0000;">'</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">.= </span><span style="color: #0000bb;">drupal_render</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">);<br />
return </span><span style="color: #0000bb;">$output</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?></span> </span> </code></div>A few things to note:<br />
<ol><li>The theme function has one argument, which is the form array that it will theme</li>
<li>You build and return an output string just as you would do in a regular theming function</li>
<li>Form elements are rendered using the <code>drupal_render</code> function</li>
<li>If you call <code>drupal_render</code> and pass it an array of elements (as in a fieldset), it will render all the elements in the passed array, in the order in which they were built in the form array.</li>
<li>While the default order of rendering for a form is the order in which it was built, you can override that in the theme function by calling <code>drupal_render</code> for any element in the place where you would like it to be rendered. In the above example, this was done with <code>$form['name']</code>.</li>
<li>The rendering code keeps track of which elements have been rendered, and will only allow them to be rendered once. Notice that <code>drupal_render</code> is called for the entire form array at the very end of the theming function, but it will only render the remaining unrendered element, which in this case is the submit button. calling <code><a class="local" href="http://drupalcontrib.org/api/drupal/drupal--includes--common.inc/function/drupal_render/6" title="Renders HTML given a structured array tree.">drupal_render</a>($form)</code> is a common way to end a theming function, as it will then render any submit buttons and/or hidden fields that have been declared in the form in a single call.</li>
</ol></li>
</span></ol><h2><span style="color: black;">Validating Forms</span></h2><span style="color: black;">The form API has general form validation which it performs on all submitted forms. If there is additional validation you wish to perform on a submitted form, you can create a validation function. the name of the validation function is the form ID with <i>_validate</i> appended to it. the function has two args: <code>$form</code> and <code>$form_state</code>. <code>$form</code> is the form array of the executed form, and <code>$form_state['values']</code> contains the form values which you may perform validation on. (Note - in more advanced usage, several forms may share a _validate or _submit function - so if the form's ID is needed, it can be retrieved from <code>$form['form_id']['#value']</code>, or <code>$form_state['values']['form_id']</code>.)</span><br />
<span style="color: black;">Here's an example validation function for our example code:</span><br />
<div class="codeblock"><code><span style="color: black;"><span style="color: black;"> <span style="color: #0000bb;"> </span><span style="color: #007700;">function </span><span style="color: #0000bb;">test_form_validate</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">, </span><span style="color: #0000bb;">&$form_state</span><span style="color: #007700;">) {<br />
if (</span><span style="color: #0000bb;">$form_state['values']</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'name'</span><span style="color: #007700;">] == </span><span style="color: #dd0000;">''</span><span style="color: #007700;">) {<br />
</span><span style="color: #0000bb;">form_set_error</span><span style="color: #007700;">(</span><span style="color: #dd0000;">''</span><span style="color: #007700;">, </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'You must select a name for this group of settings.'</span><span style="color: #007700;">));<br />
}<br />
}<br />
</span><span style="color: #0000bb;">?></span> </span> </span></code></div><h2><span style="color: black;">Submitting Forms</span></h2><span style="color: black;">The normal method of submitting forms with the API is through the use of a form submit function. This has the same naming convention and arguments as the validation function, except <i>_submit</i> is appended instead. Any forms which are submitted from a button of <code>type => 'submit'</code> will be passed to their corresponding submit function if it is available. </span><br />
<span style="color: black;">example:</span><br />
<div class="codeblock"><code><span style="color: black;"><span style="color: black;"> <span style="color: #0000bb;"> </span><span style="color: #007700;">function </span><span style="color: #0000bb;">test_form_submit</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$form</span><span style="color: #007700;">, </span><span style="color: #0000bb;">&$form_state</span><span style="color: #007700;">) {<br />
</span><span style="color: #0000bb;">db_query</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"INSERT INTO {table} (name, log, hidden) VALUES ('%s', %d, '%s')"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$form_state['values']</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'name'</span><span style="color: #007700;">], </span><span style="color: #0000bb;">$form_state['values']</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'access'</span><span style="color: #007700;">][</span><span style="color: #dd0000;">'log'</span><span style="color: #007700;">], </span><span style="color: #0000bb;">$form_state['values']</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'hidden'</span><span style="color: #007700;">]);<br />
</span><span style="color: #0000bb;">drupal_set_message</span><span style="color: #007700;">(</span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Your form has been saved.'</span><span style="color: #007700;">));<br />
}</span><span style="color: #0000bb;">?></span> </span> </span></code></div><span style="color: black;">a few things to note: </span><br />
<ol><span style="color: black;">
<li>A submit function is called only if a submit button was present and exists in the $_POST, and validation did not fail. </li>
<li>The <code>$form_state['values']</code> array will not usually have the same hierarchical structure as the constructed <code>$form</code> array (due to the flattening discussed previously), so be aware of what arrays have been flattened, and what arrays have retained their hierarchy by use of the <code>tree => TRUE</code> attribute. notice above that 'statistics_enable_access_log' belongs to a tree'd array, and the full array structure must be used to access the value.</li>
<li>If a form has a submit function, then hidden form values are not needed. Instead, any values that you need to pass to <code>$form_state['values']</code> can be declared in the <code>$form</code> array as such:<br />
<br />
<div class="codeblock"><code><span style="color: black;"> <span style="color: #0000bb;"> $form</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'foo'</span><span style="color: #007700;">] = array(</span><span style="color: #dd0000;">'#type' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'value'</span><span style="color: #007700;">, </span><span style="color: #dd0000;">'#value' </span><span style="color: #007700;">=> </span><span style="color: #dd0000;">'bar'</span><span style="color: #007700;">)<br />
</span><span style="color: #0000bb;">?></span> </span> </code></div>This is accessed in <code>$form_state['values']['foo']</code>, with a value of <i>bar</i>. This method is preferred because the values are not sent to the browser.<br />
</li>
<li>To determine where the user should be sent after the form is processed, the _submit function can place a path or URL in <code>$form_state['redirect']</code> which will be the target of a drupal_goto; every form is redirected after a submit. If you store nothing in <code>$form_state['redirect']</code>, the form will simply be redirected to itself after a submit. It is polite to use <code><span style="color: #0000bb;"><a class="local" href="http://drupalcontrib.org/api/drupal/contributions--coder--scripts--coder_format--coder_format.php/function/drupal_set_message/6" title="">drupal_set_message</a>()</span></code> to explain to the user that the submission was successful. </li>
</span></ol><h2><span style="color: black;">Understanding the Flow</span></h2><span style="color: black;">An important concept with Forms API compared to using raw HTML forms (as in Drupal 4.6 and before) is that the <code><span style="color: #0000bb;"><a class="local" href="http://drupalcontrib.org/api/drupal/drupal--includes--form.inc/function/drupal_get_form/6" title="Retrieves a form from a constructor function, or from the cache if
the form was built in a previous page-load. The form is then passed
on for processing, after and rendered for display if necessary.">drupal_get_form</a>()</span></code> function handles both presenting and responding to the form. What this means is that the $form array you construct in your function will be built first when the form is presented, and again when the form is submitted.</span><br />
<span style="color: black;">The practical upshot to this is that many developers immediately find themselves asking the question of <i>"where does my data get stored?"</i>. The answer is simply that it doesn't. You put your $form data together, perhaps loading your object from the database and filling in #default_values, the form builder then checks this against what was posted. What you gain from this, however, is that the FormsAPI can deal with your data securely. Faking a POST is much harder since it won't let values that weren't actually on the form come through to the $form_state['values'] in your submit function, and in your 'select' types, it will check to ensure that the value actually existed in the select and reject the form if it was not. In addition, Drupal adds, by default, a security token to each form that will protect against cross-site forgery. </span></div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com18tag:blogger.com,1999:blog-1817729882430277165.post-41477130686887434192011-04-19T18:04:00.000-07:002011-04-19T18:04:00.090-07:00How to install ubercart in Drupal<div dir="ltr" style="text-align: left;" trbidi="on"><span class="submitted"></span><br />
<h2>Modules Needed for Ubercart Tutorial Part 1</h2>You'll need to download the following modules to set up your Ubercart store. We're using Drupal 6 and Ubercart 2.<br />
<ul><li><a href="http://drupal.org/project/cck">Content Creation Kit(CCK)</a></li>
<li><a href="http://drupal.org/project/filefield">FileField</a></li>
<li><a href="http://drupal.org/project/imagefield">ImageField</a></li>
<li><a href="http://drupal.org/project/imageapi">ImageAPI</a></li>
<li><a href="http://drupal.org/project/imagecache">ImageCache</a></li>
<li><a href="http://drupal.org/project/token">Token</a></li>
<li><a href="http://drupal.org/project/ubercart">Ubercart</a></li>
</ul><iframe class="youtube-player" frameborder="0" height="390" src="http://www.youtube.com/embed/wkIQ65QuITE" title="YouTube video player" type="text/html" width="480"></iframe><br />
<h3>Ubercart Modules Needed</h3>So first we need to install Ubercart. Here's a clean installation of Drupal, and we're going to go online and find the Ubercart module. We're using Drupal 6 and Ubercart 2. So google Ubercart and look for the module and download the version for Drupal version 6.<br />
<br />
You'll want to download all of them there's links to them, and then just go into your drupal installation folder. Go to /sites/all/. You're going to want to make a directory called modules in there, and then unzip or untar all of your module files here such as Ubercart, FileField, all of them there.<br />
<br />
So be sure to check the description of the YouTube video for links to my blog, and the post that has all the modules you need to download and unzip in that folder.<br />
<br />
So you go to Admin > Modules and we'll enable all the modules we need. First we need to enable the Content module, enable the FileField module, ImageField, as well as Path. We also need ImageAPI, ImageAPI GD2, ImageCache, this will give us support for images for products. We need Token, Cart, Conditional Actions, Order, Product, Store, Catalog, and that's it!<br />
<br />
So we save our configuration, and after we've enabled all the modules we need, it's time to start configuring the store.<br />
<h3>Ubercart Store Configuration</h3>On the menu click on store administration and then configuration and then choose store settings. So this is all the information about your store. If you pick edit, you can pick your store name, Ubercart Demo Store. Store owner, put in your name, and put in your email address below, your store phone number, your store fax number, and then the address of your store here. Pick your country and province, or territory, or state and then your postal code. <br />
You can put in a help page if you want, you'll have to configure that later though.<br />
<h3>Enable image support in Ubercart</h3>At the next screen after Save Configuration, scroll to the bottom and click on "click here" to enable image support. Now images are enabled for our products and our catalogs.<br />
<h3>Creating products in Ubercart</h3>If you click on Create Content in the menu, and click on product, we'll create our first product here. So I'm going to create a fish hat. I don't know why but I saw a cool fish hat on reddit and I've been a bit obsessed with it ever since. I want one, I want my girlfriend to make me one.<br />
<br />
Now we're going to find an appropriate photo for this fish hat. I wouldn't recommend google ganking like this on a production web site, but this is just for fun. So browse and find the image. Make sure it fits the file format standards. <br />
You can add some text here that will show up in the alternate. You need to enter an SKU. It can be anything but Drupal requires that you do. Also add a sell price, that's the cost that customers will be charged. You want to put in a weight, and you also want to put in the dimensions of the product in whatever unit measurement you want or else you won't be able to ship the product and get shipping quotes later on.<br />
<br />
Now we'll have to go into Administer > User Management > User Permissions. For the anonymous and authenticated user enable the following permissions:<br />
<ul><li>View ImageCache Cart</li>
<li>View ImageCache product</li>
<li>View ImageCache product_full</li>
<li>View ImageCache product_list</li>
<li>View ImageCache uc_thumbnail</li>
</ul>So save your configuration and if you go to the home page you'll notice that the fish hat is now a product that's showing in the front page. You can go to your cart and play around with the shopping cart that's provided with Drupal, and ya it' looks pretty cool.That's how you create a product. <br />
<h3>Creating an Ubercart Catalog</h3>We are going to go to store administration, and you'll notice we have an unlisted product. We have created a catalog for it yet, so we need to add terms for the product to inhabit.<br />
<br />
We'll do that by creating a catalog by clicking the link below, add terms for this product to inhabit.<br />
<br />
Now I'm trying to find a suitable image for this. We'll add a silly hats catalog for the fish hat to inhabit. Add an image and a description and then click save. You've just created a catalog.<br />
<br />
So now if you go back to store administration, and click on the orphaned products link at the bottom. Find the orphaned product which is the fish hat and if you go to catalog, just add it to the fish hats catalog and click save.<br />
You'll see there are no more orphaned products which is great. Now we go to our catalog and our fish hat is in the silly hats catalog which is very nice. <br />
<h3>Creating a menu link to the Ubercart catalog</h3>So now click on administer then menus and then primary links. We're going to create a link to the catalog here. You want to put the menu link title silly hats catalog down below, and in the top you put the path to the catalog which is /taxonomy/term/1.<br />
<br />
Create a description, click enabled, and then click save.<br />
<br />
So now the silly hats catalog will show up in the primary links menu, but now we have to go to Administer > Blocks. Go to the very bottom and find Primary Links Menu and set that to the right sidebar and click save. Now you'll see the Primary links in the right side that now has our catalog on the right.<br />
<h3>Creating more Ubercart products for our catalog</h3>Now lets create another product for our catalog. Lets call it beer hat. Everyone loves beer hats, if you've been in college anyways. Add a description, add the catalog silly hats. Lets find a beer hat picture real quick off google. I wouldn't recommend this, this is for demonstration purposes only. Lets rename the file here real quick. There we go we can upload the file now. <br />
Add a title here called beer hat. Change the weight, add a length, width and height, I don't really know what it is I'm just guessing here. Oops we forget to add the SKU, add the pesky SKU, just add beer-0001, it can be anything. Now click save and you've got a beer hat in the catalog here.<br />
So now you can see we have a beer hat and a fish hat in our catalog. You can add each of them to your cart and play around with it. You can checkout and pay for it, but we haven't set up payment yet, and that will be the next step.<br />
<h3>Wrapping up and Ubercart Tutorials parts 2 and 3</h3>This is going to be part of a 3 part Ubercart tutorial. The first one shows you how to do basic setup for your store. The second shows you how to setup payment with Paypal. The third one will show you how to get shipping quotes working properly with UPS or FedEx I haven't quite decided yet.<br />
<br />
<br />
<br />
<br />
</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com6tag:blogger.com,1999:blog-1817729882430277165.post-60492733670553489022011-04-18T19:15:00.000-07:002011-04-18T19:15:00.301-07:0015 Outstanding Drupal Modules You Should Be Using<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on">Drupal is a (CMS) any web developer should get to know. It is in my opinion the best open source CMS available at the moment, and it has a huge community of contributors. If you have not looked into drupal check it out at <a href="http://www.drupal.org/">drupal.org</a>.<br />
<span id="more-1470"></span><br />
Just like WordPress, Drupal is powerful “out of the box” but has thousands of modules that have been contributed to the community to extend upon that functionality. A few of the most popular modules are <a href="http://drupal.org/project/views">Views</a>, <a href="http://drupal.org/project/cck">CCK</a>, <a href="http://drupal.org/project/panels">Panels</a>, <a href="http://drupal.org/project/xmlsitemap">XML Site map</a> and <a href="http://drupal.org/project/google_analytics">Google Analytics</a>.<br />
<br />
</div><br />
<br />
<h2 style="border-bottom: 0px none;">1.<a href="http://drupal.org/project/stringoverrides" target="_blank"> String Overrides</a></h2><a href="http://www.threestyles.com/wp-content/uploads/2010/04/stringoverrides1.png" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1479" height="285" src="http://www.threestyles.com/wp-content/uploads/2010/04/stringoverrides1.png" title="stringoverrides1" width="540" /></a><br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/stringoverrides2.png" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1480" height="342" src="http://www.threestyles.com/wp-content/uploads/2010/04/stringoverrides2.png" title="stringoverrides2" width="540" /></a><br />
The String Overrides module allows you to override text on a drupal site such as the default text on a contact form page. Some text that Drupal auto generates is difficult to change, but using String overrides allows you to change those text strings with a fairly easy user interface.<br />
<h2 style="border-bottom: 0px none;">2. <a href="http://drupal.org/project/date" target="_blank"> Date Module</a></h2>The Date Module is very powerful because it can tie so many modules together using something simple such as the date. It allows you to assign a date to an event or a custom content type and distribute that value to other modules.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/date-module.jpg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1493" height="391" src="http://www.threestyles.com/wp-content/uploads/2010/04/date-module.jpg" title="Date Module" width="540" /></a><br />
<blockquote>The date module is a flexible date/time field type for the cck content module which requires the CCK content.module and the Date API module.</blockquote>This module does need CCK in order to work but most if not all drupalheads use CCK so thats not a big issue.<br />
<h2 style="border-bottom: 0px none;">3.<a href="http://drupal.org/project/calendar" target="_blank"> Calendar Module</a></h2>The Calendar Module is intentionally listed after the Date Module because they work so flawlessly together. It pulls in dates of events or custom content types and generates them all in a calendar that is ready to be styled with CSS.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/calendar.jpg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1495" height="318" src="http://www.threestyles.com/wp-content/uploads/2010/04/calendar.jpg" title="Calendar Drupal Module" width="540" /></a><br />
<blockquote>This module will display any Views date field in calendar formats, including CCK date fields, node created or updated dates, etc. Switch between year, month, and day views. Back and next navigation is provided for all views.</blockquote>I have used this calendar module on multiple sites and it really makes it easy to get a clean looking dynamic calendar up fairly quickly. I highly recommend.<br />
<h2 style="border-bottom: 0px none;">4. <a href="http://drupal.org/project/location" target="_blank"> Location Module</a></h2>The Location Module is similar to the Date Module in the sense that is is adding specificity to a piece of content. As you probably guessed by it’s name it allows you to add a location to individual nodes.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/city.jpg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1500" height="330" src="http://www.threestyles.com/wp-content/uploads/2010/04/city.jpg" title="Location Module" width="540" /></a><br />
<blockquote>The Location module allows real-world geographic locations to be associated with Drupal nodes, including people, places, and other content.</blockquote>The actual functionality of adding a location to a node or person isn’t all that exciting, It’s what you can do with paired modules that truly brings this module to life.<br />
<h2 style="border-bottom: 0px none;">5.<a href="http://drupal.org/project/gmap" target="_blank"> GMAP Module</a></h2>I was just talking about how other modules bring the Location Module to life. Enter the GMAP Module. This takes the location module and gets all kinds of crazy with it, allowing you to now map all or some of your locations or people. You could build a medium sized social network site just based off of Drupal.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/google.jpeg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1503" height="308" src="http://www.threestyles.com/wp-content/uploads/2010/04/google.jpeg" title="GMAP Module" width="540" /></a><br />
<blockquote>The GMap module provides an interface to the Google Maps API within Drupal. It integrates with the Location module to provide users a clickable map for entering latitude and longitude, as well as to display maps of Drupal nodes and users.</blockquote>The possibilities are endless and these modules are only in the beginning stages. I can’t wait to see what Drupal 7 holds.<br />
<h2 style="border-bottom: 0px none;">6. <a href="http://drupal.org/project/ubercart" target="_blank"> UBERCART Module</a></h2>Ubercart in my opinion is the best e-commerce solution to-date for Drupal. It is a seamless integration that leverages the strengths of Drupals backend to deliver a great shopping experience.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/shopping.jpeg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1505" height="352" src="http://www.threestyles.com/wp-content/uploads/2010/04/shopping.jpeg" title="Ubercart Module" width="540" /></a><br />
<blockquote>Ubercart is an e-commerce suite developed for Drupal. It has been designed with the end user in mind, focusing on usability in three key areas: store configuration, product and catalog creation, and order administration.</blockquote>Not only does Ubercart easily integrate with drupal it has built-in modules for shipping calculation, payments, taxes, and much more.<br />
<h2 style="border-bottom: 0px none;">7. <a href="http://drupal.org/project/signup" target="_blank"> Signup Module</a></h2>The Signup allows a user of the site to “Sign Up” for specific events/nodes and it will email them the day before the event happens just to serve as a reminder. It is a wonderful tool to use if you can get your audience to use it.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/signup.jpeg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1507" height="278" src="http://www.threestyles.com/wp-content/uploads/2010/04/signup.jpeg" title="Sign Up Module" width="540" /></a><br />
<blockquote>Signup allows users to sign up (or register, as in register for a class) for nodes of any type. Includes options for sending a notification email to a selected email address upon a new user signup (good for notifying event coordinators, etc.) and a confirmation email to users who sign up.</blockquote>I used this on a site I just finished developing, and it hasn’t caught on with in the community yet. I guess we’ll see with time, either way I still like it :p<br />
<h2 style="border-bottom: 0px none;">8. <a href="http://drupal.org/project/content_access" target="_blank"> Content Access Module</a></h2>I use this module to set permissions to different roles per node, so if I have one page I only want important people to see I can go in and set permissions for that specific node. This module is very powerful.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/walkie.jpeg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1509" height="358" src="http://www.threestyles.com/wp-content/uploads/2010/04/walkie.jpeg" title="Content Access Module" width="540" /></a><br />
<blockquote>This module allows you to manage permissions for content types by role and author. It allows you to specifiy custom view, edit and delete permissions for each content type. Optionally you can enable per content access settings, so you can customize the access for each content node.</blockquote>Drupal gives you so much control over the permissions of your site, but the Content Access Module is an awesome add-on to increase Drupals functionality.<br />
<br />
<br />
<h2 style="border-bottom: 0px none;">9. <a href="http://drupal.org/project/webform" target="_blank"> Webform Module</a></h2>The Webform Module adds a webform as a nodetype which allows you to offer register forms, surveys, polls and much more. It’s also a good alternative to Drupal’s site-wide contact form.<br />
<br />
I mainly use the Webform Module in place of Drupal’s site-wide contact form. It gives you more flexibility and it’s easier to style.<br />
<h2 style="border-bottom: 0px none;">10. <a href="http://drupal.org/project/nodewords" target="_blank">Nodewords Module</a></h2>Nodewords is great for SEO because it allows you to set meta tags for each drupal page or node. This gives you awesome control over what keywords and descriptions are used on each page of your site, and if used correctly can really help your rankings.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/books.jpeg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1513" height="277" src="http://www.threestyles.com/wp-content/uploads/2010/04/books.jpeg" title="Nodewords Module" width="540" /></a><br />
<blockquote>This project allows you to set some meta tags for each Drupal page.</blockquote>I user the Nodewords Modules for the reasons stated above. It helps out with SEO and keeps google’s attention by constantly updating content with new keywords.<br />
<h2 style="border-bottom: 0px none;">11.<a href="http://drupal.org/project/nice_menus" target="_blank"> Nice Menus Module</a></h2>Nice Menus enables drop down menus for your navigation items in drupal. It uses completely CSS and even has a small bit of Javascript for IE6.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/nicemenu.jpg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1517" height="283" src="http://www.threestyles.com/wp-content/uploads/2010/04/nicemenu.jpg" title="nicemenu" width="540" /></a><br />
<blockquote>Nice Menus enables drop-down/right/left expandable menus. It uses only CSS for most browsers, with minimal Javascript for IE6. (Version 2 uses the Superfish jQuery plugin for all browsers, with an option to disable JS, and falls back to CSS-only for browsers that can handle it.)</blockquote>It’s a quick easy way to get a drop down menu going and can easily be changed to drop to the left, right or down.<br />
<h2 style="border-bottom: 0px none;">12.<a href="http://drupal.org/project/mollom" target="_blank"> Mollom</a></h2>Mollom is a great spam catcher for contact forms, web forms, comments, blogs, messages and more and was developed by Dries Buytaert the creator of Drupal.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/mollom.jpg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1518" height="267" src="http://www.threestyles.com/wp-content/uploads/2010/04/mollom.jpg" title="Mollom" width="540" /></a><br />
<blockquote>Mollom is a web service that analyzes the quality of content posted to websites. This includes comments, contact-form messages, blogs, forum posts, etc. Mollom specifically tries to determine whether this content is unwanted – i.e. “spam” – or desirable – i.e. “ham.”</blockquote>It significantly cuts down on the amount of spam you get on your Drupal site. It will provide CAPTCHA’s for you to further reduce spam.<br />
<h2 style="border-bottom: 0px none;">13. <a href="http://drupal.org/project/scheduler" target="_blank"> Scheduler Module</a></h2>The Scheduler Module allows you to create a piece of content and choose a day for it to become public, instead of having to go back in yourself and set it to public on the day it needs to go live.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/planner.jpg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1520" height="451" src="http://www.threestyles.com/wp-content/uploads/2010/04/planner.jpg" title="planner" width="540" /></a><br />
<blockquote>This module allows nodes to be published and unpublished on specified dates.</blockquote>I’m am horrible at remembering things people tell me unless I write it down. So the ability to go in and create the content and then schedule it for the day I actually want it to go live is an awesome feature.<br />
<h2 style="border-bottom: 0px none;">14.<a href="http://drupal.org/project/menu_block" target="_blank"> Menu Block Module</a></h2>Menu Block simply enables a block for each of the menus you have so you can place them in a block somewhere else on the site.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/menu-block.jpg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1521" height="266" src="http://www.threestyles.com/wp-content/uploads/2010/04/menu-block.jpg" title="menu-block" width="540" /></a><br />
<blockquote> It provides configurable blocks of menu trees starting with any level of any menu.</blockquote>I use this module on almost every site I do. Mainly because I can grab my secondary navigation and throw it in the sidebar, it really gives you a lot of flexibility.<br />
<h2 style="border-bottom: 0px none;">15. <a href="http://drupal.org/project/admin" target="_blank"> Admin Module</a></h2>This Admin module has some serious promise. They have integrated a very nice administrative theme that makes it super easy to update content within a great looking admin theme.<br />
<a href="http://www.threestyles.com/wp-content/uploads/2010/04/admin.jpg" rel="wp-prettyPhoto[g1470]"><img alt="" class="alignnone size-full wp-image-1522" height="319" src="http://www.threestyles.com/wp-content/uploads/2010/04/admin.jpg" title="admin" width="540" /></a><br />
<blockquote>The admin module provides UI improvements to the standard Drupal admin interface.</blockquote>I am not currently using this on any sites, but I am looking forward to what this module could become.<br />
</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com27tag:blogger.com,1999:blog-1817729882430277165.post-80076513755799330072011-04-17T19:15:00.000-07:002011-04-17T19:15:00.495-07:00Content Translation (field translation) in Drupal 7Drupal has long been a leader in the ability to present a website in multiple languages. In Drupal 7 we continue that tradition: Field translation or "content translation" made it into Drupal 7, but it's not obvious from a plain Drupal 7 install how you would use it.<br />
<br />
This article is fundamentally about content translation, not about interface translation, which is a completely different thing in Drupal (and always has been). Interface translation is about prompts, labels, menu entries and the like, all of which are handled by the core locale module and various contrib modules like i18n. I will explain how to import basic interface translation files, however.<br />
<br />
Drupal 6 has a node translation system which basically allows you to make "translation sets" of nodes. You start with a node in a source language (and set the language on that node), and then you can create additional translations of that node to other languages. So for example, we might start with a node in English, then use the "translate" tab to add additional nodes in different languages that are tied to that original node. That node translation system is still supported in Drupal 7, but it doesn't support translation of CCK fields, and is quite awkward in reality because you're dealing with a number of separate nodes, instead of translations of a single node. Edit: See Gabor's comment below for more on this, and considerations regarding it.<br />
<br />
Drupal 7 got field translation (yay!), also referred to as "content translation", which is an entirely different thing. In content translation you have a single node, but with different translations for each field on the node that should be translatable. And the body is a field. Unfortunately the title is not a field, and therefore is not translatable, but more on that later. To restate this: In Drupal 7 "content translation" there is just one node, and translatable fields on it are translated to provide the translations, but are still part of that single node. The gotcha in field translation (content translation) though is that in core it didn't get a user interface. As a result the contrib Entity Translation module improves content translation and provides a UI and works alongside the core content translation module, and it's fundamental to the approach described here.<br />
<br />
Here is the process I went through to set up a basic multilingual site:<br />
<br />
1. The core field translation facilities have no user interface, so you'll need the Entity Translation module. After installing and enabling it (which also enables translation and locale modules), you may need to run update.php.<br />
2. You need to enable languages for your site.<br />
* Add languages at admin/config/regional/language<br />
* Download interface translation files from http://localize.drupal.org<br />
* Import interface translations into the configured languages at admin/config/regional/translate/import (under "Translate Interface"<br />
* Click "Enabled" on the languages you've configured<br />
* At "Detection and Selection" (admin/config/regional/language/configure), choose how you want languages to be chosen. My experience is that URL selection is the best approach, so you'll need to configure subdomains or some related approach. Note that when you use URLs you need to enter the full URL including "http://". There doesn't seem to be any error checking on this. Also remember to click "enabled" on the strategy that you choose.<br />
* On the same "Detection and Selection" page, in the lower section of the page under "Content language detection" select "Interface", so that the same language is chosen for content language detection as for interface language detection.<br />
3. Enable translation of nodes and any other entities that should be translatable at admin/config/regional/translation.<br />
4. Enable "Multilingual support: Enabled, with content translation" on the content type edit form under "Publishing options". For example, for a content type named "example", this would be at admin/structure/types/manage/example/edit in the "publishing options" fieldset.<br />
5. For each field that should be translatable, go to field settings and check "users may translate this field". For the body field of the "example" content type, this would be at admin/structure/types/manage/example/fields/body/field-settings.<br />
6. Now you can create and translate fields.<br />
* Create a node and set its language to a specific language.<br />
* When you've saved it a "Translate" tab will appear allowing you to translate into other configured languages.<br />
* Click "Add translation" to add translations for the fields that have translation enabled.<br />
* Make sure to publish the translation. Publication is unfortunately hidden in the collapsed-by-default "translation options" fieldset<br />
<br />
Some gotchas regarding field translation:<br />
<br />
* The Title module is required to make titles translatable. This currently only works for nodes, not entities. All the work is actually being done in #924968 so you have to apply the patch from that issue.<br />
* Entities other than nodes are not translatable out of the box. The entity must be specifically enabled to allow its fields to be translated. das-peter will elaborate on this later.<br />
<br />
Since I'm a newbie at the D7 translation scene, I'm sure there are errors or omissions here, so please correct this and I'll update the article based on your corrections.Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com15tag:blogger.com,1999:blog-1817729882430277165.post-71131693728387677562011-04-16T18:04:00.000-07:002011-04-16T18:04:00.820-07:00Building Drupal with Reusable Fields<div dir="ltr" style="text-align: left;" trbidi="on"><div class="entry-content"><h2>CCK and Field API</h2><a href="http://drupal.org/project/cck">CCK</a> is the most useful module for Drupal. It adds custom fields and content types to Drupal. Drupal 7 incorporates the community efforts of CCK into the core as the <a href="http://api.drupal.org/api/group/field/7">Field API</a>.<br />
<br />
The CCK module allows a content type to have multiple fields with various field types and different field widgets and formatters. A field must be assigned a widget to define its input style and at least one formatter to define its display style. The UML diagram above describes the relationship between content types, fields, field widgets, and field formatters in creating a CCK type.<br />
<h2>Reuse Fields</h2>When a CCK field is added to a content type for the <b>first</b> time, this CCK field’s is created in Drupal as a <i>class</i> and an <i>instance</i> is assigned to the given content type. When the field is assigned to a content type, its configuration parameters are stored in the <i>instance</i> instead of the <i>class</i>. Instead of adding new fields to a content type, adding existing fields is a better option to reduce the system’s complexity and to improve scalability.<br />
<br />
Adding an existing field only requires the administrator to choose a field from a list of fields defined in other content types and select a widget to define the input style. The most recently created field instance brings in the default parameters that can be changed later.<br />
<h2>Reuse Fields with the API</h2>CCK allows adding customized fields, widgets, and formatters in modules. Many third-party modules (<a href="http://drupal.org/project/modules?filters=tid%3A57&solrsort=sis_project_release_usage%20desc">Drupal CCK modules list</a>) are already created to accomplish different tasks, including images, videos, and other internal and external references. CCK for Drupal 6 provides a set of API (<a href="http://drupal.org/node/101742">CCK Developer Documentation for Drupal 6</a>) for module developers. Drupal 7 provides native <a href="http://api.drupal.org/api/group/field/7">Field API</a> for module developers.<br />
<h2>Performance Issues</h2>CCK (or Field API in Drupal 7) adds extra complexity to a Drupal system. When creating a new field, the field’s definition is added to the field <i>class</i> table and the field’s configuration is added to the field <i>instance</i> table; meanwhile, a new <b>table</b> is added to the Drupal database to store the field data. Database tables add complexity to the system. In addition, queries of nodes will incur <b>JOIN</b> expressions of tables to field data. Multiple <b>JOIN</b>s will impact database performance since MySQL responds poorly to queries with multiple <b>JOIN</b>s of tables if not properly configured.<br />
Reuse of fields can reduce the number of tables in the Drupal database. For example, if 10 image fields, <i>field_image_a</i>, <i>field_image_b</i>, …, <i>field_image_j</i>, are added to the system, 10 tables are added to the database. If a single content type only utilizes two image fields, one <i>thumbnail</i> and one <i>image</i>, we can redefine the fields as <i>field_image_thumbnail</i> and <i>field_image</i>. Only two tables are introduced to the database with the latter configuration.<br />
Reuse of fields can also reduce the system’s complexity. Instead of creating and maintaining 10 different fields, Drupal admins maintain only two fields and their documentation. Database administrators only need to improve performance of two extra tables. KISS is always a good principle.</div></div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com4tag:blogger.com,1999:blog-1817729882430277165.post-81285109705672224942011-04-16T12:00:00.000-07:002011-04-16T12:01:44.698-07:00Drupal Ebook Download<div dir="ltr" style="text-align: left;" trbidi="on">Here I have found a rapidshare link having good collection of Ebooks about Drupal 7. This file is about 60MB in size. It have 9 files inside a rar file. This ebook will surely help those people who are new in Drupal 7 and ofcourse the professionals who are trying to grasp all the techie thing hidden inside drupal. So.. Why are you waiting for? Download this file, extract it and get started with Drupal. Enjoy !!<br />
<br />
Download E-Books :<br />
<a href="http://rapidshare.com/files/262785787/9PACK_Drupal_ebook.rar">http://rapidshare.com/files/262785787/9PACK_Drupal_ebook.rar</a><br />
<br />
</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com5tag:blogger.com,1999:blog-1817729882430277165.post-63553432438063183822011-04-13T08:15:00.000-07:002011-04-13T08:15:00.073-07:00New features in Drupal 7<div dir="ltr" style="text-align: left;" trbidi="on">Drupal 7 is a hot topic of discussion these days and all active Internet users are talking about recent release of this Content Management System. To be on the wave of all modern approaches and technologies we've decided to sum up all advantages of this CMS system and make a short review. So, why should we use this CMS script and why it's better than Drupal 6 or other CMS systems. In the overview below we present new top features that have been made in Drupal 7.<br />
<br />
Let's start from the beginning, from the installation. Drupal's installation script makes launching of the system much easier and it automatically populates database tables and configures the correct settings you need. It runs natively on MySQL but also supports a wide range of other databases. If you are not aware how to install Drupal 7 you can find out it in this detailed guide.<br />
<br />
Three are better than one! Three core layouts instead of the default Garland theme! New amazing trio which includes Bartik, Seven and Stark themes can be easily downloaded and installed from Drupal.org or you can create your own custom theme!<br />
<br />
If you want to have a full control over the look and feel of the site you’re building - Drupal7 is the best solution for this. The main change in updated Drupal 7 is the generalization of common data structures into entities. You can put fields almost on everything: on nodes, terms and even users. You are able to do CCK (Content Construction Kit) stuff to comments and vocabularies. This CMS system enables to create new content types, such as an article, blog post, or even music album. And this wholesome feature is used by default in Drupal7.<br />
<br />
One more build-in to the core Drupal 7 installation feature is - image styles. It enables to set picture styles, such as scaling, cropping and even turning your images grayscale. It is perfect for people who want to build a portfolio website, cause they can specify different image styles for thumbnails and full-view images. Just upload one image, and Drupal creates all the other pictures for you!<br />
<br />
The Toolbar gives you a quick access to administrative functions from any part of the site. When you click on one of the toolbar items you are not taken to a back end area as you may expect. Now the administration pages load on the top of your website as a light box. With the improving administration interface, the appearance of the Drupal 7 has been also sophisticated. And its new look is really cool, we are sure, you'll appreciate it! <br />
The shortcut feature is also very useful and functional. Now you can add items which is used more often and get immediate access to them. It's possible to add custom shortcuts to the admin menu navigation and create several different ones for different users. The admin menu tools can be fully customized for different responsibilities such as admins, editors, authors, designer and site builders.<br />
Drupal 7 has plenty of modules by which it's easy to achieve pretty much any functionality! This is an open source Content management system which is absolutely free of cost. Drupal CMS platform is very comfortable in usage and anyone can without efforts install it and have their own website up and running within minutes.</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com16tag:blogger.com,1999:blog-1817729882430277165.post-50513921120362090442011-04-11T12:09:00.000-07:002014-11-19T02:06:52.095-08:00Drupal 7 E-Books Download<div dir="ltr" style="text-align: left;" trbidi="on">
See this link: http://pdf-ebooks.org/ebooks/drupal-7-module-development-pdf.pdf<br />
<br />
This has links of many pdf files regarding Drupal 7 Development. checkit out.<br />
<br />
Comments Expected!</div>
<br/><br/>
<script type="text/javascript"><!--
google_ad_client="pub-4893303710537311";
google_ad_host="pub-1556223355139109";
google_ad_width=468;
google_ad_height=60;
google_ad_format="468x60_as";
google_ad_type="text";
google_ad_host_channel="0001";
google_color_border="F6FDFA";
google_color_bg="FFFFFF";
google_color_link="AC2028";
google_color_url="394E55";
google_color_text="000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br/><br/>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com41tag:blogger.com,1999:blog-1817729882430277165.post-64071475433932784472011-04-09T19:02:00.000-07:002011-05-06T18:38:04.947-07:00Converting Drupal themes from Drupal 6 to Drupal 7<div dir="ltr" style="text-align: left;" trbidi="on"><h3 class="middle"><a href="http://drupal.org/update/theme/6/7#blocks" target="_blank">Blocks have new, more meaningful <span class="caps">CSS</span> IDs</a></h3>I’d say it’s about time this happened. Core <span class="caps">CSS</span> block IDs now have more meaning that relates to their functionality. <br />
Some examples:<br />
<b>Recent blog posts</b><br />
Old <span class="caps">CSS</span> ID (Drupal 6): block-blog-0<br />
New <span class="caps">CSS</span> ID (Drupal 7): block-blog-recent<br />
<b>Recent comments</b><br />
Old <span class="caps">CSS</span> ID (Drupal 6): block-comment-0<br />
New <span class="caps">CSS</span> ID (Drupal 7): block-comment-recent<br />
<br />
<i style="color: #cc0000;">** n.b: If you like this article, then please click on any one of the ad links on the top or side panel. Your small help will encourage me to deliver more useful and good tutorial resources for Drupal in this blog. **</i> <br />
<h3 class="middle"><a href="http://drupal.org/update/theme/6/7#html-class-variable" target="_blank"><span class="caps">HTML</span> classes generated through a variable</a></h3>This is something I used to patch into my node.tpl file & preprocess_node hook but now it has been included in core.<br />
Each template (.tpl file) now has a <code>$classes</code> variable which now gives themers a standard way to add <span class="caps">HTML</span> classes to their template files:<br />
<div class="codeblock"><code> </code><br />
<div 0);="" 0,="" color:="" id="node-<span style=" rgb(0,=""><span style="color: #0000bb;"><span style="color: #007700;">print </span><span style="color: #0000bb;">$node</span><span style="color: #007700;">-></span><span style="color: #0000bb;">nid</span><span style="color: #007700;">; </span><span style="color: #0000bb;">?></span></span>" class="<span style="color: black;"><span style="color: #0000bb;"><span style="color: #007700;">print </span><span style="color: #0000bb;">$classes</span><span style="color: #007700;">; </span><span style="color: #0000bb;">?></span></span> clearfix"<span style="color: black;"><span style="color: #0000bb;"><span style="color: #007700;">print </span><span style="color: #0000bb;">$attributes</span><span style="color: #007700;">; </span><span style="color: #0000bb;">?></span></span>><br />
.....</span></span></div></div>The <code>$classes</code> variable can be added to in your preprocess hooks using the <code>$classes_array</code>:<br />
<div class="codeblock"><code><span style="color: black;"><span style="color: #0000bb;"> </span><span style="color: #ff8000;">/**<br />
* example taken from core bartik theme<br />
*/</span><span style="color: #007700;">function </span><span style="color: #0000bb;">bartik_preprocess_block</span><span style="color: #007700;">(&</span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">) {<br />
</span><span style="color: #ff8000;">// Set "first" and "last" classes.<br />
</span><span style="color: #007700;">if (</span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'block'</span><span style="color: #007700;">]-></span><span style="color: #0000bb;">position_first</span><span style="color: #007700;">){<br />
</span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'classes_array'</span><span style="color: #007700;">][] = </span><span style="color: #dd0000;">'first'</span><span style="color: #007700;">;<br />
}<br />
if (</span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'block'</span><span style="color: #007700;">]-></span><span style="color: #0000bb;">position_last</span><span style="color: #007700;">){<br />
</span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'classes_array'</span><span style="color: #007700;">][] = </span><span style="color: #dd0000;">'last'</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #ff8000;">// Set "odd" & "even" classes.<br />
</span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'classes_array'</span><span style="color: #007700;">][] = </span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'block'</span><span style="color: #007700;">]-></span><span style="color: #0000bb;">position </span><span style="color: #007700;">% </span><span style="color: #0000bb;">2 </span><span style="color: #007700;">== </span><span style="color: #0000bb;">0 </span><span style="color: #007700;">? </span><span style="color: #dd0000;">'odd' </span><span style="color: #007700;">: </span><span style="color: #dd0000;">'even'</span><span style="color: #007700;">;<br />
}</span><span style="color: #0000bb;">?></span></span></code></div><h3 class="middle"><a href="http://drupal.org/update/theme/6/7#html-attributes-variable" target="_blank"><span class="caps">HTML</span> attributes generated through a variable</a></h3>Now all template (.tpl) files can output 3 new variables; $attributes, $title_attributes, and $content_attributes which like the <code>$classes</code> variable mentioned above can be altered or added to in your preprocess functions. <br />
<h3 class="middle"><a href="http://drupal.org/update/theme/6/7#browser-targeted-css" target="_blank">Nice additions to drupal_add_css() function</a></h3>The <a href="http://api.drupal.org/api/function/drupal_add_css/7" target="_blank">drupal_add_css()</a> function is used to attach <span class="caps">CSS</span> files to pages and the following functionality has been added:<br />
<ul><li><b>‘weight’</b> – You can now weight your <span class="caps">CSS</span> file loading although I can’t think of too many times when you’d need this.</li>
</ul><ul><li><b>‘browsers’</b> – You can now browser-targeted your <span class="caps">CSS</span> files, so you can easily add IE <span class="caps">CSS</span> fixes without needing to add <code></code> code to your templates, which is great in my opinion.</li>
</ul><h3 class="middle"><a href="http://drupal.org/update/theme/6/7#variables-processors-for-all-theme-hooks" target="_blank">Variable process functions can now be used for all theming hooks</a></h3>Previously you could only use <a href="http://api.drupal.org/api/function/hook_preprocess/7" target="_blank">preprocess functions</a> (called before the theme template to add/alter variables that go into the .tpl file) in your theme when a .tpl file was defined for the theme function output:<br />
template (.tpl) file:<br />
<div class="codeblock"><code></code><br />
<div class="some-div-title"><br />
<span style="color: black;"><span style="color: #0000bb;"><span style="color: #007700;">echo </span><span style="color: #0000bb;">$some_custom_var</span><span style="color: #007700;">; </span><span style="color: #0000bb;">?></span></span></span></div></div><br />
Related hook_preprocess:<br />
<div class="codeblock"><code><span style="color: black;"><span style="color: #0000bb;"></span><span style="color: #007700;">function </span><span style="color: #0000bb;">THEME_preprocess_HOOK</span><span style="color: #007700;">(&</span><span style="color: #0000bb;">$vars</span><span style="color: #007700;">) {<br />
if (.....) {<br />
</span><span style="color: #0000bb;">$vars</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'some_custom_var'</span><span style="color: #007700;">] = </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Hi there'</span><span style="color: #007700;">);<br />
}<br />
}</span><span style="color: #0000bb;">?></span></span></code></div><span class="caps">BUT</span> now all theme hooks can have a <a href="http://api.drupal.org/api/function/hook_preprocess/7" target="_blank">hook_preprocess</a> and a new <a href="http://api.drupal.org/api/function/hook_process/7" target="_blank">hook_process</a> (<a href="http://drupalsn.com/learn-drupal/drupal-tutorials/converting-drupal-themes-drupal-6-drupal-7-my-favourite-additions-chan#process">see notes on that below</a>) which can be used to add new variables & alter current variables which are passed to the define theme function:<br />
theme_ function:<br />
<div class="codeblock"><code><span style="color: black;"><span style="color: #0000bb;"></span><span style="color: #007700;">function </span><span style="color: #0000bb;">theme_something_nice</span><span style="color: #007700;">() <br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$some_custom_var</span><span style="color: #007700;">;<br />
return </span><span style="color: #0000bb;">$output</span><span style="color: #007700;">;<br />
}</span><span style="color: #0000bb;">?></span></span></code></div><br />
Related hook_preprocess:<br />
<div class="codeblock"><code><span style="color: black;"><span style="color: #0000bb;"></span><span style="color: #007700;">function </span><span style="color: #0000bb;">THEME_preprocess_HOOK</span><span style="color: #007700;">(&</span><span style="color: #0000bb;">$vars</span><span style="color: #007700;">) {<br />
if (.....) {<br />
</span><span style="color: #0000bb;">$vars</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'some_custom_var'</span><span style="color: #007700;">] = </span><span style="color: #0000bb;">t</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Hi there'</span><span style="color: #007700;">);<br />
}<br />
}</span><span style="color: #0000bb;">?></span></span></code></div><h3 class="middle"><a href="http://drupal.org/update/theme/6/7#function-names-phptemplate" target="_blank">Function names must match theme name</a></h3>This will save a fair bit of confusion! When overriding module theme functions in <b>your theme you can no longer use the phptemplate_ prefix</b> and instead have to use the name of your theme as a prefix instead:<br />
Drupal 6:<br />
<div class="codeblock"><code><span style="color: black;"><span style="color: #0000bb;"></span><span style="color: #ff8000;">/**<br />
* both examples work in Drupal 6<br />
*/</span><span style="color: #007700;">function </span><span style="color: #0000bb;">phptemplate_breadcrumb</span><span style="color: #007700;">() {<br />
......<br />
}</span><span style="color: #0000bb;">?></span></span></code></div>Drupal 7:<br />
<div class="codeblock"><code><span style="color: black;"><span style="color: #0000bb;"></span><span style="color: #007700;">function </span><span style="color: #0000bb;">THEMENAME_breadcrumb</span><span style="color: #007700;">() {<br />
.....<br />
}</span><span style="color: #0000bb;">?></span></span></code></div>Read more on <a href="http://drupal.org/node/422116" target="_blank">why the phptemplate prefix was removed</a>.<br />
<h3 class="middle"><a href="http://drupal.org/update/theme/6/7#granular" target="_blank">Granular rendering in node and user templates</a></h3>Ever hacked up your node.tpl.php file and print bits of the <code>$node</code> object all over the place to get the content layout exactly as you want? Well with the new <a href="http://api.drupal.org/api/function/render/7" target="_blank">render</a> & <a href="http://api.drupal.org/api/function/hide/7" target="_blank">hide</a> functions things just got a little easier!!<br />
The <code>$content</code> variable is now a keyed array of the content values including field values, comments, file attachments or other node components which vary depending on the view mode (full, teaser etc). If you’d like to go deeper check out the the <a href="http://api.drupal.org/api/function/node_build_content/7" target="_blank">node_build_content <span class="caps">API</span> doc on api.drupal.org</a> <br />
Here’s an example from the Garland theme node.tpl.php file, as you can see the node links & comments can be pulled out and rendered as where you please:<br />
<div class="codeblock"><code> </code><br />
<div class="content clearfix"><span style="color: black;"><span style="color: #0000bb;"><span style="color: #007700;">print </span><span style="color: #0000bb;">$content_attributes</span><span style="color: #007700;">; </span><span style="color: #0000bb;">?></span></span>><br />
<span style="color: black;"><span style="color: #0000bb;"> </span><span style="color: #ff8000;">// We hide the comments and links now so that we can render them later.<br />
</span><span style="color: #0000bb;">hide</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$content</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'comments'</span><span style="color: #007700;">]);<br />
</span><span style="color: #0000bb;">hide</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$content</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'links'</span><span style="color: #007700;">]);<br />
print </span><span style="color: #0000bb;">render</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$content</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?></span></span><br />
</span></div><br />
<br />
<br />
<div class="clearfix"><br />
<span style="color: black;"><span style="color: #0000bb;"><span style="color: #007700;">if (!empty(</span><span style="color: #0000bb;">$content</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'links'</span><span style="color: #007700;">])): </span><span style="color: #0000bb;">?></span></span><br />
<div class="links"><span style="color: black;"><span style="color: #0000bb;"><span style="color: #007700;">print </span><span style="color: #0000bb;">render</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$content</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'links'</span><span style="color: #007700;">]); </span><span style="color: #0000bb;">?></span></span></span></div><br />
<span style="color: black;"><span style="color: #0000bb;"><span style="color: #007700;">endif; </span><span style="color: #0000bb;">?></span></span><br />
<br />
<span style="color: black;"><span style="color: #0000bb;"><span style="color: #007700;">print </span><span style="color: #0000bb;">render</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$content</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'comments'</span><span style="color: #007700;">]); </span><span style="color: #0000bb;">?></span></span><br />
</span></span></span></div></div><h3 class="middle"><a href="http://drupal.org/update/theme/6/7#theme_alter" target="_blank" title="YEEEH!!">Alter hooks available to themes!!</a></h3>This is by far my favourite addition. <br />
The following alter hooks have now be added or made available to use in your themes:<br />
<ul><li><a href="http://api.drupal.org/api/function/hook_page_alter/7" target="_blank">hook_page_alter</a> – This is a new D7 hook which allows all variables displayed on a page to be alter or hidden.</li>
<li><a href="http://api.drupal.org/api/function/hook_form_alter/7" target="_blank">hook_form_alter</a> – I’ve lost count of how many times I’ve wanted to make a small tweak to a form without wanting to override the form theme or create a custom module.</li>
<li><a href="http://api.drupal.org/api/function/hook_js_alter/7" target="_blank">hook_js_alter</a> </li>
</ul><ul><li><a href="http://api.drupal.org/api/function/hook_css_alter/7" target="_blank">hook_css_alter</a> </li>
</ul>These additions give even more power to Drupal theme developers which is brilliant news!! :) :)<br />
<h3 class="middle"><a href="http://drupal.org/update/theme/6/7#theme-suggestions-for-menus" target="_blank">Theme suggestions available for theme_menu_link() and theme_menu_tree()</a></h3>I’ve previously used the awesome <a href="http://drupal.org/project/menu_block" target="_blank">menu_block module</a> to theme out menus better as it uses a similar theme suggestion engine that is now available in Drupal 7.<br />
The new suggestion work for both <a href="http://api.drupal.org/api/function/theme_menu_tree/7" target="_blank">theme_menu_tree</a> which provides some wrapper <span class="caps">HTML</span> for the menu and <a href="http://api.drupal.org/api/function/theme_menu_link/7" target="_blank">theme_menu_link</a> which does the actual rendering of the menu link, so you can override these functions per menu.<br />
Here’s a simple example for a theme_menu_link override for a fictional user called “account” where we simply add an extra <code></code> around the link to give us another <span class="caps">HTML</span> element to theme with:<br />
<div class="codeblock"><code><span style="color: black;"><span style="color: #0000bb;"></span><span style="color: #007700;">function </span><span style="color: #0000bb;">THEMENAME_menu_link__account</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">) {<br />
</span><span style="color: #0000bb;">$element </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$variables</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'element'</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$sub_menu </span><span style="color: #007700;">= </span><span style="color: #dd0000;">''</span><span style="color: #007700;">;<br />
<br />
if (</span><span style="color: #0000bb;">$element</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'#below'</span><span style="color: #007700;">]) {<br />
</span><span style="color: #0000bb;">$sub_menu </span><span style="color: #007700;">= </span><span style="color: #0000bb;">drupal_render</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$element</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'#below'</span><span style="color: #007700;">]);<br />
}<br />
</span><span style="color: #0000bb;">$output </span><span style="color: #007700;">= </span><span style="color: #dd0000;">''<span style="color: #007700;">. </span><span style="color: #0000bb;">l</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$element</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'#title'</span><span style="color: #007700;">], </span><span style="color: #0000bb;">$element</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'#href'</span><span style="color: #007700;">], </span><span style="color: #0000bb;">$element</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'#localized_options'</span><span style="color: #007700;">]) .</span><span style="color: #dd0000;">'</span>'</span><span style="color: #007700;">; </span><span style="color: #ff8000;">//add extra span tag here for theming<br />
</span><span style="color: #007700;">return </span><span style="color: #dd0000;">'<li'></li'></span><span style="color: #007700;">. </span><span style="color: #0000bb;">drupal_attributes</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$element</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'#attributes'</span><span style="color: #007700;">]) . </span><span style="color: #dd0000;">'>' </span><span style="color: #007700;">. </span><span style="color: #0000bb;">$output </span><span style="color: #007700;">. </span><span style="color: #0000bb;">$sub_menu </span><span style="color: #007700;">. </span><span style="color: #dd0000;">"\n"</span><span style="color: #007700;">;<br />
}</span><span style="color: #0000bb;">?></span></span></code></div><h3 class="middle">hook_preprocess is now followed by hook_process <a href="http://www.blogger.com/post-edit.g?blogID=1817729882430277165&postID=6407147543393278447" name="process"></a></h3>I’m still a little hazy on the exact usage of the new hook_process so I wouldn’t consider it a favourite of mind….yet but I thought it should be mentioned. <br />
The idea is that <a href="http://api.drupal.org/api/function/hook_preprocess/7" target="_blank">hook_preprocess</a> is run first to define values of variables then <a href="http://api.drupal.org/api/function/hook_process/7" target="_blank">hook_process</a> is fired after to render variables.<br />
An example being the <code>$classes_array</code> is defined/constructed in hook_preprocess and is then rendered into the <code>$classes</code> string in hook_process.<br />
That concludes my favourite additions to Drupal 7 theming but please note that with Drupal 7 still being developed some of this functionality could (although unlikely) change so comment below if you find something has changed or add your favourite additions.</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com14tag:blogger.com,1999:blog-1817729882430277165.post-47965219658555889092011-04-07T12:01:00.001-07:002011-04-20T19:06:26.011-07:00How to create a custom field for Drupal 7 ?<div dir="ltr" style="text-align: left;" trbidi="on">As you may be aware, the CCK (Content Creation Kit) module has been integrated into Drupal 7 as the Field module. This article is the first in a three part series on creating a custom field using the Drupal 7 Field API. I will be using the <a href="http://drupal.org/project/integerdate">Integer date field</a> contributed module as an example thruout this series. You can learn more about the Field API by reading through the <a href="http://api.drupal.org/api/group/field/7">Field API documentation</a>.<br />
In this article I will look at creating a simple field formatter. A field formatter is what you choose on a content type's "Manage Display" tab to format the content of a field when a node is displayed. I am starting with the field formatter because it is the easiest of the three components of a field (field type, field widget, field formatter) to implement correctly, and because you may wish to build a formatter for an existing field without building a widget.<br />
<br />
** n.b: If you like this post, then please click on any one of the ad links on the top or side panel. Your small help will encourage me to deliver more useful and good tutorial resources for Drupal in this blog. <br />
<h2>The Integer date field module</h2>The Integer date field module defines a field type that stores integer values, a widget to allow users to enter dates to be converted into integers, and a formatter to display integers as dates. The conversion between date and integer is performed using the PHP <a href="http://php.net/manual/en/function.strtotime.php">strtotime</a>() function and the conversion between integer and date is performed using the Drupal Core <a href="http://api.drupal.org/api/function/format_date/7">format_date</a>() function.<br />
<h2>Hooks required for a field formatter</h2>The following list of hooks are required to implement a field formatter, I will discuss their implementation in the Integer date field module in further detail in the sections to follow.<br />
<ul><li><a href="http://api.drupal.org/api/function/hook_field_formatter_info/7">hook_field_formatter_info</a>()</li>
<li><a href="http://api.drupal.org/api/function/hook_field_formatter_settings_form/7">hook_field_formatter_settings_form</a>()</li>
<li><a href="http://api.drupal.org/api/function/hook_field_formatter_settings_summary/7">hook_field_formatter_settings_summary</a>()</li>
<li><a href="http://api.drupal.org/api/function/hook_field_formatter_view/7">hook_field_formatter_view</a>()</li>
</ul><h2>Implementing hook_field_formatter_info()</h2><blockquote><pre>/**
* Implements hook_field_formatter_info().
*/
function integerdate_field_formatter_info() {
return array(
'integerdate_date_default' => array(
'label' => t('Default formatted date'),
'field types' => array('integerdate_date',),
'settings' => array(
'format_custom_string' => '',
'format_option' => 'short',
),
),
);
}</pre></blockquote>The hook_field_formatter_info() function is required to register a formatter with the Field API. The above implementation registers a formatter with the machine readable name 'integerdate_date_default', defines the field types to which the formatter can be applied, sets a human readable label and description, and pre-defines default settings for the formatter. The formatter settings will be 'format_option' and 'format_custom_string', which will be described in the next section. The above implementation provides that the formatter can be applied to the integerdate_date field type. This field type is defined in integerdate.module and will be discussed in the third article of this series. The 'field type' value above could just as easily have been set to the Drupal number_integer field type so that the formatter could be applied to a Drupal integer field. <br />
<h2>Implementing hook_field_formatter_settings_form()</h2><blockquote><pre>/**
* Implements hook_field_formatter_settings_form().
*/
function integerdate_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
$element['format_option'] = array(
'#type' => 'select',
'#title' => t('Select date format'),
'#description' => t('Select the date format for this instance'),
'#options' => array(
'short' => integerdate_field_formatter_format_date(REQUEST_TIME, 'short'),
'medium' => integerdate_field_formatter_format_date(REQUEST_TIME, 'medium'),
'long' => integerdate_field_formatter_format_date(REQUEST_TIME, 'long'),
'html5_date' => format_date(REQUEST_TIME, 'custom', 'Y\-m\-d') . ' (HTML5 )',
'html5_month' => format_date(REQUEST_TIME, 'custom', 'Y\-m') . ' (HTML5 )',
'custom' => t(''),
),
'#default_value' => $settings['format_option'],
'#multiple' => FALSE,
);
$element['format_custom_string'] = array(
'#type' => 'textfield',
'#title' => t('Custom format string'),
'#description' => t('Enter a custom format string, to be used if "Custom format" is selected'),
'#default_value' => $settings['format_custom_string'],
);
return $element;
}</pre></blockquote>The hook_field_formatter_settings_form() function is required to provide a settings form for the formatter. The implementation above implements two form elements: <br />
<ul><li>format_option: a select element providing several default options for how the field will be displayed.</li>
<li>format_custom_string: a textfield element allowing administrators to define their own date format using a <a href="http://php.net/manual/en/function.date.php">PHP date format string</a>.</li>
</ul>The displayed values of the format_option select element options are generated by the integerdate_field_formatter_format_date() function, which is a simple wrapper for Drupal's format_date() function, which itself is a wrapper for the PHP date() function. You can look in integerdate.module to see the source for this function. <br />
<h2>Implementing hook_field_formatter_settings_summary()</h2><blockquote><pre>/**
* Implements hook_field_formatter_settings_summary().
*/
function integerdate_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = integerdate_field_formatter_format_date(REQUEST_TIME, $settings['format_option'], $settings['format_custom_string']);
return $summary;
}</pre></blockquote>The hook_field_formatter_settings_summary() function is required to display a summary of the formatter settings on a content type's "Manage display" tab, and is also required to expose the settings "Edit" control, without which administrators cannot modify the formatter's settings. The function returns a string representing a summary of the formatter settings. The implementation above returns the page request time formatted using the selected format option. <br />
<h2>Implementing hook_field_formatter_view()</h2>/** * Implements hook_field_formatter_view(). */ function integerdate_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $settings = $display['settings']; $element = array(); $formatted_date = integerdate_field_formatter_format_date($items[0]['value'], $settings['format_option'], $settings['format_custom_string']); $element[0] = array('#markup' => $formatted_date); return $element; } The hook_field_formatter_view() function is required to display the formatted field value. This function is where the magic of formatting a field happens when a node is displayed. The implementation above performs almost exactly the same behavior as the implementation of hook_field_formatter_settings_summary(). However, in order to format the field value it passes $items[0]['value'] to the date formatting function, instead of passing the page request time. $items is an array representing all of the field values to be formatted. As this field type currently only allows for a single value the function is hard coded to use the 0th array index. $items[0]['value'] is the value of the integerdate_date and number_integer field types. This key varies depending on which field type you are using. It is a good practice to read the documentation, including the <a href="http://api.drupal.org/api/function/hook_field_schema/7">hook_field_schema</a>() implementation for any field type for which you intend to build a formatter. </div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com17tag:blogger.com,1999:blog-1817729882430277165.post-12543324053964326712011-04-03T02:16:00.000-07:002014-11-19T02:08:40.345-08:00Drupal 7 Field API - Setup a new content type on install and add fields<div dir="ltr" style="text-align: left;" trbidi="on">
At the moment we are building a Drupal 7 site which requires everything to be enabled on install via modules / custom profiles. Below is a content type with some extra fields added using Field API so you can see how they are added. This should go in the module *.install file. We go through the standard process of setting up a content type, and call installed_fields and installed_instances functions.<br />
You might want to rename it from ‘article’ to something else, from what I remember on the standard install profile, Drupal 7 already creates a content type called article.<br />
<br/><br/><script type="text/javascript"><!--
google_ad_client="pub-4893303710537311";
google_ad_host="pub-1556223355139109";
google_ad_width=468;
google_ad_height=60;
google_ad_format="468x60_as";
google_ad_type="text";
google_ad_host_channel="0001";
google_color_border="F6FDFA";
google_color_bg="FFFFFF";
google_color_link="AC2028";
google_color_url="394E55";
google_color_text="000000";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br/><br/>
<br />
<br />
<div style="color: #351c75;">
<br /></div>
<pre style="color: #351c75;"><span class="r">function</span> <span class="fu">article_install</span>() {
<span class="c">// get the translation function relevant to our current localisation</span>
<span class="lv">$t</span> = get_t();
<span class="c">// define the content type as an array (same as in hook_node_info())</span>
<span class="lv">$article</span> = <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">name</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Article</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">base</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">node_content</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">description</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Content type to handle articles.</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">body_label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Article Description</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">promote</span><span class="dl">'</span></span> => <span class="i">0</span>,
<span class="s"><span class="dl">'</span><span class="k">status</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">comment</span><span class="dl">'</span></span> => <span class="i">0</span>,
);
<span class="c">// set default values for anything not explicitly defined in the above array</span>
<span class="lv">$content_type</span> = node_type_set_defaults(<span class="lv">$article</span>);
<span class="c">// add the body field to the content type</span>
node_add_body_field(<span class="lv">$content_type</span>, <span class="s"><span class="dl">'</span><span class="k">Body</span><span class="dl">'</span></span>);
<span class="c">// create the content type</span>
node_type_save(<span class="lv">$content_type</span>);
variable_set(<span class="s"><span class="dl">'</span><span class="k">node_options_article</span><span class="dl">'</span></span>, <span class="pd">array</span>(<span class="s"><span class="dl">'</span><span class="k">status</span><span class="dl">'</span></span>));
<span class="c">// hide comments for this node. http://api.drupal.org/api/drupal/modules--comment--comment.module/7</span>
variable_set(<span class="s"><span class="dl">'</span><span class="k">comment_article</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">COMMENT_NODE_HIDDEN</span><span class="dl">'</span></span>);
<span class="c">// Hide date and author information</span>
variable_set(<span class="s"><span class="dl">'</span><span class="k">node_submitted_article</span><span class="dl">'</span></span>, <span class="pc">FALSE</span>);
<span class="c">// Create all the fields we are adding to our content type.</span>
<span class="c">// http://api.drupal.org/api/function/field_create_field/7</span>
<span class="r">foreach</span> (_article_installed_fields() <span class="r">as</span> <span class="lv">$field</span>) {
field_create_field(<span class="lv">$field</span>);
}
<span class="c">// Create all the instances for our fields.</span>
<span class="c">// http://api.drupal.org/api/function/field_create_instance/7</span>
<span class="r">foreach</span> (_article_installed_instances() <span class="r">as</span> <span class="lv">$instance</span>) {
<span class="lv">$instance</span>[<span class="s"><span class="dl">'</span><span class="k">entity_type</span><span class="dl">'</span></span>] = <span class="s"><span class="dl">'</span><span class="k">node</span><span class="dl">'</span></span>;
<span class="lv">$instance</span>[<span class="s"><span class="dl">'</span><span class="k">bundle</span><span class="dl">'</span></span>] = <span class="s"><span class="dl">'</span><span class="k">article</span><span class="dl">'</span></span>;
field_create_instance(<span class="lv">$instance</span>);
}
<span class="c">// adjust the weight so it's called after a dependant module called 'categories'</span>
<span class="lv">$weight</span> = db_query(<span class="s"><span class="dl">"</span><span class="k">SELECT weight FROM </span><span class="s">{</span><span class="k">system} WHERE name = :name</span><span class="dl">"</span></span>, <span class="pd">array</span>(<span class="s"><span class="dl">'</span><span class="k">:name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">categories</span><span class="dl">'</span></span>))->fetchField();
db_update(<span class="s"><span class="dl">'</span><span class="k">system</span><span class="dl">'</span></span>)->fields(<span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">weight</span><span class="dl">'</span></span> => <span class="lv">$weight</span> + <span class="i">1</span>,
))
->condition(<span class="s"><span class="dl">'</span><span class="k">name</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">article</span><span class="dl">'</span></span>)
->execute();
}
<span class="r">function</span> <span class="fu">_article_installed_fields</span>() {
<span class="lv">$t</span> = get_t();
<span class="lv">$fields</span> = <span class="pd">array</span>(
<span class="c">// text field</span>
<span class="s"><span class="dl">'</span><span class="k">article_source</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_source</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Artcile Source</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">text</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">max_length</span><span class="dl">'</span></span> => <span class="i">1000</span>,
),
),
<span class="c">// taxonomy term reference field, referencing a vocabulary called 'authors'</span>
<span class="s"><span class="dl">'</span><span class="k">article_author</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_author</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">taxonomy_term_reference</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="co">FIELD_CARDINALITY_UNLIMITED</span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">allowed_values</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">vocabulary</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">authors</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">parent</span><span class="dl">'</span></span> => <span class="i">0</span>,
),
),
),
),
<span class="c">// node refererence auto complete field (see the instance), referencing a content-type called 'work'</span>
<span class="s"><span class="dl">'</span><span class="k">article_work_ref</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_work_ref</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Work refrerence</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="co">FIELD_CARDINALITY_UNLIMITED</span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">node_reference</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">referenceable_types</span><span class="dl">'</span></span> => <span class="pd">array</span>(<span class="s"><span class="dl">'</span><span class="k">work</span><span class="dl">'</span></span>),
),
),
<span class="c">// a text (textarea) field</span>
<span class="s"><span class="dl">'</span><span class="k">article_pullquote</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_pullquote</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Pull Quote</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">text</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">max_length</span><span class="dl">'</span></span> => <span class="i">1000</span>,
),
),
<span class="c">// image field</span>
<span class="s"><span class="dl">'</span><span class="k">article_image</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_image</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Image</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">image</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">default_image</span><span class="dl">'</span></span> => <span class="i">0</span>,
<span class="s"><span class="dl">'</span><span class="k">uri_scheme</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">public</span><span class="dl">'</span></span>,
),
),
<span class="c">// date field (date module required)</span>
<span class="s"><span class="dl">'</span><span class="k">article_date</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_date</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Date</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">date</span><span class="dl">'</span></span>,
),
);
<span class="r">return</span> <span class="lv">$fields</span>;
}
<span class="r">function</span> <span class="fu">_article_installed_instances</span>() {
<span class="lv">$t</span> = get_t();
<span class="lv">$instances</span> = <span class="pd">array</span>(
<span class="c">// instance of the text field above</span>
<span class="s"><span class="dl">'</span><span class="k">article_source</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_source</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Article Source</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">widget</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">text_textfield</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(<span class="s"><span class="dl">'</span><span class="k">size</span><span class="dl">'</span></span> => <span class="i">60</span>),
),
),
<span class="c">// instance of the taxonomy term reference field above</span>
<span class="s"><span class="dl">'</span><span class="k">article_author</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_author</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">entity_type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">node</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Author</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">bundle</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">required</span><span class="dl">'</span></span> => <span class="pc">FALSE</span>,
<span class="s"><span class="dl">'</span><span class="k">widget</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">options_select</span><span class="dl">'</span></span>,
),
),
<span class="c">// instance of the node reference 'work' auto complete field above</span>
<span class="s"><span class="dl">'</span><span class="k">article_work_ref</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_work_ref</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Work refrerence</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="co">FIELD_CARDINALITY_UNLIMITED</span>,
<span class="s"><span class="dl">'</span><span class="k">widget</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">node_reference_autocomplete</span><span class="dl">'</span></span>,
),
),
<span class="c">// instance of the textarea field above</span>
<span class="s"><span class="dl">'</span><span class="k">article_pullquote</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_pullquote</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Pull Quote</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">widget</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">text_textarea</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(<span class="s"><span class="dl">'</span><span class="k">rows</span><span class="dl">'</span></span> => <span class="i">5</span>),
),
),
<span class="c">// instance of the image field above</span>
<span class="s"><span class="dl">'</span><span class="k">article_image</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_image</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Image</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_image</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">alt_field</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">file_directory</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">image</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">file_extensions</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">png gif jpg jpeg</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">max_filesize</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">max_resolution</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">min_resolution</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">title_field</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">user_register_form</span><span class="dl">'</span></span> => <span class="pc">FALSE</span>,
),
<span class="s"><span class="dl">'</span><span class="k">widget</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">preview_image_style</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">thumbnail</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">progress_indicator</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">throbber</span><span class="dl">'</span></span>,
),
),
<span class="s"><span class="dl">'</span><span class="k">display</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">default</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">hidden</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">image</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(<span class="s"><span class="dl">'</span><span class="k">image_style</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">bfi_common_features_image</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">image_link</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">weight</span><span class="dl">'</span></span> => -<span class="i">1</span>,
),
<span class="s"><span class="dl">'</span><span class="k">teaser</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">hidden</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">image</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(<span class="s"><span class="dl">'</span><span class="k">image_style</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">thumbnail</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">image_link</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">content</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">weight</span><span class="dl">'</span></span> => -<span class="i">1</span>,
),
),
),
<span class="c">// instance of the date field above</span>
<span class="s"><span class="dl">'</span><span class="k">article_date</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">field_name</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article_date</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">label</span><span class="dl">'</span></span> => <span class="lv">$t</span>(<span class="s"><span class="dl">'</span><span class="k">Date</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">cardinality</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">widget</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">date_select</span><span class="dl">'</span></span>,
<span class="s"><span class="dl">'</span><span class="k">settings</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">input_format</span><span class="dl">'</span></span> => date_default_format(<span class="s"><span class="dl">'</span><span class="k">date_select</span><span class="dl">'</span></span>),
<span class="s"><span class="dl">'</span><span class="k">increment</span><span class="dl">'</span></span> => <span class="i">1</span>,
<span class="s"><span class="dl">'</span><span class="k">year_range</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">-3:+3</span><span class="dl">'</span></span>,
),
<span class="s"><span class="dl">'</span><span class="k">behaviors</span><span class="dl">'</span></span> => <span class="pd">array</span>(
<span class="s"><span class="dl">'</span><span class="k">multiple values</span><span class="dl">'</span></span> => <span class="co">FIELD_BEHAVIOR_CUSTOM</span>,
<span class="s"><span class="dl">'</span><span class="k">default value</span><span class="dl">'</span></span> => <span class="co">FIELD_BEHAVIOR_CUSTOM</span>,
),
),
),
);
<span class="r">return</span> <span class="lv">$instances</span>;
}
<span class="r">function</span> <span class="fu">article_uninstall</span>() {
<span class="c">// Gather all the example content that might have been created while this</span>
<span class="c">// module was enabled. Simple selects still use db_query().</span>
<span class="c">// http://api.drupal.org/api/function/db_query/7</span>
<span class="lv">$sql</span> = <span class="s"><span class="dl">'</span><span class="k">SELECT nid FROM {node} n WHERE n.type = :type</span><span class="dl">'</span></span>;
<span class="lv">$result</span> = db_query(<span class="lv">$sql</span>, <span class="pd">array</span>(<span class="s"><span class="dl">'</span><span class="k">:type</span><span class="dl">'</span></span> => <span class="s"><span class="dl">'</span><span class="k">article</span><span class="dl">'</span></span>));
<span class="lv">$nids</span> = <span class="pd">array</span>();
<span class="r">foreach</span> (<span class="lv">$result</span> <span class="r">as</span> <span class="lv">$row</span>) {
<span class="lv">$nids</span>[] = <span class="lv">$row</span>->nid;
}
<span class="c">// Delete all the nodes at once</span>
<span class="c">// http://api.drupal.org/api/function/node_delete_multiple/7</span>
node_delete_multiple(<span class="lv">$nids</span>);
<span class="c">// Loop over each of the fields defined by this module and delete</span>
<span class="c">// all instances of the field, their data, and the field itself.</span>
<span class="c">// http://api.drupal.org/api/function/field_delete_field/7</span>
<span class="r">foreach</span> (<span class="pd">array_keys</span>(_article_installed_fields()) <span class="r">as</span> <span class="lv">$field</span>) {
field_delete_field(<span class="lv">$field</span>);
}
<span class="c">// Delete our content type</span>
<span class="c">// http://api.drupal.org/api/function/node_type_delete/7</span>
node_type_delete(<span class="s"><span class="dl">'</span><span class="k">article</span><span class="dl">'</span></span>);
<span class="c">// Purge all field information</span>
<span class="c">// http://api.drupal.org/api/function/field_purge_batch/7</span>
field_purge_batch(<span class="i">1000</span>);
}</pre>
</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com37tag:blogger.com,1999:blog-1817729882430277165.post-41570995936972133592011-02-12T18:36:00.000-08:002011-02-24T17:24:52.910-08:00How to print comment anywhere in Drupal<div dir="ltr" style="text-align: left;" trbidi="on">Drupals standard practice of printing node comments below the node can get a bit stale. Sometimes you may want, or simply need to, print them somewhere else. Wouldn’t be great if comments and the comment form were just variables you could move around?<br />
<br />
Well you can—thanks to Drupal 6’s phptemplate_preprocess_page function we can easily store both the comments and the comment form in variables. The only caveat is that you must set the comment reply form to a separate page first, or something might break.<br />
<br />
The following snippets store the comment form and comments in variables and allow you print them in page.tpl.php.<br />
<br />
<br />
// Store comments and the comment form in variables<br />
function phptemplate_preprocess_page(&$vars) {<br />
$vars['comments'] = $vars['comment_form'] = '';<br />
if (module_exists('comment') && isset($vars['node'])) {<br />
$vars['comments'] = comment_render($vars['node']);<br />
$vars['comment_form'] = drupal_get_form('comment_form',<br />
array('nid' => $vars['node']->nid));<br />
}<br />
}<br />
<br />
// Unset comments from node<br />
function phptemplate_preprocess_node(&$vars) {<br />
$vars['node']->comment = 0;<br />
}<br />
?><br />
<br />
<br />
<br />
Now you can print $comments and $comment_form anywhere in page.tpl.php, and they will only print when you are viewing a node.</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com24tag:blogger.com,1999:blog-1817729882430277165.post-7649625855055659262011-02-05T18:09:00.000-08:002011-02-05T18:22:29.846-08:00Drupal Essential Training<div dir="ltr" style="text-align: left;" trbidi="on">Here is a source for a small video tutorial to start drupal development. This concised video includes <b>basic training and ideas for drupal website development</b>. If you have a high speed internet connectivity, you can grab these tutorial within 1 Hour, it is <b style="color: #3d85c6;">512MB</b> in size. This video is actually from <b style="color: #6fa8dc;">lynda.com</b> who are specialized in selling good video tutorial for web development. There might be some copyright issue in this video, so it can be removed from rapidshare. Hurry, before the links expire.<br />
<br />
<a href="http://rapidshare.com/files/155384178/LC-DET.part1.rar">http://rapidshare.com/files/155384178/LC-DET.part1.rar</a><br />
<a href="http://rapidshare.com/files/155384140/LC-DET.part2.rar">http://rapidshare.com/files/155384140/LC-DET.part2.rar</a><br />
<a href="http://rapidshare.com/files/155384017/LC-DET.part3.rar">http://rapidshare.com/files/155384017/LC-DET.part3.rar</a><br />
<br />
Let me know your comments also.<br />
<br />
Here is the preview of the tutorial from youtube.<br />
<br />
<object width="480" height="385"><param name="movie" value="http://www.youtube-nocookie.com/v/FJgQ0xId5tY?fs=1&hl=en_US&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/FJgQ0xId5tY?fs=1&hl=en_US&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br />
</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com6tag:blogger.com,1999:blog-1817729882430277165.post-26100057953291854402011-01-31T10:13:00.000-08:002011-01-31T10:14:31.679-08:00Drupal 7 Video Tutorial [Rapidshare]After a day long searching in the internet, I have found out a source for Drupal 7 tutorial in rapidshare. I hope will help the people a lot who are just new to drupal or trying to learning drupal 7. If you have an unlimited internet option, be sure to checkout this video. It is 1.3GB in size and contains informative video about drupal 7. I personally prefer these type of video tutorials as it provides us the visual details rather than reading any e-books. It will also save your time. So why are you waiting for? Grab these videos before rapidshare gonna delete these files as I suppose that these videos are somehow copy protected, they can be anytime deleted. So hurry and good luck for your Drupal 7 exploration!<br />
<br />
<br />
<br />
http://rapidshare.com/files/397015169/WCruiser.com_Drupal.7.Essential.Video.Training.part1.rar<br />
http://rapidshare.com/files/397015092/WCruiser.com_Drupal.7.Essential.Video.Training.part2.rar<br />
http://rapidshare.com/files/397015216/WCruiser.com_Drupal.7.Essential.Video.Training.part3.rar<br />
http://rapidshare.com/files/397015177/WCruiser.com_Drupal.7.Essential.Video.Training.part4.rar<br />
http://rapidshare.com/files/397015487/WCruiser.com_Drupal.7.Essential.Video.Training.part5.rar<br />
http://rapidshare.com/files/397015453/WCruiser.com_Drupal.7.Essential.Video.Training.part6.rar<br />
http://rapidshare.com/files/397015064/WCruiser.com_Drupal.7.Essential.Video.Training.part7.rarAnish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com17tag:blogger.com,1999:blog-1817729882430277165.post-11197342989397627302011-01-26T03:41:00.000-08:002011-06-21T10:41:27.594-07:00Drupal 7 Video Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">Drupal 7 has some unique and robust features than its previous version. In connection to get good information about drupal 7's architecture, I have found out some good video tutorials to get a clear ideas about the functionalities of the drupal driven websites. I like to share them to you also. I will post regularly about these video tutorial links in this blog. Please check it out and let me know if it helps you people to get drupal addicted.<br />
<div style="color: red;"><br />
</div><br />
<br />
The total video is 1.46 GB, it has been split into 14 parts in rapidshare. Leave your comments if you like this.<br />
<br />
<a href="http://rapidshare.com/files/396592403/Drupal.7.videos.part01.rar">http://rapidshare.com/files/396592403/Drupal.7.videos.part01.rar</a><br />
<a href="http://rapidshare.com/files/396592400/Drupal.7.videos.part02.rar">http://rapidshare.com/files/396592400/Drupal.7.videos.part02.rar</a><br />
<a href="http://rapidshare.com/files/396592418/Drupal.7.videos.part03.rar">http://rapidshare.com/files/396592418/Drupal.7.videos.part03.rar</a><br />
<a href="http://rapidshare.com/files/396592411/Drupal.7.videos.part04.rar">http://rapidshare.com/files/396592411/Drupal.7.videos.part04.rar</a><br />
<a href="http://rapidshare.com/files/396592416/Drupal.7.videos.part05.rar">http://rapidshare.com/files/396592416/Drupal.7.videos.part05.rar</a><br />
<a href="http://rapidshare.com/files/396592410/Drupal.7.videos.part06.rar">http://rapidshare.com/files/396592410/Drupal.7.videos.part06.rar</a><br />
<a href="http://rapidshare.com/files/396592405/Drupal.7.videos.part07.rar">http://rapidshare.com/files/396592405/Drupal.7.videos.part07.rar</a><br />
<a href="http://rapidshare.com/files/396592399/Drupal.7.videos.part08.rar">http://rapidshare.com/files/396592399/Drupal.7.videos.part08.rar</a><br />
<a href="http://rapidshare.com/files/396592402/Drupal.7.videos.part09.rar">http://rapidshare.com/files/396592402/Drupal.7.videos.part09.rar</a><br />
<a href="http://rapidshare.com/files/396592412/Drupal.7.videos.part10.rar">http://rapidshare.com/files/396592412/Drupal.7.videos.part10.rar</a><br />
<a href="http://rapidshare.com/files/396592421/Drupal.7.videos.part11.rar">http://rapidshare.com/files/396592421/Drupal.7.videos.part11.rar</a><br />
<a href="http://rapidshare.com/files/396592413/Drupal.7.videos.part12.rar">http://rapidshare.com/files/396592413/Drupal.7.videos.part12.rar</a><br />
<a href="http://rapidshare.com/files/396592404/Drupal.7.videos.part13.rar">http://rapidshare.com/files/396592404/Drupal.7.videos.part13.rar</a><br />
<a href="http://rapidshare.com/files/396592406/Drupal.7.videos.part14.rar">http://rapidshare.com/files/396592406/Drupal.7.videos.part14.rar</a><br />
<br />
<br />
** n.b: If you like this post, then please click on any one of the ad links on the top or side panel. Your small help will encourage me to deliver more useful and good tutorial resources for Drupal in this blog.<br />
<br />
</div>Anish Boralhttp://www.blogger.com/profile/02246041467517915739noreply@blogger.com7