当前位置: 首页>>代码示例>>PHP>>正文


PHP filter_formats_reset函数代码示例

本文整理汇总了PHP中filter_formats_reset函数的典型用法代码示例。如果您正苦于以下问题:PHP filter_formats_reset函数的具体用法?PHP filter_formats_reset怎么用?PHP filter_formats_reset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了filter_formats_reset函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getFormatFilters

 /**
  * Retrieves a list of filters for a given text format.
  *
  * @param string $format_name
  *    Text format machine name.
  * @param bool $reset
  *    TRUE to reset filter formats cache.
  *
  * @return array
  *    An array of filter objects associated to the given text format.
  */
 public function getFormatFilters($format_name, $reset = FALSE)
 {
     if ($reset) {
         filter_formats_reset();
     }
     return filter_list_format($format_name);
 }
开发者ID:janoka,项目名称:platform-dev,代码行数:18,代码来源:Config.php

示例2: testFilterDefaults

 /**
  * Tests explicit and implicit default settings for filters.
  */
 function testFilterDefaults()
 {
     $filter_info = $this->container->get('plugin.manager.filter')->getDefinitions();
     // Create text format using filter default settings.
     $filter_defaults_format = entity_create('filter_format', array('format' => 'filter_defaults', 'name' => 'Filter defaults'));
     $filter_defaults_format->save();
     // Verify that default weights defined in hook_filter_info() were applied.
     $saved_settings = array();
     foreach ($filter_defaults_format->filters() as $name => $filter) {
         $expected_weight = $filter_info[$name]['weight'];
         $this->assertEqual($filter->weight, $expected_weight, format_string('@name filter weight %saved equals %default', array('@name' => $name, '%saved' => $filter->weight, '%default' => $expected_weight)));
         $saved_settings[$name]['weight'] = $expected_weight;
     }
     // Re-save the text format.
     $filter_defaults_format->save();
     // Reload it from scratch.
     filter_formats_reset();
     // Verify that saved filter settings have not been changed.
     foreach ($filter_defaults_format->filters() as $name => $filter) {
         $this->assertEqual($filter->weight, $saved_settings[$name]['weight'], format_string('@name filter weight %saved equals %previous', array('@name' => $name, '%saved' => $filter->weight, '%previous' => $saved_settings[$name]['weight'])));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:25,代码来源:FilterSettingsTest.php

示例3: _testTextfieldWidgetsFormatted

 /**
  * Helper function for testTextfieldWidgetsFormatted().
  */
 function _testTextfieldWidgetsFormatted($field_type, $widget_type)
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     // Create a field.
     $field_name = Unicode::strtolower($this->randomMachineName());
     $field_storage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => $field_type));
     $field_storage->save();
     entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => 'entity_test', 'label' => $this->randomMachineName() . '_label'))->save();
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => $widget_type))->save();
     entity_get_display('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->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', array(), t('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->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed');
     $this->assertNoFieldByName("{$field_name}[0][format]", '', 'Format selector is not displayed');
     // Submit with data that should be filtered.
     $value = '<em>' . $this->randomMachineName() . '</em>';
     $edit = array("{$field_name}[0][value]" => $value);
     $this->drupalPostForm(NULL, $edit, t('Save'));
     preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
     $id = $match[1];
     $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
     // Display the entity.
     $entity = entity_load('entity_test', $id);
     $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
     $content = $display->build($entity);
     $this->setRawContent($renderer->renderRoot($content));
     $this->assertNoRaw($value, 'HTML tags are not displayed.');
     $this->assertEscaped($value, 'Escaped HTML is displayed correctly.');
     // Create a new text format that does not escape HTML, and grant the user
     // access to it.
     $this->drupalLogin($this->adminUser);
     $edit = array('format' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomMachineName());
     $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
     filter_formats_reset();
     $format = entity_load('filter_format', $edit['format']);
     $format_id = $format->id();
     $permission = $format->getPermissionName();
     $roles = $this->webUser->getRoles();
     $rid = $roles[0];
     user_role_grant_permissions($rid, array($permission));
     $this->drupalLogin($this->webUser);
     // Display edition form.
     // We should now have a 'text format' selector.
     $this->drupalGet('entity_test/manage/' . $id . '/edit');
     $this->assertFieldByName("{$field_name}[0][value]", NULL, 'Widget is displayed');
     $this->assertFieldByName("{$field_name}[0][format]", NULL, 'Format selector is displayed');
     // Edit and change the text format to the new one that was created.
     $edit = array("{$field_name}[0][format]" => $format_id);
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertText(t('entity_test @id has been updated.', array('@id' => $id)), 'Entity was updated');
     // Display the entity.
     $this->container->get('entity.manager')->getStorage('entity_test')->resetCache(array($id));
     $entity = entity_load('entity_test', $id);
     $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
     $content = $display->build($entity);
     $this->setRawContent($renderer->renderRoot($content));
     $this->assertRaw($value, 'Value is displayed unfiltered');
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:71,代码来源:TextFieldTest.php

示例4: postSave

 /**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     // Clear the static caches of filter_formats() and others.
     filter_formats_reset();
     if (!$update && !$this->isSyncing()) {
         // Default configuration of modules and installation profiles is allowed
         // to specify a list of user roles to grant access to for the new format;
         // apply the defined user role permissions when a new format is inserted
         // and has a non-empty $roles property.
         // Note: user_role_change_permissions() triggers a call chain back into
         // \Drupal\filter\FilterPermissions::permissions() and lastly
         // filter_formats(), so its cache must be reset upfront.
         if (($roles = $this->get('roles')) && ($permission = $this->getPermissionName())) {
             foreach (user_roles() as $rid => $name) {
                 $enabled = in_array($rid, $roles, TRUE);
                 user_role_change_permissions($rid, array($permission => $enabled));
             }
         }
     }
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:24,代码来源:FilterFormat.php

示例5: resetFilterCaches

 /**
  * Rebuilds text format and permission caches in the thread running the tests.
  */
 protected function resetFilterCaches()
 {
     filter_formats_reset();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:7,代码来源:FilterFormatAccessTest.php

示例6: testFilterAdmin

 /**
  * Tests filter administration functionality.
  */
 function testFilterAdmin()
 {
     $first_filter = 'filter_autop';
     $second_filter = 'filter_url';
     $basic = 'basic_html';
     $restricted = 'restricted_html';
     $full = 'full_html';
     $plain = 'plain_text';
     // Check that the fallback format exists and cannot be disabled.
     $this->assertTrue($plain == filter_fallback_format(), 'The fallback format is set to plain text.');
     $this->drupalGet('admin/config/content/formats');
     $this->assertNoRaw('admin/config/content/formats/manage/' . $plain . '/disable', 'Disable link for the fallback format not found.');
     $this->drupalGet('admin/config/content/formats/manage/' . $plain . '/disable');
     $this->assertResponse(403, 'The fallback format cannot be disabled.');
     // Verify access permissions to Full HTML format.
     $full_format = entity_load('filter_format', $full);
     $this->assertTrue($full_format->access('use', $this->adminUser), 'Admin user may use Full HTML.');
     $this->assertFalse($full_format->access('use', $this->webUser), 'Web user may not use Full HTML.');
     // Add an additional tag.
     $edit = array();
     $edit['filters[filter_html][settings][allowed_html]'] = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>';
     $this->drupalPostForm('admin/config/content/formats/manage/' . $restricted, $edit, t('Save configuration'));
     $this->assertUrl('admin/config/content/formats');
     $this->drupalGet('admin/config/content/formats/manage/' . $restricted);
     $this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], 'Allowed HTML tag added.');
     $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array(':first' => 'filters[' . $first_filter . '][weight]', ':second' => 'filters[' . $second_filter . '][weight]'));
     $this->assertTrue(!empty($elements), 'Order confirmed in admin interface.');
     // Reorder filters.
     $edit = array();
     $edit['filters[' . $second_filter . '][weight]'] = 1;
     $edit['filters[' . $first_filter . '][weight]'] = 2;
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertUrl('admin/config/content/formats');
     $this->drupalGet('admin/config/content/formats/manage/' . $restricted);
     $this->assertFieldByName('filters[' . $second_filter . '][weight]', 1, 'Order saved successfully.');
     $this->assertFieldByName('filters[' . $first_filter . '][weight]', 2, 'Order saved successfully.');
     $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array(':first' => 'filters[' . $second_filter . '][weight]', ':second' => 'filters[' . $first_filter . '][weight]'));
     $this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.');
     $filter_format = entity_load('filter_format', $restricted);
     foreach ($filter_format->filters() as $filter_name => $filter) {
         if ($filter_name == $second_filter || $filter_name == $first_filter) {
             $filters[] = $filter_name;
         }
     }
     // Ensure that the second filter is now before the first filter.
     $this->assertEqual($filter_format->filters($second_filter)->weight + 1, $filter_format->filters($first_filter)->weight, 'Order confirmed in configuration.');
     // Add format.
     $edit = array();
     $edit['format'] = Unicode::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->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
     $this->assertUrl('admin/config/content/formats');
     $this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), 'New filter created.');
     filter_formats_reset();
     $format = entity_load('filter_format', $edit['format']);
     $this->assertNotNull($format, 'Format found in database.');
     $this->drupalGet('admin/config/content/formats/manage/' . $format->id());
     $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', '', 'Role found.');
     $this->assertFieldByName('filters[' . $second_filter . '][status]', '', 'Line break filter found.');
     $this->assertFieldByName('filters[' . $first_filter . '][status]', '', 'Url filter found.');
     // Disable new filter.
     $this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', array(), t('Disable'));
     $this->assertUrl('admin/config/content/formats');
     $this->assertRaw(t('Disabled text format %format.', array('%format' => $edit['name'])), 'Format successfully disabled.');
     // Allow authenticated users on full HTML.
     $format = entity_load('filter_format', $full);
     $edit = array();
     $edit['roles[' . RoleInterface::ANONYMOUS_ID . ']'] = 0;
     $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
     $this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
     $this->assertUrl('admin/config/content/formats');
     $this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->label())), 'Full HTML format successfully updated.');
     // Switch user.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('node/add/page');
     $this->assertRaw('<option value="' . $full . '">Full HTML</option>', 'Full HTML filter accessible.');
     // Use basic HTML and see if it removes tags that are not allowed.
     $body = '<em>' . $this->randomMachineName() . '</em>';
     $extra_text = 'text';
     $text = $body . '<random>' . $extra_text . '</random>';
     $edit = array();
     $edit['title[0][value]'] = $this->randomMachineName();
     $edit['body[0][value]'] = $text;
     $edit['body[0][format]'] = $basic;
     $this->drupalPostForm('node/add/page', $edit, t('Save'));
     $this->assertRaw(t('Basic page %title has been created.', array('%title' => $edit['title[0][value]'])), 'Filtered node created.');
     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->assertTrue($node, 'Node found in database.');
     $this->drupalGet('node/' . $node->id());
     $this->assertRaw($body . $extra_text, 'Filter removed invalid tag.');
     // Use plain text and see if it escapes all tags, whether allowed or not.
     // In order to test plain text, we have to enable the hidden variable for
     // "show_fallback_format", which displays plain text in the format list.
     $this->config('filter.settings')->set('always_show_fallback_choice', TRUE)->save();
//.........这里部分代码省略.........
开发者ID:brstde,项目名称:gap1,代码行数:101,代码来源:FilterAdminTest.php

示例7: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     filter_formats_reset();
     drupal_set_message($this->t('The text format ordering has been saved.'));
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:9,代码来源:FilterFormatListBuilder.php


注:本文中的filter_formats_reset函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。