Latest posts

Browse topics

Drupal Display Suite Two Columns on User Edit Forms + Image Widget Default Image

<p>Working on a customers project I faced another interesting obstacle (s):</p><ul><li>First to have separate User Admin and User Profile pages</li><li>Second - on user edit pages to display fields on two columns (according to the design).</li></ul><p>So here arises two problems:</p><p><strong>First how to have 2 user profiles and how to style them</strong></p><p>My first approach for two user profiles was using Profiles 2 modules - &nbsp;I must admit - I'm not a huge fan of using such scenarios - they broke - and so did happened this time:</p><p>I did setup a Profile 2 user fields, worked with field permission, &nbsp;like when to hide some of the required fields on user register form.</p><p>So fare everything great -</p><p><strong>but now arises second problem - how to display fields from form in two columns.&nbsp;</strong></p><p>In short - answer comes from <a href="https://www.drupal.org/project/ds">Display Suite Module</a> which allows us to style forms as we wish, but it doesn't integrate well on Profile 2 edit forms.</p><p>So after couple of hours of investigation - I found a small but brilliant module to replace Profile 2 -<a href="https://www.drupal.org/project/edit_profile"&gt; Edit Profile Module</a></p><p>&nbsp;</p><h2>Edit Profile</h2><p>This module creates separate "Edit account" and "Edit profile" tabs for each user, with custom user fields configured under "Edit profile."</p><p>The goal of the module is to make fields attached to users (a new feature introduced in Drupal 7 core) a reasonable option for building simple, clean user profiles. Instead of having all properties of the user account editable via a single "Edit" tab (as Drupal does by default), where custom user profile fields are mixed in with account settings such as username, password, and time zone, sites using this module get a clean separation between these two different concepts, and a nicer experience for their end users.</p><p><strong>Now - once we have Edit Profile module enabled we can get rid of Profile 2 module completely</strong></p><p>Just add new fields to existing user account page (I used existing fields options not to break things up)</p><h2>Now it's time for Display Suite module</h2><p>Display Suite allows you to take full control over how your content is displayed using a drag and drop interface. Arrange your nodes, views, comments, user data etc. the way you want without having to work your way through dozens of template files. A predefined list of layouts (D7 only) is available for even more drag and drop fun!</p><p>By defining custom view modes (build modes in D6), you can define how one piece of content should be displayed in different places such as teaser lists, search results, the full node, views etc.</p><p><img src="http://www.reinisfischer.com/sites/default/files/ds.jpg&quot; alt="Drupal Display Suites edit form" title="Drupal Display Suites edit form" width="1200" height="563"></p><p><em>Drupal Display Suites edit form</em></p><p>When enabled Display Suites module head to configuration options and choose for you are interested in (in this case user - manage form)</p><p>You will have many options to choose from how to display your from - in my case I chose Two Column layout</p><p>Here is the final result of user/edit form</p><p><img src="http://www.reinisfischer.com/sites/default/files/user-edit-ds.jpg&quot; alt="User edit form DS" title="User edit form DS" width="751" height="427"></p><p><em>User edit form DS</em></p><p><span style="font-size: 1.385em; font-weight: bold; line-height: 1.538em;">Bonus - Display default image on forms</span></p><p>This is a little <a href="https://www.drupal.org/project/image_widget_default_image">utility module</a> that shows the default image of an image field as part of the image widget, if no image has been uploaded yet. It is displayed in the same way that the image preview of images that have been uploaded is displayed.</p><p>The display logic is identical to that of the image formatter: If the field instance has defined a default image, that is displayed. Else, if the field has defined a default image, that is displayed. Else no image is displayed, just like without this module.</p><p>The module does not come with any configuration or permissions.</p>

Facebook Login Button For a Drupal website

