Problem/Motivation

On every display, on every link clicked, the rendered area is displayed with the same site-wide configured title. (default "Megarow content"). This is very basic and doesn't face real implementations.

Proposed resolution

The title of the rendered area will be computed in a fallback cascade following this sequence:

  1. If the admin supplies the title as Views field options that will be used. Now the field can have an optional 3rd part. For example: Label to be clicked|node/23/edit|Title to be shown on the rendered area can contain also replacements [nid].
  2. If the title has not been passed in the field options or is empty, the module will try to determine the title from the route that was passed as second argument. For example, node/23 will return the title of the node from the menu route item.
  3. In none of the above will provide a title, will fallback to variable_get('views_megarow_title', 'Megarow content').

Remaining tasks

None.

User interface changes

New format for the field options. The title can be appended as the 3rd argument.

API changes

None.

Original report by @foredoc

Hi,

I am currently using views_megarow_generic_render with the menu callback (display_megarow/%/%) for my content (basically, tables generated with views).

However, the title in the generic render is set to be a constant value, as follows:

variable_get('views_megarow_title', t('Megarow content'))

I am wondering if I can somehow change the title dynamically.

Thanks in advance for suggestions.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

foredoc’s picture

Issue summary: View changes
abrlam’s picture

I think so. I did a similar thing (node/%) but you have to modify the views_megarow_generic_render function a bit.

In views_megarow.module, around line 131, find the following line:

$commands[] = views_megarow_command_display(variable_get('views_megarow_title', t('Megarow content')), $output, $entity_id);

Replace variable_get('views_megarow_title', t('Megarow content')) with the desired title (use dpm($content to locate the title)).

You can see what I did in the attached patch file.

Hope that helps.

foredoc’s picture

Thanks, abrlam.

Your solution work for me in short term, and I am also looking for a long term solution without modifying the module itself.

Any suggestions?

Thanks.

Artusamak’s picture

Status: Active » Closed (works as designed)

I'm aware of this problem. The major issue is where should I retrieve my dynamic title from? It brings the issue of storage, when we render the megarow content (and sets the title), we are out of range of the view object. The views object is the logic place where our title should be stored.
So by design it's not easily tweakable.
I don't want to have a callback defining a title base on the current path, i don't consider it as real fix.

claudiu.cristea’s picture

Title: Dynamic title for views_megarow_generic_render(display_megarow/%/%) ? » Dynamic title for ajaz rendered areas
Version: 7.x-1.4 » 7.x-1.x-dev
Category: Support request » Feature request
Issue summary: View changes
Status: Closed (works as designed) » Needs review
claudiu.cristea’s picture

Title: Dynamic title for ajaz rendered areas » Dynamic title for ajax rendered areas
claudiu.cristea’s picture

Here's a patch.

claudiu.cristea’s picture

Issue summary: View changes

Typos.

Artusamak’s picture

Thanks for the patches, instead of chaining the arguments in the textarea, let's do something smarter like a new field type.

claudiu.cristea’s picture

That would mean a multi value field with 3 columns: label, path, title. Too complex and out of scope. As the first 2 are chained too, you'll need to solve those as well. I don't have time to deal with that separate issue but I'm ready to review if you can provide a patch.

In the meantime this is solving nice the issue even without the 3rd argument. It falls back to the route title and that is what people expect in 90% of cases. The 3rd argument can be used also with tokens to get a very customizable title.

claudiu.cristea’s picture

OK, I created #2414863: Move the field options texarea into a multi-line field for your proposal. Now the problems are treated distinct.

NWOM’s picture

Here is the patch from #7 rerolled for the newest dev.

NWOM’s picture

Ignore the last patch. Accidentally changed a line unnecessarily.

claudiu.cristea’s picture

