To add a view to the header or footer of another view one can use a Global: View area. The inserted view can inherit the parent view's contextual filters, but unfortunately custom contextual filters cannot be set in Drupal 7 and 8.

For Drupal 7 I created a custom views_handler_area (gist). If there is any chance of this feature being committed to Views I'd be more than happy to supply patches.

View area with custom contextual filters

Comments

lendude’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.1.x-dev
Component: Miscellaneous » views.module

Nice.

Moving to right queue.

dawehner’s picture

So yeah we could patch \Drupal\views\Plugin\views\area\View to do so. I think we could totally do that.

lmeurs’s picture

lmeurs’s picture

Status: Active » Needs review

Status: Needs review » Needs work
lmeurs’s picture

Same patches, different file names.

lendude’s picture

Issue tags: +Needs tests
+++ b/core/modules/views/src/Plugin/views/area/View.php
@@ -100,6 +101,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+      Custom values will be merged with optionally inherited values, leave a custom value blank to not overwrite an inherited value. For example, %example2.", array('%example1' => '40/12/10', '%example2' => '40//10')),

I think this needs a better explanation, the description is not clear.
Also I'm not a fan of using nothing to inherit the parent arguments. I think it would be much clearer to use a placeholder like %. So 40/%/10 in the example.
"If 'Inherit contextual filters' is checked, inherited values can be merged with custom values by using % where you want to use the parent value. For example, %example2.", '%example2' => '40/%/10'
Something along those lines?

Manually tested this and looks good, but this also needs tests.

lendude’s picture

Status: Needs review » Needs work
aerozeppelin’s picture

Status: Needs work » Needs review
StatusFileSize
new6.58 KB
new6.36 KB

Added tests and updated description as per#7.

dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/area/View.php
@@ -126,12 +134,23 @@ public function render($empty = FALSE) {
+            else {
+              $arguments[$i] = $argument;
+            }

Ideally we would support tokens here.

lmeurs’s picture

Status: Needs review » Needs work

@aerozeppelin: Thanks for the patch, great to have tests! I reviewed your code and don't really get what is happening at the following snippet.

+            if ($argument == '%') {
+              if (!empty($inherit_arguments)){
+               $arguments[] = reset($inherit_arguments);
+              }
+            }

If an argument is left blank by defining %, the first element of $inherit_arguments will always be used since $inherit_arguments does not change in the loop. Also the order of arguments changes by not copying inherited arguments from their specific positions.

aerozeppelin’s picture

StatusFileSize
new15.34 KB
new10.02 KB

@lmeurs your welcome. Thank you for your feedback.

+ if ($argument == '%') {
+ if (!empty($inherit_arguments)){
+ $arguments[] = reset($inherit_arguments);
+ }
+ }

You are correct, the above snippet is wrong, it performs an incorrect operation. The tests were returning false positives. I've amended the above snippet and added more tests. Let's see.

aerozeppelin’s picture

Status: Needs work » Needs review

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

el1_1el’s picture

StatusFileSize
new2.39 KB

rerolling for 8.6

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

lubwn’s picture

Patch works nicely, but maybe if we can push tokens to contexual filters, that would be very nice! I am looking for such a functionality.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ranjith_kumar_k_u’s picture

StatusFileSize
new2.39 KB
new594 bytes

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

nikhil_110’s picture

StatusFileSize
new3.42 KB

Attached patch against Drupal 10.1.x

Patch #28 is not applied for Drupal 10.1.x so Inter-diff file is not added.

error: while searching for:
        \Drupal::messenger()->addError(t("Recursion detected in view @view display @display.", ['@view' => $view_name, '@display' => $display_id]));
      }
      else {
        if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
          $output = $view->preview($display_id, $this->view->args);
        }
        else {
          $output = $view->preview($display_id);
        }
        $this->isEmpty = $view->display_handler->outputIsEmpty();
        return $output;
      }

error: patch failed: core/modules/views/src/Plugin/views/area/View.php:121
error: core/modules/views/src/Plugin/views/area/View.php: patch does not apply

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.