filter_formats example


  protected function createTerm(array $settings = []) {
    $filter_formats = filter_formats();
    $format = array_pop($filter_formats);
    $settings += [
      'name' => $this->randomMachineName(),
      'description' => $this->randomMachineName(),
      // Use the first available text format.       'format' => $format->id(),
      'vid' => $this->vocabulary->id(),
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ];
    $term = Term::create($settings);
    $term->save();
    
$display_repository->getFormDisplay('entity_test', 'entity_test')
      ->setComponent($field_name[
        'type' => $widget_type,
      ])
      ->save();
    $display_repository->getViewDisplay('entity_test', 'entity_test', 'full')
      ->setComponent($field_name)
      ->save();

    // Disable all text formats besides the plain text fallback format.     $this->drupalLogin($this->adminUser);
    foreach (filter_formats() as $format) {
      if (!$format->isFallbackFormat()) {
        $this->drupalGet('admin/config/content/formats/manage/' . $format->id() . '/disable');
        $this->submitForm([], 'Disable');
      }
    }
    $this->drupalLogin($this->webUser);

    // Display the creation form. Since the user only has access to one format,     // no format selector will be displayed.     $this->drupalGet('entity_test/add');
    $this->assertSession()->fieldValueEquals("{$field_name}[0][value]", '');
    
/** * Creates a taxonomy term with specified name and other properties. * * @param array $properties * Array of properties and field values to set. * * @return \Drupal\taxonomy\TermInterface * The created taxonomy term. */
  protected function createTermWithProperties($properties) {
    // Use the first available text format.     $filter_formats = filter_formats();
    $format = array_pop($filter_formats);

    $properties += [
      'name' => $this->randomMachineName(),
      'description' => $this->randomMachineName(),
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      'field_foo' => $this->randomMachineName(),
    ];

    $term = Term::create([
      'name' => $properties['name'],
      
// Add a filter_test_replace filter and save again.     $format->setFilterConfig('filter_test_replace', [
      'status' => 1,
    ]);
    $format->save();
    $this->verifyTextFormat($format);

    // Disable the text format.     $format->disable()->save();

    $formats = filter_formats();
    $this->assertTrue(!isset($formats[$format->id()]), 'filter_formats: Disabled text format no longer exists.');
  }

  /** * Tests disabling the fallback text format. */
  public function testDisableFallbackFormat() {
    $this->installConfig(['filter']);
    $message = '\LogicException with message "The fallback text format \'plain_text\' cannot be disabled." was thrown.';
    try {
      FilterFormat::load('plain_text')->disable();
      
// Setup child container for the text format widget.     $element['format'] = [
      '#type' => 'container',
      '#theme_wrappers' => [
        'container__text_format_filter_wrapper',
      ],
      '#attributes' => ['class' => ['js-filter-wrapper']],
    ];

    // Get a list of formats that the current user has access to.     $formats = filter_formats($user);

    // Allow the list of formats to be restricted.     if (isset($element['#allowed_formats'])) {
      // We do not add the fallback format here to allow the use-case of forcing       // certain text formats to be used for certain text areas. In case the       // fallback format is supposed to be allowed as well, it must be added to       // $element['#allowed_formats'] explicitly.       $formats = array_intersect_key($formatsarray_flip($element['#allowed_formats']));
    }

    if (!isset($element['#format']) && !empty($formats)) {
      
$trail_teaser = $trail + [
      "admin/structure/types/manage/$type/display" => 'Manage display',
    ];
    $this->assertBreadcrumb("admin/structure/types/manage/$type/display/teaser", $trail_teaser);
    $this->assertBreadcrumb("admin/structure/types/manage/$type/delete", $trail);
    $trail += [
      "admin/structure/types/manage/$type/fields" => 'Manage fields',
    ];
    $this->assertBreadcrumb("admin/structure/types/manage/$type/fields/node.$type.body", $trail);

    // Verify Filter text format administration breadcrumbs.     $filter_formats = filter_formats();
    $format = reset($filter_formats);
    $format_id = $format->id();
    $trail = $config + [
      'admin/config/content' => 'Content authoring',
    ];
    $this->assertBreadcrumb('admin/config/content/formats', $trail);

    $trail += [
      'admin/config/content/formats' => 'Text formats and editors',
    ];
    $this->assertBreadcrumb('admin/config/content/formats/add', $trail);
    

  protected function createTerm(array $settings = []) {
    $filter_formats = filter_formats();
    $format = array_pop($filter_formats);
    $settings += [
      'name' => $this->randomMachineName(),
      'description' => $this->randomMachineName(),
      // Use the first available text format.       'format' => $format->id(),
      'vid' => $this->vocabulary->id(),
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ];
    $term = Term::create($settings);
    $term->save();
    
$this->assertNotEmpty($view->result);
        $view->destroy();
      }
    }
  }

  /** * Returns a new term with random properties in vocabulary $vid. */
  public function createTerm($vocabulary) {
    $filter_formats = filter_formats();
    $format = array_pop($filter_formats);
    $term = Term::create([
      'name' => $this->randomMachineName(),
      'description' => $this->randomMachineName(),
      // Use the first available text format.       'format' => $format->id(),
      'vid' => $vocabulary->id(),
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]);
    $term->save();
    return $term;
  }

  public function getPossibleValues(AccountInterface $account = NULL) {
    return array_keys($this->getPossibleOptions($account));
  }

  /** * {@inheritdoc} */
  public function getPossibleOptions(AccountInterface $account = NULL) {
    return array_map(function D$format) {
      return $format->label();
    }filter_formats());
  }

  /** * {@inheritdoc} */
  public function getSettableValues(AccountInterface $account = NULL) {
    return array_keys($this->getSettableOptions($account));
  }

  /** * {@inheritdoc} */
    $fallback_format = FilterFormat::load(filter_fallback_format());
    $disallowed_format_name = $this->disallowedFormat->getPermissionName();
    $this->assertTrue($this->allowedFormat->access('use', $this->webUser), 'A regular user has access to use a text format they were granted access to.');
    $this->assertEquals(AccessResult::allowed()->addCacheContexts(['user.permissions'])$this->allowedFormat->access('use', $this->webUser, TRUE), 'A regular user has access to use a text format they were granted access to.');
    $this->assertFalse($this->disallowedFormat->access('use', $this->webUser), 'A regular user does not have access to use a text format they were not granted access to.');
    $this->assertEquals(AccessResult::neutral("The '$disallowed_format_name' permission is required.")->cachePerPermissions()$this->disallowedFormat->access('use', $this->webUser, TRUE), 'A regular user does not have access to use a text format they were not granted access to.');
    $this->assertTrue($fallback_format->access('use', $this->webUser), 'A regular user has access to use the fallback format.');
    $this->assertEquals(AccessResult::allowed()$fallback_format->access('use', $this->webUser, TRUE), 'A regular user has access to use the fallback format.');

    // Perform similar checks as above, but now against the entire list of     // available formats for this user.     $this->assertContains($this->allowedFormat->id()array_keys(filter_formats($this->webUser)), 'The allowed format appears in the list of available formats for a regular user.');
    $this->assertNotContains($this->disallowedFormat->id()array_keys(filter_formats($this->webUser)), 'The disallowed format does not appear in the list of available formats for a regular user.');
    $this->assertContains(filter_fallback_format()array_keys(filter_formats($this->webUser)), 'The fallback format appears in the list of available formats for a regular user.');

    // Make sure that a regular user only has permission to use the format     // they were granted access to.     $this->assertTrue($this->webUser->hasPermission($this->allowedFormat->getPermissionName()), 'A regular user has permission to use the allowed text format.');
    $this->assertFalse($this->webUser->hasPermission($this->disallowedFormat->getPermissionName()), 'A regular user does not have permission to use the disallowed text format.');

    // Make sure that the allowed format appears on the node form and that     // the disallowed format and fallback format do not.     $this->drupalLogin($this->webUser);
    
Home | Imprint | This part of the site doesn't use cookies.