<p>So - another request come from a client - to add a Facebook login button for a Drupal website.</p><p>As for a start it might sound like easy to handle a task - I spent about a week to figure out the best possible solution for this.&nbsp;</p><p>At first we must understand what does - <strong>Facebook login button stands for</strong>?</p><p><em>Is it for user mapping - is it getting some fields from users Facebook's profile?</em></p><p>Anyway - I found 3 possible implementations on Drupal Module's world:</p><ul><li><a href="https://www.drupal.org/project/simple_fb_connect">Simple FB connect</a></li><li><a href="https://www.drupal.org/project/fboauth">FB Oauth</a></li><li><a href="https://www.drupal.org/project/fb">FB</a></li></ul><p>Now let's break each and everyone down:</p><p><em>Simple FB connect seems the easiest one to install and setup:</em></p><h2>Simple FB connect</h2><p>Simple FB Connect is a Facebook Connect LOGIN/REGISTRATION for Drupal Sites</p><p><strong>What does this module do?</strong></p><ul><li>Allow users to register with FB, their profile pic can be synced to their Drupal account&nbsp;</li><li>Allow users to login with FB</li></ul><p><strong>How it works:</strong></p><p>User can click on the "Register / Login with FB" tab on the user login page You can add a button or link anywhere on the site that points to /user/simple-fb-connect. So theming and customizing the button or link is very flexible.</p><p>When the user opens the url /user/simple-fb-connect link, it automatically takes user to Facebook and asks for his permission. Once granted the module checks the users email. If the email address is found on the Drupal Site, he is logged in automatically. Otherwise a new user account is created with the email address and the user is logged in.</p><p><strong>Sounds like a great module - i actually installed and used it - didn't like &nbsp;that couldn't find an easy way to implement Facebook connect button on Ajax Popup form, don't like the path for user linking - /user/simple-fb-connect</strong></p><h1 id="page-subtitle">Facebook OAuth (FBOAuth)</h1><p>Now - this module, brought to us by Lullabot seemed like the one I need - it gives a plenty of flexibility:</p><p>This module provides authentication services and an API to perform actions against Facebook. This module allows users to login to Drupal through the service commonly known as "Facebook Connect". This module is built with simplicity and flexibility in mind, it provides login services (and does it well), and an API for performing any other actions you may want to write yourself to query against Facebook's APIs.</p><p><strong>Features:</strong></p><ul><li>One-click login through Facebook.</li><li>Automatic import of user e-mail and profile information during initial login.</li><li>Integration with Profile module to map Facebook data to Profile fields. (Drupal 6)</li><li>Integration with Field module to map Facebook data to fields on users. (Drupal 7<span style="line-height: 1.538em;">) </span></li><li><span style="line-height: 1.538em;">A flexible and direct API for modules to get authenticated and query Facebook's APIs (plus extensive documentation).</span></li><li><span style="line-height: 1.538em;"> Extensive permission settings for Facebook data retrieval. </span></li><li><span style="line-height: 1.538em;">The ability to de-authenticate or unlink a Facebook account from a Drupal account.</span></li><li><span style="line-height: 1.538em;"> Does not require any external libraries or downloads.</span></li><li><a href="http://drupal.org/project/fboauth_profile2&quot; rel="nofollow">Facebook OAuth Profile2 Integration</a>:&nbsp;</li></ul><p><span style="line-height: 1.538em;">If you use Profile2 for user profiles, this lets FBOAuth populate Profile2 fields.</span></p><p><strong>This module seemed the most promising - it gives Oauth Profile2 integration, field mapping and more.</strong></p><p><strong>The problem? It has not been updated since 2012 - and I jut couldn't get it work - mainly because of changes in Facebook API</strong></p><h2>Drupal for Facebook</h2><p>I found a solution in this module, although it offers much more we actually need on our site - and it might be a little heavy to keep such a module, just to handle a simple Facebook login/register option. But it works perfectly fine.</p><p>This set of modules turns Drupal into a platform for developing&nbsp;Facebook Applications. This allows you to embed your content and features within facebook, or allow facebook users onto your site via&nbsp;<a href="https://developers.facebook.com/docs/guides/web/#login&quot; rel="nofollow">Facebook Connect</a>.</p><p>With&nbsp;<a href="http://www.drupalforfacebook.org/&quot; rel="nofollow">Drupal for Facebook</a>, you can harness all the power of&nbsp;<a href="http://www.drupal.org/&quot; rel="nofollow">Drupal</a>&nbsp;in you Facebook App. If you already have content in Drupal, you can expose it on&nbsp;<a href="http://www.facebook.com/&quot; rel="nofollow">Facebook</a>.</p><p>The Drupal for Facebook philosophy is that the functionality already built into Drupal should be used to create Facebook Applications. Where possible, we use Drupal's user management, permission schemes, blocks, views, etc. to implement the Facebook App. Experienced Drupal users will find it very straightforward to build a Facebook App. Facebook developers new to Drupal should spend some time browsing Drupal.org to learn best practices.</p><p><em>Drupal for Facebook</em>&nbsp;contains several sub-modules. Enable just those that you need. For example if you need Social Plugins, enable just fb.module. For Facebook Connect, enable&nbsp;<code>fb_connect.module</code>; Canvas Pages,&nbsp;<code>fb_canvas.module</code>; wall posts and status updates, the&nbsp;<code>fb_stream.module</code>; and so on...</p><p>&nbsp;</p><h2>Bonus - How to change Facebook login image in Drupal for Facebook module</h2><p>Yeah - I hear you &nbsp;- the pain with default Facebook login button - I spent couple of hours to figure this as well.</p><p>Found solution to make a changes directly in Drupal for Facebook module fb.theme.inc file</p><p>Line: 77</p><p>Change:</p><pre> // No text, use default image.<br> $markup = '&lt;div class="fb_login_button_wrapper"&gt;&lt;a href="#" onclick="FB.login(function(){}, {scope : \'' . $scope . '\'}); return false;"&gt;&lt;span&gt;&lt;img src="//www.facebook.com/images/fbconnect/login-buttons/connect_light_medium_sh…; alt="fb connect" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;';</pre><p>to:</p><pre> // No text, use default image.<br> $markup = '&lt;div class="fb_login_button_wrapper"&gt;&lt;a href="#" onclick="FB.login(function(){}, {scope : \'' . $scope . '\'}); return false;"&gt;&lt;span&gt;&lt;img src="/sites/all/themes/&lt;yout-theme&gt;/images/&lt;your-button&gt;.png" alt="fb connect" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;';</pre><p>Works fine with Ajax popup forms as well:</p><p><img src="http://www.reinisfischer.com/sites/default/files/popupform.jpg&quot; width="344" height="264"></p>

