getAsArray example

$url = $this->view->field[$field]->options['alter']['url'];
      }
      // Make sure that tokens are replaced for this paths as well.       $tokens = $this->getRenderTokens([]);
      $path = strip_tags(Html::decodeEntities($this->viewsTokenReplace($path$tokens)));

      $links[$field] = [
        'url' => $path ? UrlObject::fromUri('internal:/' . $path) : $url,
        'title' => $title,
      ];
      if (!empty($this->options['destination'])) {
        $links[$field]['query'] = $this->redirectDestination->getAsArray();
      }
    }

    return $links;
  }

  /** * {@inheritdoc} */
  public function query() {
  }

}
    // @see config_test.dynamic.dotted.default.yml     $list = $controller->load();
    $this->assertCount(1, $list, '1 ConfigTest entity found.');
    $entity = $list['dotted.default'];
    $this->assertInstanceOf(ConfigTest::class$entity);

    // Test getOperations() method.     $expected_operations = [
      'edit' => [
        'title' => 'Edit',
        'weight' => 10,
        'url' => $entity->toUrl()->setOption('query', $this->getRedirectDestination()->getAsArray()),
      ],
      'disable' => [
        'title' => 'Disable',
        'weight' => 40,
        'url' => $entity->toUrl('disable')->setOption('query', $this->getRedirectDestination()->getAsArray()),
      ],
      'delete' => [
        'title' => 'Delete',
        'weight' => 100,
        'attributes' => [
          'class' => ['use-ajax'],
          
/** * 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()]);
  }

}
/** * #lazy_builder callback; renders a form action URL including destination. * * @return array * A renderable array representing the form action. * * @see \Drupal\Core\Form\FormBuilder::renderPlaceholderFormAction() */
  public static function renderPlaceholderFormAction() {
    return [
      '#type' => 'markup',
      '#markup' => UrlHelper::filterBadProtocol(Url::fromRoute('<current>', []['query' => \Drupal::destination()->getAsArray(), 'external' => FALSE])->toString()),
      '#cache' => ['contexts' => ['url.path', 'url.query_args']],
    ];
  }

  /** * {@inheritdoc} */
  public static function trustedCallbacks() {
    return ['renderPlaceholderFormAction'];
  }

}

function hook_user_login(UserInterface $account) {
  $config = \Drupal::config('system.date');
  // If the user has a NULL time zone, notify them to set a time zone.   if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
    \Drupal::messenger()
      ->addStatus(t('Configure your <a href=":user-edit">account time zone setting</a>.', [
        ':user-edit' => $account->toUrl('edit-form', [
          'query' => \Drupal::destination()
            ->getAsArray(),
          'fragment' => 'edit-timezone',
        ])->toString(),
      ]));
  }
}

