filter_default_format example

    $nodes[] = clone $node;

    // Create three revisions.     $revision_count = 3;
    for ($i = 0; $i < $revision_count$i++) {
      $logs[] = $node->revision_log = $this->randomMachineName(32);

      // Create revision with a random title and body and update variables.       $node->title = $this->randomMachineName();
      $node->body = [
        'value' => $this->randomMachineName(32),
        'format' => filter_default_format(),
      ];
      $node->untranslatable_string_field->value = $this->randomString();
      $node->setNewRevision();

      // Edit the 1st and 2nd revision with a different user.       if ($i < 2) {
        $editor = $this->drupalCreateUser();
        $node->setRevisionUserId($editor->id());
      }
      else {
        $node->setRevisionUserId($web_user->id());
      }
/** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $form['content'] = [
      '#title' => $this->t('Content'),
      '#type' => 'text_format',
      '#default_value' => $this->options['content']['value'],
      '#rows' => 6,
      '#format' => $this->options['content']['format'] ?? filter_default_format(),
      '#editor' => FALSE,
    ];
  }

  /** * {@inheritdoc} */
  public function preQuery() {
    $content = $this->options['content']['value'];
    // Check for tokens that require a total row count.     if (str_contains($content, '[view:page-count]') || str_contains($content, '[view:total-rows]')) {
      
'access content',
        'create article content',
      ]);
    }
    foreach ($this->users as $web_user) {
      $this->drupalLogin($web_user);
      foreach ([0 => 'Public', 1 => 'Private'] as $is_private => $type) {
        $settings = [
          'body' => [
            [
              'value' => $type . ' node',
              'format' => filter_default_format(),
            ],
          ],
          'title' => "$type Article created by " . $web_user->getAccountName(),
          'type' => 'article',
          'uid' => $web_user->id(),
          'private' => (bool) $is_private,
        ];

        $node = $this->drupalCreateNode($settings);
        $this->assertEquals($is_private(int) $node->private->value, 'The private status of the node was properly set in the node_access_test table.');
      }
    }

      ],
    ]);

    // Execute the view.     $this->executeView($view);

    $view->display_handler->handlers['header']['area']->options['content']['format'] = $this->randomString();
    $build = $view->display_handler->handlers['header']['area']->render();
    $this->assertEquals('', $renderer->renderRoot($build), 'Nonexistent format should return empty markup.');

    $view->display_handler->handlers['header']['area']->options['content']['format'] = filter_default_format();
    $build = $view->display_handler->handlers['header']['area']->render();
    $this->assertEquals(check_markup($string)$renderer->renderRoot($build), 'Existent format should return something');

    // Empty results, and it shouldn't be displayed .     $this->assertEquals([]$view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header');
    // Empty results, and it should be displayed.     $view->display_handler->handlers['header']['area']->options['empty'] = TRUE;
    $build = $view->display_handler->handlers['header']['area']->render(TRUE);
    $this->assertEquals(check_markup($string)$renderer->renderRoot($build), 'No result, but empty enabled lead to a full header');
  }

}
$this->drupalCreateContentType(['type' => 'page']);
    $node = $this->drupalCreateNode();

    $result = Json::decode($this->drupalGet('test/serialize/node-field', ['query' => ['_format' => 'json']]));
    $this->assertEquals($node->id()$result[0]['nid']);
    $this->assertEquals((string) $node->body->processed, (string) $result[0]['body']);

    // Make sure that serialized fields are not exposed to XSS.     $node = $this->drupalCreateNode();
    $node->body = [
      'value' => '<script type="text/javascript">alert("node-body");</script>' . $this->randomMachineName(32),
      'format' => filter_default_format(),
    ];
    $node->save();
    $result = Json::decode($this->drupalGet('test/serialize/node-field', ['query' => ['_format' => 'json']]));
    $this->assertEquals($node->id()$result[1]['nid']);
    $this->assertStringNotContainsString("<script", $this->getSession()->getPage()->getContent(), "No script tag is present in the raw page contents.");

    $this->drupalLogin($this->adminUser);

    // Add an alias and make the output raw.     $row_options = 'admin/structure/views/nojs/display/test_serializer_node_display_field/rest_export_1/row_options';

    

  public function testFeedOutput() {
    $this->drupalCreateContentType(['type' => 'page']);

    // Verify a title with HTML entities is properly escaped.     $node_title = 'This "cool" & "neat" article\'s title';
    $node = $this->drupalCreateNode([
      'title' => $node_title,
      'body' => [
        0 => [
          'value' => 'A paragraph',
          'format' => filter_default_format(),
        ],
      ],
    ]);
    $node_link = $node->toUrl()->setAbsolute()->toString();

    // Test the site name setting.     $site_name = $this->randomMachineName();
    $frontpage_url = Url::fromRoute('<front>')->setAbsolute()->toString();
    $this->config('system.site')->set('name', $site_name)->save();

    $this->drupalGet('test-feed-display.xml');
    

    $this->drupalLogin($test_user);

    // Add a new language.     ConfigurableLanguage::createFromLangcode('es')->save();

    // Set up times to be applied to the English and Spanish translations of the     // node create time, so that they are filtered in/out in the     // search_date_query_alter test module.     $created_time_en = new \DateTime('February 10 2016 10PM');
    $created_time_es = new \DateTime('March 19 2016 10PM');
    $default_format = filter_default_format();

    $node = $this->drupalCreateNode([
      'title' => 'Node EN',
      'type' => 'page',
      'body' => [
        'value' => $this->randomMachineName(32),
        'format' => $default_format,
      ],
      'langcode' => 'en',
      'created' => $created_time_en->getTimestamp(),
    ]);

    
$this->drupalCreateContentType(['type' => 'article']);

    // Create two nodes.     for ($i = 0; $i < 2; $i++) {
      $this->nodes[] = $this->drupalCreateNode(
        [
          'type' => 'article',
          'body' => [
            [
              'value' => $this->randomMachineName(42),
              'format' => filter_default_format(),
              'summary' => $this->randomMachineName(),
            ],
          ],
        ]
      );
    }
  }

  /** * Tests the node row plugin. */
  
