Currently, views implements its own token replacement. This is used in areas, titles, among others. We should explore adding support for core tokens. We could then have, for example, the site name token available for area text, which we don't have now.

I would also hope that maybe this will make the Result area handler obsolete, as we would in theory have global view tokens for things like result count and items per page.

This issue is not for the actual tokens provided. See related issues below.

Related:

#1817938: Add more tokens to views.tokens.inc

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

damiankloip’s picture

Status: Active » Needs review
FileSize
2.83 KB

Here is an initial patch. I haven't spent much time on this yet, just adding what I have for now. It's always good to get feedback, regardless of the state.

This implements 3 new methods on PluginBase to do token replacement, get available tokens, and provide a form helper method to add available tokens for forms.

aspilicious’s picture

+++ b/lib/Drupal/views/Plugin/views/PluginBase.phpundefined
@@ -227,4 +227,85 @@ abstract class PluginBase extends ComponentPluginBase {
+   * Returns a string with any core tokens replaced.
+   * @param string $string

Add a newline

+++ b/lib/Drupal/views/Plugin/views/PluginBase.phpundefined
@@ -227,4 +227,85 @@ abstract class PluginBase extends ComponentPluginBase {
+  /**
+   * Helper method to add available core tokens to a form.

In an oop world helper methods are private. If they must be public they are not "helper functions". And than we shouldn't start this sentence with "Helper function" but with a 3th person verb just like we do in other places :)

dawehner’s picture

Just adding a tag.

damiankloip’s picture

FileSize
2.83 KB

Here is a new patch, just including aspilicious' comments.

xjm’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.x-dev
Component: Code » views.module
Status: Needs review » Needs work
Issue tags: +Needs reroll
fastangel’s picture

Status: Needs work » Needs review
FileSize
2.88 KB

I attached new patch with reroll.

damiankloip’s picture

FileSize
4.69 KB

Here is a patch including some basic integration with core tokens for Text and TextCustom handlers.

Status: Needs review » Needs work

The last submitted patch, 1818450-7.patch, failed testing.

damiankloip’s picture

Issue tags: -Needs reroll

ok, I think this actually seems to be an issue with theme_item_list in D8.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
4.7 KB

Scrap that, you need to use '#markup' and not 'data'!

damiankloip’s picture

FileSize
6 KB

Added support for the title override area handler too.

xjm’s picture

Issue tags: +Needs tests
dawehner’s picture

FileSize
62.33 KB

Before and after is pretty much the same, as expected.

damiankloip’s picture

Assigned: Unassigned » damiankloip

Nice, thanks for the confirmation dawehner. I will write some tests.

damiankloip’s picture

FileSize
8.97 KB
2.89 KB

A few tests.

damiankloip’s picture

FileSize
8.98 KB

How about we just merge these tests in with the existing handler output and UI tests?

dawehner’s picture

+++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.phpundefined
+++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.phpundefined
@@ -79,6 +79,27 @@ public function testUI() {

@@ -79,6 +79,27 @@ public function testUI() {
+    $view = views_get_view('test_example_area');
+    $view->initHandlers();
+
+    // Test the list of available tokens.
+    $available = $view->empty['test_example']->getAvailableGlobalTokens();
+
+    foreach (array('site', 'view') as $type) {
+      $this->assertTrue(!empty($available[$type]) && is_array($available[$type]));
+      // Test that each item exists in the list.
+      foreach ($available[$type] as $token => $info) {
+        $this->assertText("[$type:$token]");

Couldn't we split this up in an extra method (testRenderArea maybe?) and move the UI tests into an extra file, but this is a followup.

Status: Needs review » Needs work
Issue tags: -Needs tests, -VDC

The last submitted patch, 1818450-16.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests, +VDC

#16: 1818450-16.patch queued for re-testing.

damiankloip’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

ok, the patch in #16 is actually fine and green. http://qa.drupal.org/pifr/test/390373

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

I agree that my comment in #17 is more a topic for a follow up.

xjm’s picture

Can we file the followup now? :)

dawehner’s picture

webchick’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Seems like a nice little improvement.

Committed and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.