Variants and Node Add/Edit Overrides

Variants in Drupal allow you to reuse Panel Page layouts to make your life easier. You use Selection Rules to allow the system to decide what variant to use based on any number of criteria. In my case, I use Variants on the node add/edit form to provide a consistent interface between several different content types. As with many things Drupal, there are a few idiosyncrasies.

I have a custom content type called member-galleries. This holds images in a gallery like display. To render the add node properly, I had to learn the hard way that using

Image

the “Node Being Edited: Gallery Image form” is not the correct form to use. Even though Gallery Image is the field name that I gave the Image field on the content type that I created. It just seemed to make sense, right? And even worse, it appears when you test the functionality that this is the way to go. But, I kept getting a red herring error about file size when I would try to save an image. It turned out that the Variant really needed the “Node Being Edited” Base form instead. It appears to be exactly the same until you try to save a node of the content type.

Use two URLs to choose a different version of one variant

Hey hey. I haven’t posted in a while. I have been really busy doing some of the Codecademy stuff. And I have been learning a lot about Rules and some of the more granular ways to choose content on my site.

That brings me to today’s topic. I have One content type called research. I need to be able to use this content type on more than one node add/edit form for that one content type. So, I have one variant on the Node Add/Edit page in Page Manager. I thought that it might best to setup two variants at first then use some selection rules to choose based on the URL. Image

I looked at a few different ways to do this and the one that I have settled on is this. I have  one variant. I need to have one Panel on the page that is different from the other. So, I use a visibility rule for one panel and a different one for the other. Then, I placed both of those Panels on the page. Since it is a Node ADD/Edit variant, I have to work in the URL, node/add/research. so the rule for one panel is node/add/research/news and the other is node/add/research/courts. I created a menu that reflects these URLs and now I can get to the correct version of the one variant from URL selection rules on two different panel panes.

Tab Tamer – Error from Node add/edit when using Panels and Variants

tab tamer is a great module. all the default drupal tabs along the top really throw off my css. so i found this great mod to help. tab tamer allows you very granular control over the system generated tabs.

When I chose “hidden” for the tab in tab tamer for the node/edit field the variant for node add/edit disabled itself. after testing a few things, i was able to get it working again by setting that specific tab to hidden.

Turn Aggregator items into true Drupal Nodes

Drupal 8 should address the longstanding issue with items from the core RSS aggregator module existing as simple db objects rather tahn nodes, which limits what you can do with them in many ways.

The core Aggregator is really a big deal for me. the db created from these items is one of the biggest draws to my site. So I have tried many things to work around the limitations of DB objects.

I flirted with the idea of dumping the table to a flat file then importing it. That would work, can be CRONed and all that. But I really want to keep my solution specific to Drupal and not engage in a one-off like that.

The core mod has a categorization interface that I really like. It allows me to go through 100s of items every day pretty quickly and assign relevant topics to one of about 20 categories.

So, this is what I did to get the aggregator db items into nodes.

I created a View of the Aggregator Items. I created an RSS feed based on this View. then I used Feeds Importers to import that RSS feed into a content type that I created just for that.  This will work and you will be able to get quite a bit of data from the importer. But it isn’t as flexible as I wanted. UI simply could not get all the fields that I wanted to come across, even when forcing fields. That will work, but I always got undesirable formatting for the links. Or the links would come across malformed, with the name of my site prepended to the URL for example.

I really can’t use the Feeds Importers module to import all of the items in natively either. It will work, And you can build an interface of sorts in Views using VBO to assign taxonomy terms to the items, but it is cludgy and doesn’t scale well. But that can be a viable method too if you don’t have a lot of volume.

So, I want to use the core module for its stability and ease of categorization. but I need to be able to do things like allow users to see the items and make comments on them. I say comments but I really mean take notes. So, I used a Views Content Pane (with override URL and AJAX enabled) with a Node Add/Edit Variant in a Panel Page to allow user to see the Aggregated items, drag URLs from the View, take notes and alter the View (that’s where AJAX is magic) from the same place. Here is a SS of what it looks like.

