filter_formats_reset example

$this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->addressEquals('node/' . $node->id());
    $this->assertSession()->pageTextContains($new_title);
    $this->assertSession()->pageTextNotContains($old_title);
  }

  /** * Rebuilds text format and permission caches in the thread running the tests. */
  protected function resetFilterCaches() {
    filter_formats_reset();
  }

}
$edit['formats[' . $second_format->id() . '][weight]'] = -3;
    $this->drupalGet('admin/config/content/formats');
    $this->submitForm($edit, 'Save');
    $this->resetFilterCaches();
    $this->assertEquals(filter_default_format($first_user)filter_default_format($second_user), 'After the formats are reordered, both users have the same default format.');
  }

  /** * Rebuilds text format and permission caches in the thread running the tests. */
  protected function resetFilterCaches() {
    filter_formats_reset();
  }

}
public function disable() {
    if ($this->isFallbackFormat()) {
      throw new \LogicException("The fallback text format '{$this->id()}' cannot be disabled.");
    }

    parent::disable();

    // Allow modules to react on text format deletion.     \Drupal::moduleHandler()->invokeAll('filter_format_disable', [$this]);

    // Clear the filter cache whenever a text format is disabled.     filter_formats_reset();

    return $this;
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    // Ensure the filters have been sorted before saving.     $this->filters()->sort();

    
$this->assertStringContainsString(Html::escape($value)(string) $rendered_entity);

    // Create a new text format that does not escape HTML, and grant the user     // access to it.     $this->drupalLogin($this->adminUser);
    $edit = [
      'format' => mb_strtolower($this->randomMachineName()),
      'name' => $this->randomMachineName(),
    ];
    $this->drupalGet('admin/config/content/formats/add');
    $this->submitForm($edit, 'Save configuration');
    filter_formats_reset();
    $format = FilterFormat::load($edit['format']);
    $format_id = $format->id();
    $permission = $format->getPermissionName();
    $roles = $this->webUser->getRoles();
    $rid = $roles[0];
    user_role_grant_permissions($rid[$permission]);
    $this->drupalLogin($this->webUser);

    // Display edition form.     // We should now have a 'text format' selector.     $this->drupalGet('entity_test/manage/' . $id . '/edit');
    
    $edit = [];
    $edit['format'] = mb_strtolower($this->randomMachineName());
    $edit['name'] = $this->randomMachineName();
    $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
    $edit['filters[' . $second_filter . '][status]'] = TRUE;
    $edit['filters[' . $first_filter . '][status]'] = TRUE;
    $this->drupalGet('admin/config/content/formats/add');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->addressEquals('admin/config/content/formats');
    $this->assertSession()->statusMessageContains("Added text format {$edit['name']}.", 'status');

    filter_formats_reset();
    $format = FilterFormat::load($edit['format']);
    $this->assertNotNull($format, 'Format found in database.');
    $this->drupalGet('admin/config/content/formats/manage/' . $format->id());
    $this->assertSession()->checkboxChecked('roles[' . RoleInterface::AUTHENTICATED_ID . ']');
    $this->assertSession()->checkboxChecked('filters[' . $second_filter . '][status]');
    $this->assertSession()->checkboxChecked('filters[' . $first_filter . '][status]');
    /** @var \Drupal\user\Entity\Role $role */
    \Drupal::entityTypeManager()->getStorage('user_role')->resetCache([RoleInterface::AUTHENTICATED_ID]);
    $role = Role::load(RoleInterface::AUTHENTICATED_ID);
    $this->assertTrue($role->hasPermission($format->getPermissionName()), 'The authenticated role has permission to use the filter.');

    
$form = parent::buildForm($form$form_state);
    $form['actions']['submit']['#value'] = $this->t('Save');
    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form$form_state);

    filter_formats_reset();
    $this->messenger->addStatus($this->t('The text format ordering has been saved.'));
  }

}
Home | Imprint | This part of the site doesn't use cookies.