$this->drupalCreateContentType(['type' => 'article']);

    // Create two nodes.     for ($i = 0; $i < 2; $i++) {
      $this->nodes[] = $this->drupalCreateNode(
        [
          'type' => 'article',
          'body' => [
            [
              'value' => $this->randomMachineName(42),
              'format' => filter_default_format(),
              'summary' => $this->randomMachineName(),
            ],
          ],
        ]
      );
    }
  }

  /** * Tests the node path plugin functionality when converted to entity link. */
  
// Get original node.     $nodes[] = clone $node;

    // Create two revisions.     $revision_count = 2;
    for ($i = 0; $i < $revision_count$i++) {

      // Create revision with a random title and body and update variables.       $node->title = $this->randomMachineName();
      $node->body = [
        'value' => $this->randomMachineName(32),
        'format' => filter_default_format(),
      ];
      $node->setNewRevision();

      $node->save();

      // Make sure we get revision information.       $node = Node::load($node->id());
      $nodes[] = clone $node;
    }

    $this->nodes = $nodes;

    
// Add a new language.     ConfigurableLanguage::createFromLangcode('es')->save();

    // Make the body field translatable. The title is already translatable by     // definition. The parent class has already created the article and page     // content types.     $field_storage = FieldStorageConfig::loadByName('node', 'body');
    $field_storage->setTranslatable(TRUE);
    $field_storage->save();

    // Create a few page nodes with multilingual body values.     $default_format = filter_default_format();
    $nodes = [
      [
        'title' => 'First node en',
        'type' => 'page',
        'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
        'langcode' => 'en',
      ],
      [
        'title' => 'Second node this is the Spanish title',
        'type' => 'page',
        'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
        
/** * Tests the rendered output for fields display with multiple translations. */
  public function testFeedFieldOutput() {
    $node = $this->drupalCreateNode([
      'type' => 'page',
      'title' => 'en',
      'body' => [
        0 => [
          'value' => 'Something in English.',
          'format' => filter_default_format(),
        ],
      ],
      'langcode' => 'en',
    ]);

    $es_translation = $node->addTranslation('es');
    $es_translation->set('title', 'es');
    $es_translation->set('body', [['value' => 'Algo en EspaƱol']]);
    $es_translation->save();

    $pt_br_translation = $node->addTranslation('pt-br');
    
'id' => 'basic',
      'label' => 'Basic',
    ]);
    $bundle->save();
    block_content_add_body_field($bundle->id());
    BlockContent::create([
      'info' => 'My content block',
      'type' => 'basic',
      'body' => [
        [
          'value' => 'This is the block content',
          'format' => filter_default_format(),
        ],
      ],
    ])->save();

    $this->createContentType(['type' => 'bundle_with_section_field']);
    $this->node = $this->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The node title',
      'body' => [
        [
          'value' => 'The node body',
        ],
'#account' => $this->editor,
    ];
    $editor = \Drupal::service('renderer')->renderPlain($username);

    // Get original node.     $nodes[] = clone $node;

    // Create revision with a random title and body and update variables.     $node->title = $this->randomMachineName();
    $node->body = [
      'value' => $this->randomMachineName(32),
      'format' => filter_default_format(),
    ];
    $node->setNewRevision();
    $revision_log = 'Revision <em>message</em> with markup.';
    $node->revision_log->value = $revision_log;
    $node->save();
    // Make sure we get revision information.     $node = Node::load($node->id());
    $nodes[] = clone $node;

    $this->drupalGet('node/' . $node->id() . '/revisions');

    
// Adjust the weights so that the first and second formats (in that order)     // are the two lowest weighted formats available to any user.     $edit = [];
    $edit['formats[' . $first_format->id() . '][weight]'] = -2;
    $edit['formats[' . $second_format->id() . '][weight]'] = -1;
    $this->drupalGet('admin/config/content/formats');
    $this->submitForm($edit, 'Save');
    $this->resetFilterCaches();

    // Check that each user's default format is the lowest weighted format that     // the user has access to.     $actual = filter_default_format($first_user);
    $expected = $first_format->id();
    $this->assertEquals($expected$actual, "First user's default format {$actual} is the expected lowest weighted format {$expected} that the user has access to.");
    $actual = filter_default_format($second_user);
    $expected = $second_format->id();
    $this->assertEquals($expected$actual, "Second user's default format {$actual} is the expected lowest weighted format {$expected} that the user has access to, and different to the first user's.");

    // Reorder the two formats, and check that both users now have the same     // default.     $edit = [];
    $edit['formats[' . $second_format->id() . '][weight]'] = -3;
    $this->drupalGet('admin/config/content/formats');
    
Home | Imprint | This part of the site doesn't use cookies.