Image

Then, I created another View of the Content Type “Research” which is used to hold the notes, links and such. I created a simple Content Pane View that shows the title of the Nodes (I use the Private Module to keep these posts completely private) and enabled AJAX so that the View Content Pane refreshes without having to refresh the whole page. Now I have a very nice research interface for my member with an easy way to reference my data.

More on Variants for the node add/edit forms

So I have Forums, Blogs and Galleries. And I want to style each one differently. So my first thought is to put the form inside of a Panel Page so that I can add other content. And that is the right direction, but it isn’t enough.

The Node Add/Edit form is already in the Page Manager as a Panel Page. It is disabled by default. By enabling it, I will have the ability to customize the form’s display. I already explained the part about the contexts

Image

method of determining what node type will be affected by the change. But here is something to keep in mind.

If you enable the page, and then create a variant for a content type to be used (when you add a node to that content type for example) you will find that the add form for ALL content types looks like the variant you created for example, for the Blog entry content type.

You will need to create a variant for each of the content types individually or they will all inherit the one variant’s customizations. and what I had to do to make THAT work properly was to use a selection rule for the variants that come at the beginning of the list. Since variant order determines in a large part, what is applied, you have to create selectors so that the “filtering” process works properly.

This is one of Drupal’s great strengths, but it is also kinda strange to me and took a while for me to get my head around. Look at the SS. Each of the three content types has a variant. and a context that applies to it. But, without a Selection Rule that also applies to it, the variant will simply inherit its appearance from a rule above it, the first one that happens to apply. There are other ways to do these same things with selection rules

Multilingual – MS Translator, Panel Variants & Language Switcher

I am so happy right now that I could almost cry. If it weren’t for the mainliners that live in the halfway house that we share I would. You just don’t cry in front of felons…

I have the multilingual stuff setup just the way that I want. And it works really seemlessly. I have a variant (actually I have three) on the main page of my site, DOCResource.org. You can go and check this out for yourself if you want.

Variants – in this order – order is important!

  1. Spanish users – the condition on this is whether the site language is spanish or not. this variant has a panel pane that displays the Misc item created by the Widget mod that holds the HTML & Jscript for the language switcher. The variable on this page is controlled by one of two elements; the user account or the choice from the language switcher dropdown. All Drupal translated items are in Spanish via Internationalization and the RSS items are in English because that is the way they come in. If the user wants to see anything in English translated to Spanish, they can click the MS Translator Widget button in the top right. 
  2. Authenticated Users – Shows the page the way it is for a default English speaking user. No Panel display for the MS T. Widget. This is the way a user would come in from the Facebook login as well. But, anyone can hit the dropdown switcher and get the same experience that someone will get from having an account that specifies spanish.
  3. Anonymous – Shows the login block and a limited version of the RSS Feed via a cloned view from the original. That way it updates the same way but the links are not enabled and the user is encouraged to sign in to the site to get more content.

This is great! Now what I have to do is place that MS T Widget on the pages that aggregator outside content (via RSS and email) so that a spanish speaker can read them natively. VERY VERY NICE!

Panel Pages, Variants and the Default front page in Drupal

I’ve been plugging all the different sections of content I have created into a layout that comprises my site. And by “sections” I generally mean Views that have been created to display content on a Panel Page.

So I have a Panel page that has been designate as the “Default front page” of the site. There are plenty of ways to display a specific page as the front page of a site depending on what web server you are using (IIS, Apache….) and other factors in the code, an HTTP redirect…. lots of ways….

In Drupal you go to Site Information to see what path leads to the front page. But you can also choose this when you are configuring your Panel Page. And this is where I was able to use a Variant in a way that really helps.

I have one front page, and two variants of that page. They have the same path, but different layouts and different components. And the deciding factor is whether the “logged in user” is “authenticated” or “anonymous”. If your anonymous, you get one thing, logged in, you get another. This is really helpful because some people choose to save passwords and log in automatically to sites and you want them to get the “front page” of the site that matches their login status. So this one way that Variants can help.