Drupal https://shivanjaikaran.com/ en Composer Memory Problem on Shared Web Hosting https://shivanjaikaran.com/composer-memory-problem-shared-web-hosting <span>Composer Memory Problem on Shared Web Hosting</span> <span><span>admin</span></span> <span>Mon, 08/03/2020 - 04:27</span> <ul class="links inline"><li class="comment-add"><a href="/composer-memory-problem-shared-web-hosting#comment-form" title="Share your thoughts and opinions." hreflang="en">Add new comment</a></li></ul> <div><p>If you are using shared web hosting for your composer managed Drupal website, you have probably ran into the problem of your server running out of memory for simple commands such as "composer install". Shared web hosting usually have memory limits which are shared across many websites.</p> <p>This problem becomes quickly apparent if you are trying to install a new Drupal website into your shared hosting account. Because this is probably the first time that you have to run "composer install" for this website. Composer will then have to go and fetch all the files and download them into your vendor directory. The high memory consumption in composer is mostly due to dependency resolution. This process is memory intensive. The end result is your process is abruptly killed without finishing.</p> <p><strong>Solution</strong></p> <p>A quick and easy solution is to install the site locally whereby you can successfully run "composer install". You would then have the vendor directory locally. Then use a service like FTP to manually upload the vendor folder into the correct directory on your hosting server. Then on your hosting server, try running "composer install" again. </p> <p>At this point, composer would not need to fetch all the files again. Composer may or may not have to update some files in the vendor directory. This is OK. But the process should now be able to complete within your memory limitations.</p> <p>It should be noted that the <a href="https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md" rel="nofollow">vendor directory should <strong>not</strong> be committed to your git directory</a> for a few important reasons. </p> <p>There are arguments for and against committing the vendor directory. It is not technically wrong but there some risks associated with it. The recommendation about not committing /vendor to the git repo is mostly related to avoiding headaches with git submodules (duplicated history, etc). The <a href="https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md" rel="nofollow">composer docs page</a> shows some ways that you can prevent hitting those.</p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> <div><a href="/tag/composer" hreflang="en">composer</a></div> </div> </div> <section class="comments" > <article data-comment-user-id="0" id="comment-1629" class="js-comment comment"> <mark class="hidden" data-comment-timestamp="1596729223"></mark> <div class="comment-side"> <img src="/themes/custom/likable_subtheme/images/avatar.png" /> <div class="comment-submitted"> <p class="comment-name"> <span>Just-passin-thru (not verified)</span> </p> <p class="comment-time"> Thu, 08/06/2020 - 09:35 </p> <p class="comment-permalink"> <a href="/comment/1629#comment-1629" hreflang="en">Permalink</a> </p> </div> </div> <div class="comment-text"> <div class="comment-arrow"></div> <h3><a href="/comment/1629#comment-1629" class="permalink" rel="bookmark" hreflang="en">I&#039;ve used the following to…</a></h3> <div class="content"> <div><p>I've used the following to overcome this issue and it works fine:</p> <p> </p> <p>COMPOSER_MEMORY_LIMIT=-1 composer require ...</p> </div> <div class="sharethis-wrapper"> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1629" class="st_facebook"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1629" class="st_email"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1629" st_title="" class="st_twitter"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1629" st_title="" class="st_sharethis"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1629" st_title="" class="st_print"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1629" st_title="" class="st_fblike"></span> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=1629&amp;1=default&amp;2=en&amp;3=" token="W3tx8Vn9APB2vsZgPQhrFnwuibsRGEdmK2sSkurfj78"></drupal-render-placeholder> </div> </div> </article> <article data-comment-user-id="0" id="comment-1630" class="js-comment comment"> <mark class="hidden" data-comment-timestamp="1600841429"></mark> <div class="comment-side"> <img src="/themes/custom/likable_subtheme/images/avatar.png" /> <div class="comment-submitted"> <p class="comment-name"> <span>Khan Mohammad Nakib (not verified)</span> </p> <p class="comment-time"> Wed, 09/23/2020 - 01:31 </p> <p class="comment-permalink"> <a href="/comment/1630#comment-1630" hreflang="en">Permalink</a> </p> </div> </div> <div class="comment-text"> <div class="comment-arrow"></div> <h3><a href="/comment/1630#comment-1630" class="permalink" rel="bookmark" hreflang="en">Thanks for this. Exactly I…</a></h3> <div class="content"> <div><p>Thanks for this. Exactly I was looking for this.</p> </div> <div class="sharethis-wrapper"> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1630" class="st_facebook"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1630" class="st_email"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1630" st_title="" class="st_twitter"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1630" st_title="" class="st_sharethis"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1630" st_title="" class="st_print"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1630" st_title="" class="st_fblike"></span> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=1630&amp;1=default&amp;2=en&amp;3=" token="Mk69D0wRo-7LMmWcv0DnqHBaG_mUFdll5GHmeneke14"></drupal-render-placeholder> </div> </div> </article> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=62&amp;2=comment_node_page&amp;3=comment_node_page" token="Ppp35F7iUh6pzztRZKLLLcivgmRKGol44_dnlUdGKPk"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> English </div> </div> Mon, 03 Aug 2020 08:27:53 +0000 admin 62 at https://shivanjaikaran.com Add Parallax Nodes from a View to Drupal 8 With ScrollMagic https://shivanjaikaran.com/add-parallax-nodes-view-drupal-8-scrollmagic <span>Add Parallax Nodes from a View to Drupal 8 With ScrollMagic</span> <span><span>admin</span></span> <span>Mon, 01/20/2020 - 06:07</span> <div><p>In this tutorial I will explain how I accomplished taking a listing of nodes that came from a View and created a Parallax effect using the Bootstrap theme from Drupal 8.</p> <p><a href="https://gitlab.com/xamount/parallax-demo" rel="nofollow">The code in this tutorial can be found on GitLab.</a> </p> <p>To use the code in the repos, you can:</p> <ol> <li>Clone the repos locally</li> <li>Run composer install from the root folder</li> <li>Run drush config:import -y </li> </ol> <p>I would like to refer to this article which explains how to <a href="https://www.ostraining.com/blog/drupal/add-parallax-styled-blocks-to-your-drupal-8-theme/" rel="nofollow">Add Parallax Blocks to Drupal 8 With ScrollMagic</a>. I got my ideas and most of the code from there.</p> <p>You will need to have Drupal 8 installed with Views and a <a href="https://www.ostraining.com/blog/drupal/create-a-drupal-8-bootstrap-subtheme-using-cdn/" rel="nofollow">Bootstrap subtheme set up</a>.</p> <p>For this tutorial, I am using a simple Page content type that I created with 3 fields: Title, Body and Background Image.</p> <p>You should then create a View that lists this Page content type. I am listing the Body field and Background Image field in my example. I am keeping my Page content type and View very simple for explanation purposes. But you can set up more complex Views and content types as you wish. You just need at least an image field (or you can place a background image to an existing content type field via CSS as well).</p> <p><strong>Step #1 - Configure the Bootstrap theme</strong></p> <p>Because Parallax effects are usually full width, you should turn on the Fluid container option in the Bootstrap theme menu.</p> <ul> <li>Enter your subtheme Boothstrap theme settings.</li> <li>Under General &gt;&gt; Container check the Fluid container box<img alt="Fluid checkbox" data-entity-type="file" data-entity-uuid="63427687-862f-44c2-8fe0-702819900f19" height="222" src="/sites/default/files/inline-images/fluid.png" width="482" /></li> </ul> <p><strong>Step #2 - Set up your Content Type and Views.</strong></p> <p>Here is my Page content type with 3 fields: Title (not show in in screenshot), Body and Background image</p> <p><img alt="Page content type fields" data-entity-type="file" data-entity-uuid="269a8101-beae-47ef-ba68-a1378278760b" height="215" src="/sites/default/files/inline-images/page_fields.png" width="710" /></p> <p>Here is my View. It's a pretty much standard View which just lists the Page content type and creates a page out of it. I am using the image field here as the background image for the Parallax. You can also use another field (text or whatever) and set a CSS background as the image.</p> <p><img alt="View listing page content types" data-entity-type="file" data-entity-uuid="f18ae1ae-2b92-4dcf-916a-f6bda9a5c76f" height="422" src="/sites/default/files/inline-images/view.png" width="854" /></p> <p>Now create some Page content and go to the View page to see the listing of your content.</p> <p><strong>Step #3 - Style the View using CSS</strong></p> <p>Here is my CSS:</p> <p><code>.view-homepage { </code></p> <p><code>  .views-row { text-align: center; position: relative; overflow: hidden; height: 500px; }</code></p> <p><code>  .views-field-field-background-image { position: absolute; width: 100%; height: 140%; } </code></p> <p><code>  .views-field-body { </code></p> <p><code>    position: relative; top: 50%;<br />     -webkit-transform: translateY(-50%);<br />     -ms-transform: translateY(-50%);<br />     transform: translateY(-50%);<br />     color: #fff;<br />   }<br /> }</code></p> <p><strong>Step #4 - Get the ScrollMagic files</strong></p> <p>Go to <a href="https://github.com/janpaepke/ScrollMagic/" rel="nofollow">Github</a> and download/extract library.</p> <p>Now go to your theme folder and create a folder called /js/ and move these files into the folder</p> <ul> <li>animation.gsap.min.js</li> <li>ScrollMagic.min.js</li> <li>TweenMax.min.js</li> <li>and also manually create a blank parallax.js</li> </ul> <p>You now need to tell the theme to load the js libraries. To do that, open your_theme/your_theme.libraries.yml:</p> <p><code>global-styling:<br />   css:<br />     theme:<br />      css/style.css: {} </code></p> <p><code>  js:<br />     js/ScrollMagic.min.js: {}<br />     js/animation.gsap.min.js: {}<br />     js/TweenMax.min.js: {}<br />     js/parallax.js: {}<br />   dependencies:<br />     - core/drupal<br />     - core/jquery </code></p> <p><strong>Step #5 Add the Parallax JS code to parallax.js</strong></p> <p><code>(function ($) {<br />     'use strict';<br />     Drupal.behaviors.myBehavior = {<br />         attach: function (context, settings) {</code></p> <p><code>            var controller = new ScrollMagic.Controller();</code></p> <p><code>            $('.views-row').each(function (index) {</code></p> <p><code>                var $bg = $(this).find('.views-field-field-background-image');<br />                 var $content = $(this).find('.views-field-body');</code></p> <p><code>                var tl = new TimelineMax();<br />                 tl<br />                     .from($bg, 2, {y: '-40%', ease: Power0.easeNone}, 0)<br />                     .from($content, 1, {autoAlpha: 0, ease: Power0.easeNone}, 0.4)<br />                 ;</code></p> <p><code>                var scene = new ScrollMagic.Scene({<br />                     triggerElement: this,<br />                     triggerHook: 1,<br />                     duration: "100%"<br />                 })<br />                 .setTween(tl)<br />                 .addTo(controller);<br />             });<br />         }<br />     }<br /> }(jQuery));</code></p> <p>Make sure the images you are using are big enough for the max width you want to display.</p> <p>You should now have a nice parallax scrolling effect for each node in the View list.</p> <p><img alt="Parallax example" data-entity-type="file" data-entity-uuid="5edd4b87-6dec-44f9-a919-2c5621bb556c" height="277" src="/sites/default/files/inline-images/parallax.gif" width="705" /></p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/taxonomy/term/81" hreflang="en">Drupal 8</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> <div><a href="/taxonomy/term/82" hreflang="en">CSS</a></div> <div><a href="/taxonomy/term/83" hreflang="en">Parallax</a></div> </div> </div> <section class="comments" > <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=61&amp;2=comment_node_page&amp;3=comment_node_page" token="WMY4_CR3wMHU671RWz9mYD2ti-PIk8em8dGPdokPrrQ"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> English </div> </div> Mon, 20 Jan 2020 10:07:06 +0000 admin 61 at https://shivanjaikaran.com Drupal 8: Composerizing Drupal 8 in 10 Easy Steps https://shivanjaikaran.com/drupal-8-composerizing-drupal-8-10-easy-steps <span>Drupal 8: Composerizing Drupal 8 in 10 Easy Steps</span> <span><span>admin</span></span> <span>Thu, 01/31/2019 - 00:07</span> <div><p dir="ltr">Do you have a Drupal 8 website that you have migrated from Drupal 4 to 5 to 6 to 7 and then to 8 (or anywhere along this timeline)?</p> <p dir="ltr">Do you have a Drupal 8 website that is not managed with Composer? (Maybe you installed the site manually?)</p> <p dir="ltr">If your answer is Yes to any of the above, then this quick guide tutorial is for you. This tutorial will explain in 10 easy and proven steps how to take a Drupal 8 website and get it to be managed under Composer. </p> <p dir="ltr"><a href="https://www.drupal.org/docs/develop/using-composer/using-composer-with-drupal" rel="nofollow">Read how Drupal 8 uses Composer.</a></p> <p dir="ltr">For this tutorial to be effective for you, you must take care of all the Assumptions I mentioned below <strong>BEFORE</strong> you start.</p> <p><strong>Assumptions</strong></p> <ul dir="ltr"> <li>You have a Drupal 8 website and it is under GIT version control (using master branch).</li> <li>You have not hacked core (but if you did note where you did it).</li> <li>You have contrib modules and/or themes in your code base.</li> <li>Any custom module or custom theme is in their usual Drupal folder (for e.g. drupal_root/modules/custom_module OR drupal_root/themes/custom_theme)</li> <li>You have updated all Drupal core, contributed modules and themes to their latest stable version. (This is important for Step 6 to go smoothly)</li> <li>For this tutorial code base means your Drupal root directory</li> </ul> <p><figure role="group"> <img alt="my current codebase" data-entity-type="file" data-entity-uuid="2aed7e8e-dd95-44c5-a56c-137343a96786" height="73" src="/sites/default/files/inline-images/Figure%201.png" width="702" /> <figcaption><em>My current code base looks like this.</em></figcaption> </figure> </p> <p> </p> <p><strong>Step 1</strong></p> <p dir="ltr">Backup the following folders:</p> <ul> <li dir="ltr"> <p dir="ltr">your public files folder</p> </li> <li dir="ltr"> <p dir="ltr">database</p> </li> </ul> <p dir="ltr">Do not worry about the rest of your code base because it is under version control.</p> <p dir="ltr"> </p> <p dir="ltr"><strong>Step 2</strong></p> <p dir="ltr">Git clone your code base locally and create a new branch off your master branch (or whatever branch your live repos sits on).</p> <p dir="ltr">Commands</p> <p dir="ltr"><code>git clone &lt;your git repo &gt;</code></p> <p dir="ltr"><code>Now change directory into your newly cloned git repos.</code></p> <p dir="ltr"><code>git checkout -b composerize-drupal master</code></p> <p dir="ltr">composerize-drupal is just the name of the branch we will be working in for this tutorial so we don't mess with our master branch. Once we are successful, we will merge this branch back into master.</p> <p dir="ltr"> </p> <p dir="ltr"><strong>Step 3</strong></p> <p dir="ltr">Note down the names of the contributed modules/themes that you currently use. It is ok to skip this step because your git version control (master branch) will have these folders still so you can refer to it from there through the git web interface.</p> <p dir="ltr">But here are the Drush commands if you wish to do it this way:</p> <p dir="ltr">To list all the contributed module: <code>drush pm-list --type=Module --no-core --status=enabled</code></p> <p dir="ltr">To list all the contributed themes: <code>drush pm-list --type=Theme --no-core --status=enabled</code></p> <p>If you hacked core or made custom patches, note down where these hacks/patches are in your codebase (again it should be viewable in your git interface in the master branch so you do not need to actually write this down)</p> <p> </p> <p><strong>Step 4</strong></p> <p>In your local branch , delete everything including all the files that begin with “.” (dot) from your Drupal root EXCEPT the .git folder. So now your code base should only have the .git folder.</p> <p dir="ltr">Now you can stage and commit this change to the current branch composer-drupal:</p> <p dir="ltr"><code>git add -A</code></p> <p dir="ltr"><code>git commit -m "Remove all files and folders except .git"</code></p> <p dir="ltr"> </p> <p dir="ltr"><strong>Step 5</strong></p> <p dir="ltr">Install a new version of Drupal using Composer:</p> <p dir="ltr"><code>composer create-project drupal-composer/drupal-project:8.x-dev composerized-drupal --no-interaction</code></p> <p>The name of the folder that composer will install Drupal too is composerized-drupal.</p> <p dir="ltr">Now you need to move <strong>ALL</strong> of the files and folders from the folder composerized-drupal into the root of your original code base hence consequently leaving the composerized-drupal folder empty. Don't forget to move all the files that begin with a dot.</p> <p dir="ltr">So from your code base root:</p> <p dir="ltr"><code>mv composerized-drupal/* ./</code></p> <p dir="ltr"><code>mv composerized-drupal/.* ./</code></p> <p dir="ltr"><code>rm -rf composerized-drupal</code></p> <p dir="ltr">Now your code base should have the default Drupal composer files like Figure 2.</p> <p><figure role="group"> <img alt="Figure 2" data-entity-type="file" data-entity-uuid="49fab089-6d6f-4523-8660-d10bde423d91" height="51" src="/sites/default/files/inline-images/Figure%202.png" width="692" /> <figcaption><em>Figure 2</em></figcaption> </figure> </p> <p>Now it’s a good time to commit these changes.</p> <p dir="ltr"><code>git add -A</code></p> <p dir="ltr"><code>git commit -m "Added default Drupal composer files"</code></p> <p dir="ltr"> </p> <p dir="ltr"><strong>Step 6</strong></p> <p dir="ltr">For each contributed module, theme or profile from your old site you need to add it to the current code base by using composer such as:</p> <p dir="ltr"><code>composer require drupal/adsense drupal/backup_migrate drupal/codefilter drupal/ctools drupal/insert drupal/pathauto drupal/rules drupal/sharethis drupal/tagadelic drupal/token drupal/typed_data</code></p> <p dir="ltr">Composer will then fetch the latest stable release and put it in the correct directory automatically.</p> <p dir="ltr">Now it’s a good time to stage and commit your changes.</p> <p dir="ltr"><code>git add -A</code></p> <p dir="ltr"><code>git commit -m "Add contrib projects to the codebase."</code></p> <p> </p> <p dir="ltr"><strong>Step 7</strong></p> <p dir="ltr">For any of your custom code:</p> <ul> <li dir="ltr"> <p dir="ltr">Place modules in drupal_root/web/modules/custom/</p> </li> <li dir="ltr"> <p dir="ltr">Place themes in drupal_root/web/themes/custom/</p> </li> <li dir="ltr"> <p dir="ltr">Place profiles in drupal_root/web/profiles/custom/</p> </li> </ul> <p dir="ltr"><a href="https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies#third-party-libraries" rel="nofollow">Visit this link if you use 3rd party libraries.</a></p> <p dir="ltr">If you made customizations to .htaccess or robots.txt, <a href="https://drupal.stackexchange.com/questions/222898/composer-updates-htaccess-file-when-updating" rel="nofollow">here is how to apply those changes in a composer managed Drupal site.</a> (Don't forget to commit your changes to composer.json)</p> <p dir="ltr"><a href="https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies#patches" rel="nofollow">If you patched core, contributed modules or themes see this link to patch with composer.</a></p> <p dir="ltr">NB - Do not just randomly add your customizations in without letting composer know about it. If you do this, your changes will be lost next time you run composer install or composer update.</p> <p dir="ltr"> </p> <p dir="ltr"><strong>Step 8</strong></p> <p dir="ltr">TEST, TEST, TEST!</p> <p dir="ltr">Restore a copy of the LIVE database to your local machine and visit the URL of the local site in your browser.</p> <p dir="ltr">Drupal will automatically go to the install step. Follow through with the process and fix any errors along the way.</p> <p dir="ltr">Clear the cache: <code>drush cr</code></p> <p dir="ltr">You may have to find <a href="//drupalize.me/tutorial/clear-drupals-cache?p=2512" rel="nofollow">other ways to clear Drupal cache if Drush does not work</a> at this point.</p> <p dir="ltr">Check the status reports and click around the site. Any errors you find, fix it and commit it.</p> <p dir="ltr">The status page may have Drupal updates to the database available. Update the Drupal database if you need too.</p> <p dir="ltr">Usually I visit admin/config/media/file-system to double check the public and private folder paths are set correctly.</p> <p dir="ltr">NB - your custom files folder will be missing from your code base at this point. You can copy the files folder locally to drupal_root/web/sites/default/files if you need it for testing purposes but this will be taken care of in Step 10 on the LIVE site.</p> <p dir="ltr">At the end of this step, drush status and drush cr should return clean results with no errors.</p> <p dir="ltr"> </p> <p dir="ltr"><strong>Step 9</strong></p> <p dir="ltr">This is the big step where you push the changes up to the master branch.</p> <p dir="ltr">So push your changes up: <code>git push -u origin composerize-drupal</code></p> <p dir="ltr">Now we want to merge our composer branch into master:</p> <p dir="ltr"><code>git checkout master</code></p> <p dir="ltr"><code>git merge --no-ff composerize-drupal</code></p> <p dir="ltr">Delete the composer branch as we no longer need it:</p> <p dir="ltr"><code>git branch -d composerize-drupal</code></p> <p dir="ltr">Push the changes up:</p> <p dir="ltr"><code>git push -u origin master</code></p> <p dir="ltr"> </p> <p dir="ltr"><strong>Step 10</strong></p> <p dir="ltr">Now we need to pull in the changes on your LIVE server. Your LIVE site will be down for a few minutes in this step so you should do this at an off-peak time. In the event that something drastically goes wrong, you would need to revert the commit with the merge and restore your database and files folder.</p> <p dir="ltr">On LIVE:</p> <p dir="ltr">Change your Webserver document root to point to code_base/web since composer would have placed all the Drupal files into a sub directory named “web.” This is a very important step.</p> <p dir="ltr">Then</p> <p dir="ltr"><code>git pull</code></p> <p dir="ltr"><code>composer install --no-dev</code></p> <p dir="ltr">After running the above command, if you had previously made customizations to core, contrib modules or contrib themes, and you didn't tell composer about it, they will be lost like I said in Step 7.</p> <p dir="ltr">At this point you may notice your original sites folder is still at code_base/sites. You can delete the folder completely because the web/sites folder will be in use now.</p> <p dir="ltr">Copy your custom files folder to code_base/web/sites/default/files</p> <p dir="ltr">Now visit your site and repeat Step 8 (except restoring a copy of the LIVE database to your local as you would be on LIVE now).</p> <hr /> <p>I hope this tutorial is helpful to you. You can leave a comment if you had any edge cases and the solutions that you found.</p> <p> </p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/taxonomy/term/81" hreflang="en">Drupal 8</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=60&amp;2=comment_node_page&amp;3=comment_node_page" token="j_G5IjZ4lvOBntfFr8wEXp-I0qP1oh7N4zalUMmuD8Y"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> English </div> </div> Thu, 31 Jan 2019 04:07:22 +0000 admin 60 at https://shivanjaikaran.com Drupal 8: How to render your custom theme images with image styles in your Twig template https://shivanjaikaran.com/drupal-8-how-render-your-custom-theme-images-image-styles-your-twig-template <span>Drupal 8: How to render your custom theme images with image styles in your Twig template</span> <span><span>admin</span></span> <span>Thu, 01/03/2019 - 07:03</span> <div><p>In this article we are going to look at how we can render custom images using image styles in your Twig template in Drupal 8. By custom images, I mean images that originate from a custom module/theme (not an image originating from a field entity/node). In other words, the image would not even exist in "public://your-image.png" but rather it might exist somewhere in your custom module or theme.</p> <p>In YOUR_THEME.theme file, put at the top:</p> <p><strong>use Drupal\image\Entity\ImageStyle;</strong></p> <p>Then, depending on which Twig template you want to use the image style, you need to create the appropriate preprocess function. In this example, let's use theme_preprocess_page</p> <p>So in YOUR_THEME_preprocess_page:</p> <p><strong>function YOUR_THEME_preprocess_page(array &amp;$variables) {</strong></p> <p><strong>  $style = ImageStyle::load('custom_style');</strong></p> <p><strong>  $variables['rounded_image'] = $style-&gt;buildUrl(drupal_get_path('theme', 'YOUR_THEME').'/images/your_image.png');</strong></p> <p><strong>}</strong></p> <p>Then in your Twig template (for e.g page.html.twig):</p> <p><strong>&lt;img src = "{{ rounded_image }}" /&gt;</strong></p> <p> </p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=56&amp;2=comment_node_page&amp;3=comment_node_page" token="WKU2Gw7Er8RTZ8FGUQjm1pouxTBHaEwy7z_m90_WEhU"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> English </div> </div> Thu, 03 Jan 2019 11:03:11 +0000 admin 56 at https://shivanjaikaran.com Upgrading from Drupal 5 to 7 and the XML Sitemap Module https://shivanjaikaran.com/upgrading-drupal-5-7-and-xml-sitemap-module <span>Upgrading from Drupal 5 to 7 and the XML Sitemap Module</span> <span><span>admin</span></span> <span>Tue, 12/17/2013 - 03:26</span> <div><p>After months of deliberation and procrastination, I have finally found the time to upgrade my own website. It's now running on Drupal 7. I decided to change the theme and keep it simple. A neat layout and also mobile friendly theme is what I was aiming for. Thanks to the many contributors at Drupal, finding a user contributed simple and clean theme was not very hard at all. The hardest part of this upgrade was the <a href="http://drupal.org/project/xmlsitemap" rel="nofollow">XML Sitemap</a> module.</p> <p>Because I went straight from Drupal 5 to Drupal 7, there were some extra steps I had to take to get this module to work. The upgrade path for this module was not a straight forward one however. I must say that I did follow the module's instructions for this upgrade in which they said "If you're upgrading from version 5 to version 7, please use the 5.x-1.7 to 6.x-1.x to 6.x-2.x to 7.x-2.0-rc1 path." This led to me having the latest stable module, but every time I go to the config page for the module I was given a notice error. Even trying to uninstall the module was somewhat impossible. So I was basically stuck with an installed XML sitemap module that I could not uninstall nor use. This seems to be a pretty common problem with this module.</p> <p><strong>The Solution</strong></p> <p>Before you do anything of this nature, it goes without saying that you should BACKUP YOUR DATABASE. I resorted to manually deleting the module's tables and variables from the database. To do this I used PHPMyAdmin and deleted all tables that started with xmlsitemap. I also did the same for each row in the variables table for all variables LIKE %xmlsitemap%. A little dirty hack ain't it? After doing this, I was then able to uninstall the module within the admin interface. Now, finally I could install the module as a fresh install. I know this is not ideal but fortunately, this module does not store a lot of information so I could have afforded to loose that for a fresh install. I hope this post will save someone else from chasing shadows in debugging this problem.</p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/tag/drupal-7" hreflang="en">Drupal 7</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=52&amp;2=comment_node_page&amp;3=comment_node_page" token="tuhQvNM4FpALn8Tm0QxpjjwNLx-mHHUsoIq2dRl2NiA"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Tue, 17 Dec 2013 07:26:51 +0000 admin 52 at https://shivanjaikaran.com Annoying Drupal 5/6 problem. Can't sign in even if your username/password is correct. https://shivanjaikaran.com/annoying-drupal-56-problem-cant-sign-even-if-your-usernamepassword-correct <span>Annoying Drupal 5/6 problem. Can&#039;t sign in even if your username/password is correct.</span> <span><span>admin</span></span> <span>Tue, 12/03/2013 - 14:26</span> <div><p>If you still happen to be maintaining a Drupal 5 or 6 website for a client you may encounter this problem of getting access denied even though you correctly entering the right username and password.</p> <p>The first place to check, (and this is the most common solution), is to check the Sessions table in your mySQL database. Try repairing this table and that should do the trick. An easy way to do this is to use PHPMyAdmin.</p> <p>In PHPMyAdmin, choose your Drupal database, check the box next to the Sessions table, and find the "With selected" drop-down near the bottom of the page. Choose "Repair table".</p> <p>If repairing the Sessions table via PHPMyAdmin doesn't work, you can truncate the Sessions table. The repercussion of this being that all your users will have to log in again.</p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=51&amp;2=comment_node_page&amp;3=comment_node_page" token="agKaqBFkbKDIfQMNHG7Fikha0UxRDDLcp6GS8hRNWDo"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Tue, 03 Dec 2013 18:26:13 +0000 admin 51 at https://shivanjaikaran.com Drupal 7: How to add a custom CSS class to the last search result item on the search page https://shivanjaikaran.com/drupal-7-how-add-custom-css-class-last-search-result-item-search-page <span>Drupal 7: How to add a custom CSS class to the last search result item on the search page</span> <span><span>admin</span></span> <span>Wed, 11/14/2012 - 13:53</span> <ul class="links inline"><li class="comment-add"><a href="/drupal-7-how-add-custom-css-class-last-search-result-item-search-page#comment-form" title="Share your thoughts and opinions." hreflang="und">Add new comment</a></li></ul> <div><p>This is a small tidbit of information in the event that you wanted to alter the Drupal search results page. You can add a custom CSS class to the last search result item (for whatever reason you may have). In my case, I wanted to remove the border-bottom from the last result, so I had to add a special CSS class to do this. Just follow these simple steps:</p> <ol> <li>Override <a href="http://api.drupal.org/api/drupal/modules!search!search.pages.inc/function/template_preprocess_search_results/7" rel="nofollow">template_preprocess_search_results</a> Here is how to alter the code. This goes in your template.php: <code> function yourthemename_preprocess_search_results(&amp;$variables) { $variables['search_results'] = ''; if (!empty($variables['module'])) { $variables['module'] = check_plain($variables['module']); } //checking the total number of results $num_results = count($variables['results']); $counter = 0; foreach ($variables['results'] as $result) { $counter++; if ($num_results == $counter) { //means we have the last result so we add the class $variables['search_results'] .= theme('search_result', array('result' =&gt; $result, 'module' =&gt; $variables['module'], 'last' =&gt; 'last')); } else { $variables['search_results'] .= theme('search_result', array('result' =&gt; $result, 'module' =&gt; $variables['module'])); } } $variables['pager'] = theme('pager', array('tags' =&gt; NULL)); $variables['theme_hook_suggestions'][] = 'search_results__' . $variables['module']; } </code></li> <li>Now we override <a href="http://api.drupal.org/api/drupal/modules!search!search-result.tpl.php/7" rel="nofollow">search-result.tpl.php</a> Create this file and put it in your custom theme folder.</li> <li><code>"&lt;?php print $attributes; ?&gt;&gt; &lt;?php print render($title_prefix); ?&gt; </code> <p><code>&gt; <a rel="nofollow">"&gt;&lt;?php print $title; ?&gt;</a> </code></p> <p> <code> &lt;?php print render($title_suffix); ?&gt; </code><code>&lt;?php if ($snippet): ?&gt; </code></p> <p><code>&gt;&lt;?php print $snippet; ?&gt;</code></p> <p> <code> &lt;?php endif; ?&gt; &lt;?php if ($info): ?&gt; </code></p> <p><code>&lt;?php print $info; ?&gt;</code></p> <p> <code> &lt;?php endif; ?&gt; </code><code> </code></p></li> <li>Clear your cache</li> </ol> <p>Now if you search for something, you will notice that your very last search result has the CSS class of "last". This also works for search results that have a pager. That is, the last result on every page will have the class of "last".</p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/tag/drupal-7" hreflang="en">Drupal 7</a></div> <div><a href="/tag/search" hreflang="en">search</a></div> <div><a href="/tag/tutorial" hreflang="en">tutorial</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <article data-comment-user-id="0" id="comment-1607" class="js-comment comment"> <mark class="hidden" data-comment-timestamp="1567354953"></mark> <div class="comment-side"> <img src="/themes/custom/likable_subtheme/images/avatar.png" /> <div class="comment-submitted"> <p class="comment-name"> <span>johnybravo123 (not verified)</span> </p> <p class="comment-time"> Sun, 09/01/2019 - 12:07 </p> <p class="comment-permalink"> <a href="/comment/1607#comment-1607" hreflang="en">Permalink</a> </p> </div> </div> <div class="comment-text"> <div class="comment-arrow"></div> <h3><a href="/comment/1607#comment-1607" class="permalink" rel="bookmark" hreflang="en">Thanks for Sharing....!!</a></h3> <div class="content"> <div><p>Thanks for Sharing....!!</p> </div> <div class="sharethis-wrapper"> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1607" class="st_facebook"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1607" class="st_email"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1607" st_title="" class="st_twitter"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1607" st_title="" class="st_sharethis"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1607" st_title="" class="st_print"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1607" st_title="" class="st_fblike"></span> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=1607&amp;1=default&amp;2=en&amp;3=" token="_YNqD4JBYkBZ2GmpdVsqxjJhgo4b7CsLHrzlGeA5eqQ"></drupal-render-placeholder> </div> </div> </article> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=50&amp;2=comment_node_page&amp;3=comment_node_page" token="ApDbkPDuzm4sAIjju5T7a0FpK23QAQ3xpyKXVp7CfGo"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Wed, 14 Nov 2012 17:53:23 +0000 admin 50 at https://shivanjaikaran.com Drupal 7: How to add a custom node view and force a node template to use it https://shivanjaikaran.com/drupal-7-how-add-custom-node-view-and-force-node-template-use-it <span>Drupal 7: How to add a custom node view and force a node template to use it</span> <span><span>admin</span></span> <span>Mon, 10/15/2012 - 15:11</span> <ul class="links inline"><li class="comment-add"><a href="/drupal-7-how-add-custom-node-view-and-force-node-template-use-it#comment-form" title="Share your thoughts and opinions." hreflang="und">Add new comment</a></li></ul> <div><p>This is a small Drupal 7 tip if you wanted to create a custom node view and force a node template to use this custom node view.</p> <p><strong>Use case</strong></p> <p>Let's say you are creating a custom node template for a node of type "grades". You may need to show/hide specific fields in your content type for your Grades template. (This is just an example but you can use this tip in various ways).</p> <p><strong>The Steps</strong></p> <ol> <li>You can create a new view mode by putting this code into your custom module:</li> <li> <code><br /> /** * Implements hook_entity_info_alter(). */<br /> function MYMODULE_entity_info_alter(&amp;$entity_info) { $entity_info['node']['view modes']['custom_teaser'] = array( 'label' =&gt; t('Your Custom Teaser'), 'custom settings' =&gt; TRUE, ); } </code></li> <li>Then go to Manage Displays in your content type and set which fields you want to show/hide in the "Your Custom Teaser" view mode.</li> <li>Now you have to force the viewing of your node to use this custom node view "Your Cusom Teaser". Put this code into your custom module: <code> function MYMODULE_preprocess_node(&amp;$variables) { if ($variables['elements']['#view_mode'] == 'custom_teaser') { $variables['theme_hook_suggestions'][] = "node__grades"; } } </code><br /> This will force the viewing of your custom content type "grades" to use grade.tpl.php</li> </ol> <p><strong>Further Reading</strong> Here is how you would make a <a href="http://mearra.com/blogs/juha-niemi/drupal-7-custom-node-view-modes" rel="nofollow">View use your custom node view for Drupal 7</a>.</p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/tag/drupal-7" hreflang="en">Drupal 7</a></div> <div><a href="/tag/tip" hreflang="en">tip</a></div> <div><a href="/tag/custom" hreflang="en">custom</a></div> <div><a href="/tag/node" hreflang="en">node</a></div> <div><a href="/tag/view" hreflang="en">view</a></div> <div><a href="/tag/modes" hreflang="en">modes</a></div> <div><a href="/tag/template" hreflang="en">template</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <article data-comment-user-id="0" id="comment-1603" class="js-comment comment"> <mark class="hidden" data-comment-timestamp="1350339840"></mark> <div class="comment-side"> <img src="/themes/custom/likable_subtheme/images/avatar.png" /> <div class="comment-submitted"> <p class="comment-name"> <span>Anonymous (not verified)</span> </p> <p class="comment-time"> Mon, 10/15/2012 - 18:24 </p> <p class="comment-permalink"> <a href="/comment/1603#comment-1603" hreflang="en">Permalink</a> </p> </div> </div> <div class="comment-text"> <div class="comment-arrow"></div> <h3><a href="/comment/1603#comment-1603" class="permalink" rel="bookmark" hreflang="en">Found this module to be</a></h3> <div class="content"> <div><p>Found this module to be useful : <a href="http://drupal.org/project/view_mode_templates">http://drupal.org/project/view_mode_templates</a></p> </div> <div class="sharethis-wrapper"> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1603" class="st_facebook"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1603" class="st_email"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1603" st_title="" class="st_twitter"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1603" st_title="" class="st_sharethis"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1603" st_title="" class="st_print"></span> <span st_url="https://shivanjaikaran.com/taxonomy/term/8/feed#comment-1603" st_title="" class="st_fblike"></span> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=1603&amp;1=default&amp;2=en&amp;3=" token="OOUWIC9pKVbIpeRj6cOVEKEnbR2N_VUX8NUiJcTYdQA"></drupal-render-placeholder> </div> </div> </article> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=49&amp;2=comment_node_page&amp;3=comment_node_page" token="7k3Z2bSnx3W_9A9KojC5vjZrabC_7lLGPxtiAQeUmxo"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Mon, 15 Oct 2012 19:11:36 +0000 admin 49 at https://shivanjaikaran.com Trinidad Guardian's Main Stage launched using Drupal! https://shivanjaikaran.com/trinidad-guardians-main-stage-launched-using-drupal <span>Trinidad Guardian&#039;s Main Stage launched using Drupal!</span> <span><span>admin</span></span> <span>Thu, 02/04/2010 - 02:39</span> <div><p><a href="http://mainstage.guardian.co.tt" rel="nofollow"><img alt="Main Stage" src="/sites/default/files/Screenshot_2_0.png" title="Main Stage" /></a> A few days ago, the <a href="http://mainstage.guardian.co.tt" rel="nofollow">Trinidad Guardian's Main Stage</a> was launched. Without a doubt, the website runs on the very powerful cutting edge content management system, <a href="http//drupal.org" rel="nofollow">Drupal 6.</a> The design was done in-house at The Guardian (provided as a template) and some features used are the jQuery powered photo galleries. A gallery is considered a "node" which can contain multiple images, all of which are seamlessly uploaded through the web interface of the same website. The website also showcases the use of the <a href="http://drupal.org/project/event" rel="nofollow">Event module</a> which will contain Fete information for this Carnival period. A simple yet powerful website, contenting among the rest of gallery-powered website already existing in Trinidad and Tobago. A few theme improvements are still pending at the time of writing this article. This website was developed in about two (2) weeks by <a href="https://logontt.com" rel="nofollow">Log On Ltd, the leading provider of Drupal powered websites in Trinidad and Tobago.</a></p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> <div><a href="/tag/carnival" hreflang="en">carnival</a></div> <div><a href="/tag/trinidad-guardian" hreflang="en">Trinidad Guardian</a></div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/tag/drupal-sites" hreflang="en">Drupal sites</a></div> </div> </div> <section class="comments" > <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=40&amp;2=comment_node_page&amp;3=comment_node_page" token="GvOJ9Hoc0CU4K4wRyL2vdtD3ZceGxhQK9Bn5czoUGUc"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Thu, 04 Feb 2010 06:39:33 +0000 admin 40 at https://shivanjaikaran.com Leveraging the Drupal Content Management System https://shivanjaikaran.com/leveraging-drupal-content-management-system <span>Leveraging the Drupal Content Management System</span> <span><span>admin</span></span> <span>Sun, 10/04/2009 - 00:09</span> <div><p>This is my presentation for the event: "Building with Open Source: For Developers", and was presented today for the <a href="http://www.ttcsweb.org/articles/sfd/index.htm" rel="nofollow">Trinidad and Tobago Computer Society Software Freedom Day events</a>. Comments and questions are welcome. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. It is available in the OpenOffice format (naturally) and as a pdf. I apologize for not being able to finish the presentation on time. One hour is just too little to get me going on about Drupal. :) <a href="https://www.shivanjaikaran.com/sites/default/files/ttcs_drupal_presentation.odp" rel="nofollow">ttcs_drupal_presentation.odp</a> [ 4.9 MB ] <a href="https://www.shivanjaikaran.com/sites/default/files/ttcs_drupal_presentation.pdf" rel="nofollow">ttcs_drupal_presentation.pdf</a> [ 3.2 MB ] </p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> <div><a href="/tag/foss" hreflang="en">foss</a></div> <div><a href="/tag/open-source" hreflang="en">open source</a></div> <div><a href="/tag/software-freedom-day" hreflang="en">software freedom day</a></div> <div><a href="/tag/ttcs" hreflang="en">ttcs</a></div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> </div> </div> <section class="comments" > <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=37&amp;2=comment_node_page&amp;3=comment_node_page" token="H9H4RV3B2Za-df6Bmxd8tJ_HX_Taos3vtOGJ2B68OZs"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Sun, 04 Oct 2009 04:09:24 +0000 admin 37 at https://shivanjaikaran.com