mergeOptions example

/** * Ensures that a destination is present on the given URL. * * @param \Drupal\Core\Url $url * The URL object to which the destination should be added. * * @return \Drupal\Core\Url * The updated URL object. */
  protected function ensureDestination(Url $url) {
    return $url->mergeOptions(['query' => $this->getRedirectDestination()->getAsArray()]);
  }

}
$path = $options['path'];
    unset($options['path']);

    // Create URL.     // @todo Views should expect and store a leading /. See:     // https://www.drupal.org/node/2423913     $url = UrlHelper::isExternal($path) ? Url::fromUri($path$options) : Url::fromUserInput('/' . ltrim($path, '/')$options);

    // Merge the exposed query parameters.     if (!empty($this->view->exposed_raw_input)) {
      $url->mergeOptions(['query' => $this->view->exposed_raw_input]);
    }
    return $url;
  }

  /** * {@inheritdoc} */
  public function render() {
    $rows = (!empty($this->view->result) || $this->view->style_plugin->evenEmpty()) ? $this->view->style_plugin->render($this->view->result) : [];

    $element = [
      
$url->setOptions([]);
    $this->assertEquals([]$url->getOptions());
  }

  /** * Tests the mergeOptions() method. * * @covers ::mergeOptions */
  public function testMergeOptions() {
    $url = Url::fromRoute('test_route', []['foo' => 'bar', 'bar' => ['key' => 'value']]);
    $url->mergeOptions(['bar' => ['key' => 'value1', 'key2' => 'value2']]);
    $this->assertEquals(['foo' => 'bar', 'bar' => ['key' => 'value1', 'key2' => 'value2']]$url->getOptions());
  }

  /** * Tests the access() method for routed URLs. * * @param bool $access * The access value. * * @covers ::access * @covers ::accessManager * @dataProvider accessProvider */
if (!$url instanceof Url) {
      $url = Url::fromUri($url);
    }
    // The twig extension should not modify the original URL object, this     // ensures consistent rendering.     // @see https://www.drupal.org/node/2842399     $url = clone $url;
    if ($attributes) {
      if ($attributes instanceof Attribute) {
        $attributes = $attributes->toArray();
      }
      $url->mergeOptions(['attributes' => $attributes]);
    }
    // The text has been processed by twig already, convert it to a safe object     // for the render system.     if ($text instanceof TwigMarkup) {
      $text = Markup::create($text);
    }
    $build = [
      '#type' => 'link',
      '#title' => $text,
      '#url' => $url,
    ];
    
Home | Imprint | This part of the site doesn't use cookies.