+++ b/views_megarow.module
@@ -103,6 +103,15 @@ function views_megarow_generic_render($entity_id) {
+
+

Remove extra line.

NWOM’s picture

Oops. My mistake. Here it is again.

claudiu.cristea’s picture

@NWOM, if this worked for you, why not RTBC?

NWOM’s picture

Status: Needs review » Reviewed & tested by the community

I'm not able to verify whether it is conform to drupal 7 coding standards, since I'm not a PHP programmer. I just wanted to help and re-roll the patch. Of course, I can set it to RTBC, just wasn't sure.

Artusamak’s picture

Status: Reviewed & tested by the community » Needs review

Thank you for your patch but please do not mark as RTBC an issue if it hasn't been tested by someone else and confirmed as OK.
As mentioned earlier in the issue, i would rather see #2414863: Move the field options texarea into a multi-line field pushed forwarded than complexing this field a bit more.

claudiu.cristea’s picture

@Artusamak, the patch worked for him. So, he RTBC it after he tested :)

The other issue is not blocker for this. That one just makes the admin UI fancy. That one is not covering only the problems in this issue, so there's no reason to block this on that. That is a "nice to have", this is a real problem to megarow.

Artusamak’s picture

Status: Needs review » Reviewed & tested by the community

Hmm, my bad, i read a bit too fast. Thank you for the comment.

Your feedbacks are correct, i will examine the patch closer to commit it or not.

NWOM’s picture

Status: Reviewed & tested by the community » Needs work

I found a small bug with the patch. My node titles are automatically generated based on the beginning of the body text via Automatic Entity Label. I coincidentally have a few nodes where the body text contained two periods ".." which is then consequently used in the Views Megarow Title and in the URL via the megarow_title querystring.

In this case it results in the following crash when clicking on the megarow link:

An AJAX HTTP error occurred.
HTTP Result Code: 403
Debugging information follows.
Path: /display_megarow/110544/node/110544?megarow_title=fsa..
StatusText: Forbidden
ResponseText: 403 Forbidden
nginx/1.8.0

I'm sure there are other potential characters that will also have the same effect.

This can be easily reproduced by adding ".." to any node title. Also, the megarow link works as expected when this patch has been removed.

claudiu.cristea’s picture

Status: Needs work » Reviewed & tested by the community

@NWOM, I cannot reproduce the bug that you've described in #21. So, back to RTBC as per #20.

NWOM’s picture

@claudiu.cristea: Did you attempt to reproduce the issue by adding two periods to a title? It is very easy to reproduce.

I honestly don't think it's that big of a deal, since it can be fixed by rules. However, it is still a regression in comparison to the module without the patch, since a title can currently have two periods without issues. The only reason why I marked it as needs work, is due to other characters that may fall into the same regression.

claudiu.cristea’s picture

I created a megarow view based on nodes. I added 2 dots to title and saved. Everything went well.

NWOM’s picture

Ah ok. Good to know. Thanks for the response.

bocaj’s picture

Applied the patch in #15 to the latest dev and it worked great! It did exactly what I needed for a current project that I'm working on. I agree that only being able to set a title for all megarows isn't ideal. Having this functionality worked great!

The only minor issue I saw was on the textarea description at the end it says "Replacements ca be used for all parts." It should obviously read "Replacements can be used for all parts."

Artusamak’s picture

Status: Reviewed & tested by the community » Needs work
-      $links[] = $this->getLink($label, $url, array('class' => array('views-megarow-open')));
+      $links[] = $this->getLink($label, $url, $query, array('class' => 'views-megarow-open'));

If you do this, you will change the signature and may introduce regressions for classes potentially extending the views_handler_field_megarow_links handler. The argument should be added in last position.

+  if (!empty($_GET['megarow_title'])) {
+    $title = $_GET['megarow_title'];
+  }
+  else {
+    $route = menu_get_item($path);
+    $title = !empty($route['title']) ? $route['title'] : variable_get('views_megarow_title', 'Megarow content');
+  }
+

The title isn't sanitized when coming from the GET.