Drupal Menu Badges + Views + Flags + Rules = Counting Messages

<p>The Drupal project I'm currently working with get's complicated each and every day - so for a start I faced a problem to display dynamic content as menu items - i found a great not to say one of the greate findings this years in field of Drupal development - <a href="http://www.reinisfischer.com/drupal-create-dynamical-menus-menu-views&q…; target="_blank">Drupal &nbsp;Menu Views</a> , then I faced a problem to display tokens in Menu paths - again a superb solution with help of <a href="http://www.reinisfischer.com/menu-tokens-module-drupal-site&quot; target="_blank">Menu Tokens module</a>.</p><p>Finaly I faced another Drupal Menu related problem -<strong> to display a comment count in a Dynamical Menu with menu tokens enabled.&nbsp;</strong></p><p>I must admit - I was lucky enough to solve this problem as well - <strong>The Solution</strong> comes from another great Drupal module - Menu Badges</p><h2>About Menu Badges</h2><p><span>Provides a method for adding iOS-style badges to menu items.&nbsp;</span></p><h2>Adding Badges to Menus</h2><p>Once enabled, go to Administration &gt; Structure &gt; Menus, and click "list links" next to the menu containing the target item. Click "edit" next to the item and select the badge to display with the Display Menu Badge select box.</p><h2>Adding Badges to Tabs</h2><p>For adding badges to menu tabs, there is a tab under Administration &gt; Structure &gt; Menus called "Tab Menu Badges". Search for the menu router path of the tab you want to alter, then select a badge from the corresponding select box.</p><h2>Badge Types</h2><p>The module includes five example badges, and new badges can be created easily with&nbsp;<a href="http://drupal.org/project/views&quot; rel="nofollow">Views</a>. See this screencast for instructions:&nbsp;<a href="http://www.youtube.com/watch?v=4AoZQNg5QOI&quot; rel="nofollow">http://www.youtube.com/watch?v=4AoZQNg5QOI</a&gt;. Modules can also supply their own badges with a hook implementation. See the&nbsp;<a href="http://drupalcode.org/project/menu_badges.git/blob_plain/refs/heads/7.x…; rel="nofollow">README.txt</a>file for details.</p><p>&nbsp;</p><p>This is what I got after a couple of minutes playing with views and Menu badges</p><p><img src="http://www.reinisfischer.com/sites/default/files/menubadges.jpg&quot; alt="Menu Badges Example" title="Menu Badges Example" width="440" height="82"></p><p><em>Menu Badges Example</em></p><p>Now - as you can see from the above screen - this small element actually takes a lot views and a lot custom CSS - but it does well what it must to do.</p><p>Now the tricky part was to setup a view - which actually counts items, to be displayed on Menu Badges.</p><p>I created a view with Menu badge display counting all comments published on site (this is the behaviour customer is looking for)</p><p>To get a count out of Drupal views - we must turn on Aaggregation and add a NID field and set it to count (use aggregation)</p><p><img src="http://www.reinisfischer.com/sites/default/files/menubadgeview.jpg&quot; alt="Menu Badge View" title="Menu Badge View" width="1172" height="600"></p><p><em>Menu Badge View</em></p><p>As you can see from screen above - I'm using Flags Relationship, to count kinda only those comment's logged in user hasn't read yet (the tricky part here - I have not yet figured out how to decrease counter).&nbsp;</p><p>Flags are created by using another module: Drupal Flags.&nbsp;</p><p>Nothing fancy there - download that module, create a new comment type flag (is_new), now to get things more complexed you will have to add Drupal Rules (again, there is Drupal Rules module, you can use).</p><p>I created a new rule - which basically does following - <strong>after comment is saved it's flagged as is_new</strong> (so I can use this flag in my views)</p><p>What I haven't yet figured out is how to create a rule, which removes flag <strong>is_new</strong> after user has viewed particular comment.</p><p>Anyway - we have fully functional views, flags and we have menu badges module.</p><p>What we do now - we go to our Menus and add a menu badge to links - menu badges are created from view we made before</p><p><img src="http://www.reinisfischer.com/sites/default/files/menubadgeslink.jpg&quot; alt="Menu badges link" title="Menu badges link" width="1200" height="352"></p><p><em>Menu badges link</em></p><p>That's all - you can use CSS to style your badge icon.</p><p>P.S. If you have some idea how I can create a Drupal rule, to remove is_new flag after comment has been viewed - please drop me a comment!</p>

