An 'embed' display has an option 'linked display'. This controls the path that the View uses for the exposed filters form.

The options for this let you set a custom URL.

However, I don't see how this can possibly work. In views_plugin_display we have this code:

  /**
   * Return the base path to use for this display.
   *
   * This can be overridden for displays that do strange things
   * with the path.
   */
  function get_path() {
    if ($this->has_path()) {
      return $this->get_option('path');
    }

    $display_id = $this->get_link_display();
    if ($display_id && !empty($this->view->display[$display_id]) && is_object($this->view->display[$display_id]->handler)) {
      return $this->view->display[$display_id]->handler->get_path();
    }

    // We need to get here for the custom URL option to have worked.

    if ($this->get_option('link_display') == 'custom_url' && $link_url = $this->get_option('link_url')) {
      return $link_url;
    }
  }

The above makes sense in itself. However, before we get to the point where we can see that the option is set to 'custom_url', we call get_link_display().

  function get_link_display() {
    $display_id = $this->get_option('link_display');
    // If unknown, pick the first one.
    if (empty($display_id) || empty($this->view->display[$display_id])) {
      foreach ($this->view->display as $display_id => $display) {
        if (!empty($display->handler) && $display->handler->has_path()) {
          return $display_id;
        }
      }
    }
    else {
      return $display_id;
    }
    // fall-through returns NULL
  }

This will retrieve the 'link_display' option and find it's equal to 'custom_url'.
That is going to be an unknown display on the view, so empty($this->view->display[$display_id] is TRUE.
Therefore, the function will try to find another display on the view which has a path.
If it finds one, it returns the ID for that.

So now we get back to get_path(). Our call just got us a display_id, AND the way it was obtained is guaranteed to be a valid display ID!

    if ($display_id && !empty($this->view->display[$display_id]) && is_object($this->view->display[$display_id]->handler)) {
      return $this->view->display[$display_id]->handler->get_path();
    }

So the condition here is guaranteed to pass. We return the path from the display ID which get_link_display() found.

It's impossible for this code at the end to be executed:

    if ($this->get_option('link_display') == 'custom_url' && $link_url = $this->get_option('link_url')) {
      return $link_url;
    }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Active » Needs review
FileSize
3.78 KB

Very simple fix: handle the special case first.

joachim’s picture

The last submitted patch, 1: 2180897.views_.embed-display-linked-display-custom-url.patch, failed testing.

joelpittet’s picture

Hmm this seems to make sense, bumping to get a few more eyeballs.

jwineichen’s picture

#2 worked for me

jwineichen’s picture

Would be great if this could be reviewed and pushed the to next release.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 5 year old patch in #2 to views_plugin_display.inc does not apply to the latest views 7.x-3.x-dev.

Checking patch plugins/views_plugin_display.inc...
error: while searching for:
      return $this->get_option('path');
    }

    $display_id = $this->get_link_display();
    if ($display_id && !empty($this->view->display[$display_id]) && is_object($this->view->display[$display_id]->handler)) {
      return $this->view->display[$display_id]->handler->get_path();
    }

    if ($this->get_option('link_display') == 'custom_url' && $link_url = $this->get_option('link_url')) {
      return $link_url;
    }
  }

  function get_url() {

error: patch failed: plugins/views_plugin_display.inc:779
error: plugins/views_plugin_display.inc: patch does not apply
Andrew Answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
856 bytes

Patch rerolled.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

I've been using the patch in #2 for a while now, seems like others agree.

  • DamienMcKenna committed 8cc29df on 7.x-3.x authored by joachim
    Issue #2180897 by joachim, Andrew Answer, joelpittet, jwineichen, Chris...
DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed
Parent issue: » #3118500: Plan for Views 7.x-3.25

Committed. Thanks!

Status: Fixed » Closed (fixed)

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