Url example

$parent_id$menu_name$parent_link_path] = $source_value;
    $this->migrateLookup->lookup(NULL, [$parent_id])
      ->willReturn([['id' => $lookup_result]]);
    if ($route_name) {
      $plugin_definition = ['menu_name' => $menu_name];
      $static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
      $static_override = $static_override->reveal();
      $menu_link = new MenuLinkDefault([]$plugin_id$plugin_definition$static_override);
      $this->menuLinkManager->loadLinksByRoute($route_name[], 'admin')
        ->willReturn([$plugin_id => $menu_link]);

      $url = new Url($route_name[][]);
      $this->pathValidator->getUrlIfValidWithoutAccessCheck($parent_link_path)
        ->willReturn($url);
    }
    $result = $this->doTransform($source_value$plugin_id);
    $this->assertSame($expected_result$result);
  }

  /** * Provides data for testMenuLinkParent(). */
  public function providerMenuLinkParent() {
    
$build['fields'] = [];

    foreach ($executable->display_handler->getOption($types[$type]['plural']) as $id => $field) {
      // Build the option link for this handler ("Node: ID = article").       $build['fields'][$id] = [];
      $build['fields'][$id]['#theme'] = 'views_ui_display_tab_setting';

      $handler = $executable->display_handler->getHandler($type$id);
      if ($handler->broken()) {
        $build['fields'][$id]['#class'][] = 'broken';
        $field_name = $handler->adminLabel();
        $build['fields'][$id]['#link'] = Link::fromTextAndUrl($field_namenew Url('views_ui.form_handler', [
          'js' => 'nojs',
          'view' => $view->id(),
          'display_id' => $display['id'],
          'type' => $type,
          'id' => $id,
        ]['attributes' => ['class' => ['views-ajax-link']]]))->toString();
        continue;
      }

      $field_name = $handler->adminLabel(TRUE);
      if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
        
'use_site_name' => TRUE,
      'use_site_slogan' => TRUE,
      'label_display' => FALSE,
    ];
  }

  /** * {@inheritdoc} */
  public function blockForm($form, FormStateInterface $form_state) {
    // Get permissions.     $url_system_theme_settings = new Url('system.theme_settings');

    if ($url_system_theme_settings->access()) {
      // Provide links to the Appearance Settings page if the user has access to       // administer themes.       $site_logo_description = $this->t('Defined on the <a href="@appearance">Appearance Settings</a> page.', [
        '@appearance' => $url_system_theme_settings->toString(),
      ]);
    }
    else {
      // Explain that the user does not have access to the Appearance and Theme       // Settings pages.
$count,
          '1 pending update (@number_applied to be applied, @number_incompatible skipped)',
          '@count pending updates (@number_applied to be applied, @number_incompatible skipped)',
          ['@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count]
        );
      }
      else {
        $build['start']['#title'] = $this->formatPlural($count, '1 pending update', '@count pending updates');
      }
      // @todo Simplify with https://www.drupal.org/node/2548095       $base_url = str_replace('/update.php', '', $request->getBaseUrl());
      $url = (new Url('system.db_update', ['op' => 'run']))->setOption('base_url', $base_url);
      $build['link'] = [
        '#type' => 'link',
        '#title' => $this->t('Apply pending updates'),
        '#attributes' => ['class' => ['button', 'button--primary']],
        '#weight' => 5,
        '#url' => $url,
        '#access' => $url->access($this->currentUser()),
      ];
    }

    return $build;
  }

      }
    }

    $elements['responsive_image_style'] = [
      '#title' => $this->t('Responsive image style'),
      '#type' => 'select',
      '#default_value' => $this->getSetting('responsive_image_style') ?: NULL,
      '#required' => TRUE,
      '#options' => $responsive_image_options,
      '#description' => [
        '#markup' => $this->linkGenerator->generate($this->t('Configure Responsive Image Styles')new Url('entity.responsive_image_style.collection')),
        '#access' => $this->currentUser->hasPermission('administer responsive image styles'),
      ],
    ];

    $image_loading = $this->getSetting('image_loading');
    $elements['image_loading'] = [
      '#type' => 'details',
      '#title' => $this->t('Image loading'),
      '#weight' => 10,
      '#description' => $this->t('Lazy render images with native image loading attribute (<em>loading="lazy"</em>). This improves performance by allowing browsers to lazily load images. See <a href="@url">Lazy loading</a>.', [
        '@url' => 'https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading#images_and_iframes',
      ]),
/** * {@inheritdoc} */
  public function getConfirmText() {
    return $this->t('Uninstall');
  }

  /** * {@inheritdoc} */
  public function getCancelUrl() {
    return new Url('system.modules_uninstall');
  }

  /** * {@inheritdoc} */
  public function getDescription() {
    return $this->t('Would you like to continue with uninstalling the above?');
  }

  /** * {@inheritdoc} */
/** * Tests the build method with one path element. * * @covers ::build */
  public function testBuildWithOnePathElement() {
    $this->context->expects($this->once())
      ->method('getPathInfo')
      ->willReturn('/example');

    $breadcrumb = $this->builder->build($this->createMock('Drupal\Core\Routing\RouteMatchInterface'));
    $this->assertEquals([0 => new Link('Home', new Url('<front>'))]$breadcrumb->getLinks());
    $this->assertEqualsCanonicalizing(['url.path.is_front', 'url.path.parent']$breadcrumb->getCacheContexts());
    $this->assertEqualsCanonicalizing([]$breadcrumb->getCacheTags());
    $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
  }

  /** * Tests the build method with two path elements. * * @covers ::build * @covers ::getRequestForPath */
  
/** * {@inheritdoc} */
  public function getDescription() {
    return $this->t('Switch to the live version of the site.');
  }

  /** * {@inheritdoc} */
  public function getCancelUrl() {
    return new Url('<current>');
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->workspaceManager->switchToLive();
    $this->messenger()->addMessage($this->t('You are now viewing the live version of the site.'));
  }

}
'sAction' => 'manufacturer',
                'sSupplier' => $manufacturer['id'],
            ];
        }

        unset($manufacturer);

        $routes = $this->router->generateList(array_column($manufacturers, 'urlParams')$routingContext);
        $urls = [];

        for ($i = 0, $routeCount = \count($routes)$i < $routeCount; ++$i) {
            $urls[] = new Url($routes[$i]$manufacturers[$i]['changed'], 'weekly', Supplier::class$manufacturers[$i]['id']);
        }

        $this->allExported = true;

        return $urls;
    }

    /** * {@inheritdoc} */
    public function reset()
    {
use Symfony\Component\Validator\Exception\InvalidArgumentException;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;

/** * @author Renan Taranto <renantaranto@gmail.com> */
class UrlTest extends TestCase
{
    public function testNormalizerCanBeSet()
    {
        $url = new Url(['normalizer' => 'trim']);

        $this->assertEquals('trim', $url->normalizer);
    }

    public function testInvalidNormalizerThrowsException()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The "normalizer" option must be a valid callable ("string" given).');
        new Url(['normalizer' => 'Unknown Callable']);
    }

    
if (empty($products)) {
            return new UrlResult([], null);
        }

        $keys = FetchModeHelper::keyPair($products);

        $seoUrls = $this->getSeoUrls(array_values($keys), 'frontend.detail.page', $context$this->connection);

        $seoUrls = FetchModeHelper::groupUnique($seoUrls);

        $urls = [];
        $url = new Url();

        foreach ($products as $product) {
            $lastMod = $product['updated_at'] ?: $product['created_at'];

            $lastMod = (new \DateTime($lastMod))->format(Defaults::STORAGE_DATE_TIME_FORMAT);

            $newUrl = clone $url;

            if (isset($seoUrls[$product['id']])) {
                $newUrl->setLoc($seoUrls[$product['id']]['seo_path_info']);
            } else {
                
'#menu_name' => 'mock',
      '#theme' => 'menu__mock',
      '#items' => [
        // To be filled when generating test cases, using $get_built_element().       ],
    ];

    $get_built_element = function DMenuLinkTreeElement $element) {
      $return = [
        'attributes' => new Attribute(),
        'title' => $element->link->getTitle(),
        'url' => new Url($element->link->getRouteName()$element->link->getRouteParameters()['set_active_class' => TRUE]),
        'below' => [],
        'original_link' => $element->link,
        'is_expanded' => FALSE,
        'is_collapsed' => FALSE,
        'in_active_trail' => FALSE,
      ];

      if ($element->hasChildren && !empty($element->subtree)) {
        $return['is_expanded'] = TRUE;
      }
      elseif ($element->hasChildren) {
        
'#default_value' => $data['link']['bid'],
        '#attributes' => [
          'class' => ['book-bid'],
        ],
      ];

      $form[$id]['operations'] = [
        '#type' => 'operations',
      ];
      $form[$id]['operations']['#links']['view'] = [
        'title' => $this->t('View'),
        'url' => new Url('entity.node.canonical', ['node' => $nid]),
      ];

      if ($access) {
        $form[$id]['operations']['#links']['edit'] = [
          'title' => $this->t('Edit'),
          'url' => new Url('entity.node.edit_form', ['node' => $nid]),
          'query' => $destination,
        ];
        $form[$id]['operations']['#links']['delete'] = [
          'title' => $this->t('Delete'),
          'url' => new Url('entity.node.delete_form', ['node' => $nid]),
          
$role_with_access = Role::create(['id' => 'role_with_access', 'label' => 'With access']);
    $role_with_access->grantPermission('administer users');
    $role_with_access->save();

    /** @var \Drupal\user\RoleInterface $role_without_access */
    $role_without_access = Role::create(['id' => 'role_without_access', 'label' => 'Without access']);
    $role_without_access->save();

    $user_with_access = User::create(['roles' => ['role_with_access']]);
    $user_without_access = User::create(['roles' => ['role_without_access']]);

    $url_always_access = new Url('router_test.1');
    $this->assertTrue($url_always_access->access($user_with_access));
    $this->assertTrue($url_always_access->access($user_without_access));

    $url_none_access = new Url('router_test.15');
    $this->assertFalse($url_none_access->access($user_with_access));
    $this->assertFalse($url_none_access->access($user_without_access));

    $url_access = new Url('router_test.16');
    $this->assertTrue($url_access->access($user_with_access));
    $this->assertFalse($url_access->access($user_without_access));
  }

}
$this->assertSame($status$redirect->getStatusCode());
  }

  /** * Provides test data for testing the redirectForm() method with a route name. * * @return array * Returns some test data. */
  public function providerTestRedirectWithUrl() {
    return [
      [new Url('test_route_a', []['absolute' => TRUE]), 'test-route'],
      [new Url('test_route_b', ['key' => 'value']['absolute' => TRUE]), 'test-route/value'],
    ];
  }

  /** * Tests the redirectForm() method with a response object. * * @covers ::redirectForm */
  public function testRedirectWithResponseObject() {
    $form_submitter = $this->getFormSubmitter();
    
Home | Imprint | This part of the site doesn't use cookies.