Drupal: Create Dynamical Menus with Menu Views

Today working on a customer's Drupal project, I found a kind of strange need - to display for authenticated users their flagged content in a drop-down menu - kinda Facebook, LinkedIn behavior, when you click on gear icon and magic happens - you see your latest messages, invitations, and e.t.c.

So I must admit - at the start I didn't have an idea - how actually to flag content. But luckily for me, a few years ago - I was playing with Flags Module and working on this project I decided flags will do exactly what we need - they are going to flag nodes.

First problems arise - we actually have two flags - Add to Favourite and Add to Complete. The problem arises - how to display both of these flags on a single views block and enable user to flag each of them.

The solution is quite  simple: add two Relationships on the same view:

Flags Relationships

Flags Relationships

Now - the flags is just a first stage of this task. Next task is to display flagged content in a nice drop-down menu.

My first idea was to create some views blocks and then to use CSS ul li to hide child item while parent item is not hovered (usual menu trick - which doesn't involve the use of any superfish or other menu modules), and display a drop-down menu (views block) when parent item is hovered.

The bad thing is - I didn't find a parents item :(

Few hours latter I found something great brought to us by LevelTen - Menu Views

About Menu views

Allows menu items to render views instead of links. This is useful for creating "mega-menus".

What Menu Views Does

Menu Views is a utility module. It provides back-end support for replacing a standard menu item link with a menu item view. Menu items (in any menu) now have the option of toggling between two different menu item types: link or view. Depending on which option is selected, the appropriate configuration form is displayed on the admin side and the appropriate type of item is rendered on the front-end.

What Menu Views Does NOT Do

Menu Views is NOT a theming/styling module for mega-menus. As stated above, this module is strictly a utility module for replacing menu item link with a view. Once the HTML markup is there, Menu View's job is done! Read#1794010: Menu Views is not working.

Depending on how a theme renders the primary and secondary navigation, this module may not work because the parent items may not ever be extended (regardless whether they are checked as such in the menu item). It is strongly recommended to use one of the following modules in your theme's menu region instead (see: Use menus in Drupal 7? You need Menu block module.).

Sponsorship

This module is sponsored and developed by LevelTen Interactive. LevelTen is a full-service interactive agency focused on building online brands by integrating digital strategy, Drupal development, and internet marketing.

Thank you LevelTen for this great module - you solved me a lot of time.

For now - I'm already seeing more places where menu views could be added.

How to solve Nginx: 413 Request Entity Too Large error

If you have ever encountered an error message that says "Nginx: 413 Request Entity Too Large", you know how frustrating it can be. This error message usually pops up when you try to upload a file that is too large for your server to handle. The good news is that it is possible to fix this error message.

In this article, we will discuss some methods you can use to solve the "Nginx: 413 Request Entity Too Large" error.

Here are some solutions to fix the "Nginx: 413 Request Entity Too Large" error:

  1. Increase the client_max_body_size limit: The first solution is to increase the client_max_body_size limit in your Nginx configuration file. This limit determines the maximum size of the files that can be uploaded to your server. You can increase this limit by adding the following line to your Nginx configuration file:  

client_max_body_size 100M;

This will increase the client_max_body_size limit to 100MB. You can increase or decrease this limit to suit your needs.

  1. Change the upload_max_filesize limit in PHP: If you are running a PHP application, you may also need to increase the upload_max_filesize limit in your PHP configuration file. You can do this by adding the following line to your PHP configuration file:  

upload_max_filesize = 100M

This will increase the upload_max_filesize limit to 100MB. Again, you can adjust this limit as needed.

  1. Modify the request buffer size: Another solution to the "Nginx: 413 Request Entity Too Large" error is to modify the request buffer size in your Nginx configuration file. This can be done by adding the following lines to your Nginx configuration file:  

client_body_buffer_size 128k;

client_header_buffer_size 1k;

client_max_body_size 10m;

large_client_header_buffers 2 1k;

These lines will increase the client body buffer size, client header buffer size, and the maximum size of the client request body. You can adjust the values as needed.

  1. Use a Content Delivery Network (CDN): If you are still experiencing the "Nginx: 413 Request Entity Too Large" error after trying the above solutions, you may want to consider using a Content Delivery Network (CDN) to handle your file uploads. CDNs can handle large files and take the burden off your server.

  2. Contact your hosting provider: If you have tried all of the above solutions and you are still experiencing the "Nginx: 413 Request Entity Too Large" error, it may be time to contact your hosting provider. They may be able to help you troubleshoot the issue and provide a solution.

In conclusion, the "Nginx: 413 Request Entity Too Large" error can be frustrating, but it can be fixed. By following the above solutions, you can increase the file upload limits and get your server working properly.