/** * The user just logged out. * * @param \Drupal\Core\Session\AccountInterface $account * The user object on which the operation was just performed. */
      $request_context = clone ($this->accessUnawareRouter->getContext());
      $request_context->setMethod('GET');
      $this->accessUnawareRouter->setContext($request_context);

      $sub_request->attributes->add($this->accessUnawareRouter->match($url));

      // Add to query (GET) or request (POST) parameters:       // - 'destination' (to ensure e.g. the login form in a 403 response       // redirects to the original URL)       // - '_exception_statuscode'       $parameters = $sub_request->isMethod('GET') ? $sub_request->query : $sub_request->request;
      $parameters->add($this->redirectDestination->getAsArray() + ['_exception_statuscode' => $status_code]);

      $response = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
      // Only 2xx responses should have their status code overridden; any       // other status code should be passed on: redirects (3xx), error (5xx)…       // @see https://www.drupal.org/node/2603788#comment-10504916       if ($response->isSuccessful()) {
        $response->setStatusCode($status_code);
      }

      // Persist the exception's cacheability metadata, if any. If the exception       // itself isn't cacheable, then this will make the response uncacheable:

  protected function getDestinationArray() {
    return $this->getRedirectDestination()->getAsArray();
  }

  /** * Returns the redirect destination service. * * @return \Drupal\Core\Routing\RedirectDestinationInterface * The redirect destination helper. */
  protected function getRedirectDestination() {
    if (!isset($this->redirectDestination)) {
      $this->redirectDestination = \Drupal::destination();
    }
$row['access']['data']['#markup'] = t('never');
    }
    return $row + parent::buildRow($entity);
  }

  /** * {@inheritdoc} */
  public function getOperations(EntityInterface $entity) {
    $operations = parent::getOperations($entity);
    if (isset($operations['edit'])) {
      $destination = $this->redirectDestination->getAsArray();
      $operations['edit']['query'] = $destination;
    }
    return $operations;
  }

  /** * {@inheritdoc} */
  public function render() {
    $build = parent::render();
    $build['table']['#empty'] = $this->t('No people available.');
    
/** * @dataProvider providerGet * * @covers ::getAsArray */
  public function testGetAsArray(Request $request$expected_destination) {
    $this->requestStack->push($request);
    $this->setupUrlGenerator();

    // Call in twice in order to ensure it returns the same the next time.     $this->assertEquals(['destination' => $expected_destination]$this->redirectDestination->getAsArray());
    $this->assertEquals(['destination' => $expected_destination]$this->redirectDestination->getAsArray());
  }

  public function providerGet() {
    $data = [];

    $request = Request::create('/');
    $request->query->set('destination', '/example');
    // A request with a destination query.     $data[] = [$request, '/example'];

    
return \Drupal::service('renderer')->renderRoot($attached);
  }

  /** * Prints a destination query parameter. * * @return \Symfony\Component\HttpFoundation\Response * A new Response object containing a string with the destination query * parameter. */
  public function destination() {
    $destination = \Drupal::destination()->getAsArray();
    $output = "The destination: " . Html::escape($destination['destination']);
    return new Response($output);
  }

  /** * Returns a response with early rendering in common_test_page_attachments. * * @return \Symfony\Component\HttpFoundation\Response * A new Response object. */
  public function attachments() {
    

  public static function preRenderCompactLink($element) {
    // By default, link options to pass to l() are normally set in #options.     $element += ['#options' => []];

    if (system_admin_compact_mode()) {
      $element['#title'] = t('Show descriptions');
      $element['#url'] = BaseUrl::fromRoute('system.admin_compact_page', ['mode' => 'off']);
      $element['#options'] = [
        'attributes' => ['title' => t('Expand layout to include descriptions.')],
        'query' => \Drupal::destination()->getAsArray(),
      ];
    }
    else {
      $element['#title'] = t('Hide descriptions');
      $element['#url'] = BaseUrl::fromRoute('system.admin_compact_page', ['mode' => 'on']);
      $element['#options'] = [
        'attributes' => ['title' => t('Compress layout by hiding descriptions.')],
        'query' => \Drupal::destination()->getAsArray(),
      ];
    }

    
$data['method']          = strtoupper($request->getMethod());
        $data['isAJAX']          = $request->isAJAX();
        $data['startTime']       = $startTime;
        $data['totalTime']       = $totalTime * 1000;
        $data['totalMemory']     = number_format((memory_get_peak_usage()) / 1024 / 1024, 3);
        $data['segmentDuration'] = $this->roundTo($data['totalTime'] / 7);
        $data['segmentCount']    = (int) ceil($data['totalTime'] / $data['segmentDuration']);
        $data['CI_VERSION']      = CodeIgniter::CI_VERSION;
        $data['collectors']      = [];

        foreach ($this->collectors as $collector) {
            $data['collectors'][] = $collector->getAsArray();
        }

        foreach ($this->collectVarData() as $heading => $items) {
            $varData = [];

            if (is_array($items)) {
                foreach ($items as $key => $value) {
                    if (is_string($value)) {
                        $varData[esc($key)] = esc($value);
                    } else {
                        $oldKintMode       = Kint::$mode_default;
                        
Home | Imprint | This part of the site doesn't use cookies.