本文整理汇总了PHP中Drupal\filter\Entity\FilterFormat::create方法的典型用法代码示例。如果您正苦于以下问题:PHP FilterFormat::create方法的具体用法?PHP FilterFormat::create怎么用?PHP FilterFormat::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\filter\Entity\FilterFormat
的用法示例。
在下文中一共展示了FilterFormat::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCommentForm_2698811
/**
* Ensure comment form works with history and big_pipe modules.
*
* @see https://www.drupal.org/node/2698811
*/
public function testCommentForm_2698811()
{
$this->assertTrue($this->container->get('module_installer')->install(['comment', 'history', 'ckeditor'], TRUE), 'Installed modules.');
// Ensure an `article` node type exists.
$this->createContentType(['type' => 'article']);
$this->addDefaultCommentField('node', 'article');
// Enable CKEditor.
$format = $this->randomMachineName();
FilterFormat::create(['format' => $format, 'name' => $this->randomString(), 'weight' => 1, 'filters' => []])->save();
$settings['toolbar']['rows'] = [[['name' => 'Links', 'items' => ['DrupalLink', 'DrupalUnlink']]]];
$editor = Editor::create(['format' => $format, 'editor' => 'ckeditor']);
$editor->setSettings($settings);
$editor->save();
$admin_user = $this->drupalCreateUser(['access comments', 'post comments', 'use text format ' . $format]);
$this->drupalLogin($admin_user);
$node = $this->createNode(['type' => 'article', 'comment' => CommentItemInterface::OPEN]);
// Create some comments.
foreach (range(1, 5) as $i) {
$comment = Comment::create(['status' => CommentInterface::PUBLISHED, 'field_name' => 'comment', 'entity_type' => 'node', 'entity_id' => $node->id()]);
$comment->save();
}
$this->drupalGet($node->toUrl()->toString());
// Confirm that CKEditor loaded.
$javascript = <<<JS
(function(){
return Object.keys(CKEDITOR.instances).length > 0;
}());
JS;
$this->assertJsCondition($javascript);
}
示例2: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
FilterFormat::create(array('format' => 'my_text_format', 'name' => 'My text format', 'filters' => array('filter_autop' => array('module' => 'filter', 'status' => TRUE))))->save();
FieldStorageConfig::create(array('field_name' => 'formatted_text', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array()))->save();
FieldConfig::create(['entity_type' => $this->entityType, 'bundle' => $this->bundle, 'field_name' => 'formatted_text', 'label' => 'Filtered text'])->save();
}
示例3: setUp
protected function setUp()
{
parent::setUp();
// Use Classy theme for testing markup output.
\Drupal::service('theme_handler')->install(['classy']);
\Drupal::service('theme_handler')->setDefault('classy');
// Grant the 'view test entity' permission.
$this->installConfig(array('user'));
Role::load(RoleInterface::ANONYMOUS_ID)->grantPermission('view test entity')->save();
// The label formatter rendering generates links, so build the router.
$this->container->get('router.builder')->rebuild();
$this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType, 'default', array(), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Set up a field, so that the entity that'll be referenced bubbles up a
// cache tag when rendering it entirely.
FieldStorageConfig::create(array('field_name' => 'body', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array()))->save();
FieldConfig::create(['entity_type' => $this->entityType, 'bundle' => $this->bundle, 'field_name' => 'body', 'label' => 'Body'])->save();
entity_get_display($this->entityType, $this->bundle, 'default')->setComponent('body', array('type' => 'text_default', 'settings' => array()))->save();
FilterFormat::create(array('format' => 'full_html', 'name' => 'Full HTML'))->save();
// Create the entity to be referenced.
$this->referencedEntity = $this->container->get('entity_type.manager')->getStorage($this->entityType)->create(array('name' => $this->randomMachineName()));
$this->referencedEntity->body = array('value' => '<p>Hello, world!</p>', 'format' => 'full_html');
$this->referencedEntity->save();
// Create another entity to be referenced but do not save it.
$this->unsavedReferencedEntity = $this->container->get('entity_type.manager')->getStorage($this->entityType)->create(array('name' => $this->randomMachineName()));
$this->unsavedReferencedEntity->body = array('value' => '<p>Hello, unsaved world!</p>', 'format' => 'full_html');
}
示例4: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->filter = FilterFormat::create(['format' => 'test_format', 'name' => $this->randomMachineName()]);
$this->filter->setFilterConfig('video_embed_wysiwyg', ['status' => 1]);
$this->filter->save();
}
示例5: setUp
protected function setUp()
{
parent::setUp();
// Let there be T-rex.
\Drupal::state()->set('editor_test_give_me_a_trex_thanks', TRUE);
\Drupal::service('plugin.manager.editor')->clearCachedDefinitions();
// Add text formats.
$filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array()));
$filtered_html_format->save();
$full_html_format = FilterFormat::create(array('format' => 'full_html', 'name' => 'Full HTML', 'weight' => 1, 'filters' => array()));
$full_html_format->save();
// Create article node type.
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
// Create page node type, but remove the body.
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Page'));
$body = FieldConfig::loadByName('node', 'page', 'body');
$body->delete();
// Create a formatted text field, which uses an <input type="text">.
FieldStorageConfig::create(array('field_name' => 'field_text', 'entity_type' => 'node', 'type' => 'text'))->save();
FieldConfig::create(array('field_name' => 'field_text', 'entity_type' => 'node', 'label' => 'Textfield', 'bundle' => 'page'))->save();
entity_get_form_display('node', 'page', 'default')->setComponent('field_text')->save();
// Create 3 users, each with access to different text formats.
$this->untrustedUser = $this->drupalCreateUser(array('create article content', 'edit any article content'));
$this->normalUser = $this->drupalCreateUser(array('create article content', 'edit any article content', 'use text format filtered_html'));
$this->privilegedUser = $this->drupalCreateUser(array('create article content', 'edit any article content', 'create page content', 'edit any page content', 'use text format filtered_html', 'use text format full_html'));
}
示例6: testTextFormatCrud
/**
* Tests CRUD operations for text formats and filters.
*/
function testTextFormatCrud()
{
// Add a text format with minimum data only.
$format = FilterFormat::create(array('format' => 'empty_format', 'name' => 'Empty format'));
$format->save();
$this->verifyTextFormat($format);
// Add another text format specifying all possible properties.
$format = FilterFormat::create(array('format' => 'custom_format', 'name' => 'Custom format'));
$format->setFilterConfig('filter_url', array('status' => 1, 'settings' => array('filter_url_length' => 30)));
$format->save();
$this->verifyTextFormat($format);
// Alter some text format properties and save again.
$format->set('name', 'Altered format');
$format->setFilterConfig('filter_url', array('status' => 0));
$format->setFilterConfig('filter_autop', array('status' => 1));
$format->save();
$this->verifyTextFormat($format);
// Add a filter_test_replace filter and save again.
$format->setFilterConfig('filter_test_replace', array('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.');
}
示例7: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_rev');
// Create the necessary formats.
$this->installConfig(array('filter'));
FilterFormat::create(array('format' => 'no_filters', 'filters' => array()))->save();
}
示例8: setUp
protected function setUp()
{
parent::setUp();
$filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML'));
$filtered_html_format->save();
$filtered_html_permission = $filtered_html_format->getPermissionName();
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array($filtered_html_permission));
}
示例9: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// Create a text format and associate this with CKEditor.
FilterFormat::create(['format' => 'full_html', 'name' => 'Full HTML', 'weight' => 1, 'filters' => []])->save();
Editor::create(['format' => 'full_html', 'editor' => 'ckeditor'])->save();
// Create a new user with admin rights.
$this->admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer site configuration', 'administer filters']);
}
示例10: setUp
protected function setUp()
{
parent::setUp();
// Add text format.
$filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array()));
$filtered_html_format->save();
// Create admin user.
$this->adminUser = $this->drupalCreateUser(array('administer filters'));
}
示例11: setUp
protected function setUp()
{
parent::setUp();
// Install the Filter module.
// Create text format, associate CKEditor.
$filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array()));
$filtered_html_format->save();
$editor = Editor::create(['format' => 'filtered_html', 'editor' => 'ckeditor']);
$editor->save();
}
示例12: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$basic_html_format = FilterFormat::load('basic_html');
$restricted_html_format = FilterFormat::create(array('format' => 'restricted_html', 'name' => 'Restricted HTML'));
$restricted_html_format->save();
$full_html_format = FilterFormat::create(array('format' => 'full_html', 'name' => 'Full HTML'));
$full_html_format->save();
$this->loginAsAdmin(['access content overview', 'administer tmgmt', 'translate any entity', 'edit any translatable_node content', $basic_html_format->getPermissionName(), $restricted_html_format->getPermissionName(), $full_html_format->getPermissionName()]);
}
示例13: setUp
protected function setUp()
{
parent::setUp();
// Install the Filter module.
// Add text formats.
$filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array()));
$filtered_html_format->save();
$full_html_format = FilterFormat::create(array('format' => 'full_html', 'name' => 'Full HTML', 'weight' => 1, 'filters' => array()));
$full_html_format->save();
}
示例14: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->format = strtolower($this->randomMachineName());
$filter_format = FilterFormat::create(['format' => $this->format, 'name' => $this->randomString(), 'filters' => []]);
$filter_format->save();
$editor = Editor::create(['format' => $this->format, 'editor' => 'ckeditor']);
$editor->save();
$this->adminUser = $this->drupalCreateUser(['administer filters']);
}
示例15: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// Add text format.
FilterFormat::create(['format' => 'basic_html', 'name' => 'Basic HTML', 'weight' => 0])->save();
// Set up text editor.
Editor::create(['format' => 'basic_html', 'editor' => 'unicorn', 'image_upload' => ['status' => TRUE, 'scheme' => 'public', 'directory' => 'inline-images', 'max_size' => '', 'max_dimensions' => ['width' => NULL, 'height' => NULL]]])->save();
// Create admin user.
$this->adminUser = $this->drupalCreateUser(['administer filters', 'use text format basic_html']);
$this->drupalLogin($this->adminUser);
}