resetSeenIds example



  /** * Adds another form to the stack. * * Clicking 'apply' will go to this form rather than closing the ajax popup. */
  public function addFormToStack($key$display_id$type$id = NULL, $top = FALSE, $rebuild_keys = FALSE) {
    // Reset the cache of IDs. Drupal rather aggressively prevents ID     // duplication but this causes it to remember IDs that are no longer even     // being used.     Html::resetSeenIds();

    if (empty($this->stack)) {
      $this->stack = [];
    }

    $stack = [implode('-', array_filter([$key$this->id()$display_id$type$id]))$key$display_id$type$id];
    // If we're being asked to add this form to the bottom of the stack, no     // special logic is required. Our work is equally easy if we were asked to add     // to the top of the stack, but there's nothing in it yet.     if (!$top || empty($this->stack)) {
      $this->stack[] = $stack;
    }
->onlyMethods(['batchGet'])
      ->getMock();
    $this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);

    $this->formBuilder = new FormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->elementInfo, $this->themeManager, $this->csrfToken);
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    Html::resetSeenIds();
    (new FormState())->clearErrors();
  }

  /** * Provides a mocked form object. * * @param string $form_id * The form ID to be used. * @param mixed $expected_form * (optional) If provided, the expected form response for buildForm() to * return. Defaults to NULL. * @param int $count * (optional) The number of times the form is expected to be built. Defaults * to 1. * * @return \PHPUnit\Framework\MockObject\MockObject|\Drupal\Core\Form\FormInterface * The mocked form object. */
$expected = [];
    $expected[] = '<div id="block-test-block1">';
    $expected[] = ' ';
    $expected[] = ' ';
    $expected[] = ' ';
    $expected[] = ' </div>';
    $expected[] = '';
    $expected_output = implode("\n", $expected);
    $this->assertSame($expected_output(string) $this->renderer->renderRoot($output));

    // Reset the HTML IDs so that the next render is not affected.     Html::resetSeenIds();

    // Test the rendering of a block with a given title.     $entity = $this->controller->create([
      'id' => 'test_block2',
      'theme' => 'stark',
      'plugin' => 'test_html',
      'settings' => [
        'label' => 'Powered by Bananas',
      ],
    ]);
    $entity->save();
    
$form_state->setCached();
    }

    // \Drupal\Component\Utility\Html::getUniqueId() maintains a cache of     // element IDs it has seen, so it can prevent duplicates. We want to be     // sure we reset that cache when a form is processed, so scenarios that     // result in the form being built behind the scenes and again for the     // browser don't increment all the element IDs needlessly.     if (!FormState::hasAnyErrors()) {
      // We only reset HTML ID's when there are no validation errors as this can       // cause ID collisions with other forms on the page otherwise.       Html::resetSeenIds();
    }

    // If only parts of the form will be returned to the browser (e.g., Ajax or     // RIA clients), or if the form already had a new build ID regenerated when     // it was retrieved from the form cache, reuse the existing #build_id.     // Otherwise, a new #build_id is generated, to not clobber the previous     // build's data in the form cache; also allowing the user to go back to an     // earlier build, make changes, and re-submit.     // @see self::prepareForm()     $rebuild_info = $form_state->getRebuildInfo();
    $enforce_old_build_id = isset($old_form['#build_id']) && !empty($rebuild_info['copy']['#build_id']);
    
/** @var \Drupal\Core\Form\FormStateInterface $form_state */
    $form_state = $this->getFormState($view$display_id$js);
    $view = $form_state->get('view');
    $form_key = $form_state->get('form_key');

    // @todo Remove the need for this.     \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');

    // Reset the cache of IDs. Drupal rather aggressively prevents ID     // duplication but this causes it to remember IDs that are no longer even     // being used.     Html::resetSeenIds();

    // check to see if this is the top form of the stack. If it is, pop     // it off; if it isn't, the user clicked somewhere else and the stack is     // now irrelevant.     if (!empty($view->stack)) {
      $identifier = implode('-', array_filter([$form_key$view->id()$display_id$form_state->get('type')$form_state->get('id')]));
      // Retrieve the first form from the stack without changing the integer keys,       // as they're being used for the "2 of 3" progress indicator.       reset($view->stack);
      $stack_key = key($view->stack);
      $top = current($view->stack);
      

  public function testHtmlGetUniqueId($expected$source$reset = FALSE) {
    if ($reset) {
      Html::resetSeenIds();
    }
    $this->assertSame($expected, Html::getUniqueId($source));
  }

  /** * Provides test data for testHtmlGetId(). * * @return array * Test data. */
  public function providerTestHtmlGetUniqueId() {
    
Home | Imprint | This part of the site doesn't use cookies.