本文整理汇总了PHP中filter_formats函数的典型用法代码示例。如果您正苦于以下问题:PHP filter_formats函数的具体用法?PHP filter_formats怎么用?PHP filter_formats使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filter_formats函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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.');
}
示例2: setUp
protected function setUp()
{
parent::setUp();
// Enable user signatures.
\Drupal::config('user.settings')->set('signatures', 1)->save();
// Create Basic page node type.
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
// Add a comment field with commenting enabled by default.
$this->container->get('comment.manager')->addDefaultField('node', 'page');
// Prefetch and create text formats.
$this->filtered_html_format = entity_create('filter_format', array('format' => 'filtered_html_format', 'name' => 'Filtered HTML', 'weight' => -1, 'filters' => array('filter_html' => array('module' => 'filter', 'status' => TRUE, 'settings' => array('allowed_html' => '<a> <em> <strong>')))));
$this->filtered_html_format->save();
$this->full_html_format = entity_create('filter_format', array('format' => 'full_html', 'name' => 'Full HTML'));
$this->full_html_format->save();
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($this->filtered_html_format->getPermissionName()));
// Create regular and administrative users.
$this->web_user = $this->drupalCreateUser(array('post comments'));
$admin_permissions = array('post comments', 'administer comments', 'administer user form display', 'administer account settings');
foreach (filter_formats() as $format) {
if ($permission = $format->getPermissionName()) {
$admin_permissions[] = $permission;
}
}
$this->admin_user = $this->drupalCreateUser($admin_permissions);
}
示例3: getSettableOptions
/**
* {@inheritdoc}
*/
public function getSettableOptions(AccountInterface $account = NULL)
{
// @todo: Avoid calling functions but move to injected dependencies.
return array_map(function ($format) {
return $format->label();
}, filter_formats($account));
}
示例4: createTerm
/**
* Returns a new term with random properties in vocabulary $vid.
*
* @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary
* The vocabulary object.
* @param array $values
* (optional) An array of values to set, keyed by property name. If the
* entity type has bundles, the bundle key has to be specified.
*
* @return \Drupal\taxonomy\Entity\Term
* The new taxonomy term object.
*/
function createTerm(Vocabulary $vocabulary, $values = array())
{
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = Term::create($values + ['name' => $this->randomMachineName(), 'description' => ['value' => $this->randomMachineName(), 'format' => $format->id()], 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
$term->save();
return $term;
}
示例5: getFormat
/**
* Get a text format object given its machine name.
*
* @param string $format_name
* Text format machine name.
* @param bool $reset
* TRUE to reset filter formats cache.
*
* @return object|bool
* Text format object or FALSE.
*/
public function getFormat($format_name, $reset = FALSE)
{
if ($reset) {
filter_formats_reset();
}
$formats = filter_formats();
return isset($formats[$format_name]) ? (object) $formats[$format_name] : FALSE;
}
示例6: createTerm
/**
* Returns a new term with random properties in vocabulary $vid.
*
* @return \Drupal\taxonomy\Term
* The created taxonomy term.
*/
protected function createTerm()
{
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'format' => $format->format, 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$term->save();
return $term;
}
示例7: buildConfigurationForm
public function buildConfigurationForm(array &$form, array &$form_state)
{
global $user;
$options = array();
foreach (filter_formats($user) as $id => $format) {
$options[$id] = $format->label();
}
$form['format'] = array('#type' => 'select', '#title' => $this->t('Description format'), '#options' => $options, '#default_value' => $this->configuration['format']);
}
示例8: buildConfigurationForm
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state)
{
$options = [];
foreach (filter_formats($this->user) as $id => $format) {
$options[$id] = $format->label();
}
$form['format'] = ['#type' => 'select', '#title' => $this->t('Filter format'), '#options' => $options, '#default_value' => $this->configuration['format']];
return $form;
}
示例9: findDependencies
/**
* Overrides Drupal\configuration\Config\Configuration::findDependencies().
*/
public function findDependencies()
{
$format = $this->getIdentifier();
$formats = filter_formats();
if (isset($formats[$format])) {
$filter_format = ConfigurationManagement::createConfigurationInstance('text_format.' . $format);
$this->addToDependencies($filter_format);
}
parent::findDependencies();
}
示例10: getAttachments
/**
* Implements QuickEditInPlaceEditorInterface::getAttachments().
*
* @see Drupal 8's \Drupal\editor\Plugin\quickedit\editor\Editor::getAttachments().
*/
public function getAttachments()
{
global $user;
// Get a list of formats to which the current user has access.
$formats = filter_formats($user);
// Get filter configuration information for the available formats.
$settings = editor_get_attached($formats);
// Also include editor.module's formatted text editor.
$settings['library'][] = array('editor', 'quickedit.inPlaceEditor.formattedText');
$settings['js'][] = array('type' => 'setting', 'data' => array('quickedit' => array('ckeditor' => array('basePath' => base_path() . drupal_get_path('module', 'editor_ckeditor') . '/lib/ckeditor/'))));
return $settings;
}
示例11: bootstrap_subtheme_filter_tips
/**
* Overrides theme_filter_tips().
*/
function bootstrap_subtheme_filter_tips($variables)
{
global $user;
drupal_set_title('');
// Create a place holder for the tabs.
$build['tabs'] = array('#theme' => 'item_list', '#items' => array(), '#attributes' => array('class' => array('nav', 'nav-tabs'), 'role' => 'tablist'));
// Create a placeholder for the panes.
$build['panes'] = array('#theme_wrappers' => array('container'), '#attributes' => array('class' => array('tab-content')));
$format_id = arg(2);
$current_path = current_path();
$formats = filter_formats($user);
$filter_info = filter_get_filters();
foreach ($formats as $format) {
$tab = array('data' => array('#type' => 'link', '#title' => check_plain($format->name), '#href' => $current_path, '#attributes' => array('role' => 'tab', 'data-toggle' => 'tab'), '#options' => array('fragment' => $format->format)));
if (!$format_id || $format_id === $format->format) {
$tab['class'][] = 'active';
$format_id = $format->format;
}
$build['tabs']['#items'][] = $tab;
// Retrieve each filter in the format.
$tips = array();
$filters = filter_list_format($format->format);
foreach ($filters as $name => $filter) {
if ($filter->status && isset($filter_info[$name]['tips callback']) && is_callable($filter_info[$name]['tips callback'])) {
$tip = $filter_info[$name]['tips callback']($filter, $format, TRUE);
if (isset($tip)) {
$tips[] = $tip;
}
}
}
// Construct the pane.
$pane = array('#theme_wrappers' => array('container'), '#attributes' => array('class' => array('tab-pane', 'fade'), 'id' => $format->format));
if (count($tips) === 1) {
$pane['list'] = array('#markup' => $tips[0]);
} else {
$pane['list'] = array('#theme' => 'item_list', '#items' => $tips);
}
if ($format_id === $format->format) {
$pane['#attributes']['class'][] = 'active';
$pane['#attributes']['class'][] = 'in';
$format_id = $format->format;
}
$build['panes'][] = $pane;
}
return drupal_render($build);
}
示例12: mass_add_terms
/**
* Helper function for mass adding of terms.
*
* @param $input
* The textual input with terms. Each line contains a single term. Child term
* can be prefixed with a dash '-' (one dash for each level). Term names
* starting with a dash and should not become a child term need to be wrapped
* in quotes.
* @param $vid
* The vocabulary id.
* @param int $parents
* An array of parent term ids for the new inserted terms. Can be 0.
* @param $term_names_too_long
* Return value that is used to indicate that some term names were too long
* and truncated to 255 characters.
*
* @return An array of the newly inserted term objects
*/
public static function mass_add_terms($input, $vid, $parents, &$term_names_too_long = array())
{
$new_terms = array();
$terms = explode("\n", str_replace("\r", '', $input));
$parents = count($parents) ? $parents : 0;
// Stores the current lineage of newly inserted terms.
$last_parents = array();
foreach ($terms as $name) {
if (empty($name)) {
continue;
}
$matches = array();
// Child term prefixed with one or more dashes
if (preg_match('/^(-){1,}/', $name, $matches)) {
$depth = strlen($matches[0]);
$name = substr($name, $depth);
$current_parents = isset($last_parents[$depth - 1]) ? array($last_parents[$depth - 1]->id()) : 0;
} elseif (preg_match('/^\\"(-){1,}.*\\"/', $name, $matches)) {
$name = substr($name, 1, -1);
$depth = 0;
$current_parents = $parents;
} else {
$depth = 0;
$current_parents = $parents;
}
// Truncate long string names that will cause database exceptions.
if (strlen($name) > 255) {
$term_names_too_long[] = $name;
$name = substr($name, 0, 255);
}
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$values = ['name' => $name, 'format' => $format->id(), 'vid' => $vid, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED];
if (!empty($current_parents)) {
foreach ($current_parents as $p) {
$values['parent'][] = array('target_id' => $p);
}
}
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create($values);
$term->save();
$new_terms[] = $term;
$last_parents[$depth] = $term;
}
return $new_terms;
}
示例13: createTerm
/**
* Creates and saves a new term with in vocabulary $vid.
*
* @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary
* The vocabulary object.
* @param array $values
* (optional) An array of values to set, keyed by property name. If the
* entity type has bundles, the bundle key has to be specified.
*
* @return \Drupal\taxonomy\Entity\Term
* The new taxonomy term object.
*/
private function createTerm(Vocabulary $vocabulary, $values = array()) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$termStorage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$term = $termStorage->create($values + array(
'name' => $this->randomMachineName(),
'description' => array(
'value' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->id(),
),
'vid' => $vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$term->save();
return $term;
}
示例14: createTerm
/**
* @param $contentTypes
* @param $limit
* @param $titleWords
* @param $timeRange
*
* @return array
*/
public function createTerm($vocabularies, $limit, $nameWords)
{
$terms = [];
$values = [];
for ($i = 0; $i < $limit; $i++) {
$vocabulary = Vocabulary::load($vocabularies[array_rand($vocabularies)]);
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', $values + array('name' => $this->getRandom()->sentences(mt_rand(1, $nameWords), true), 'description' => array('value' => $this->getRandom()->sentences(), 'format' => $format->id()), 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
try {
$term->save();
$terms['success'][] = ['tid' => $term->id(), 'vocabulary' => $vocabulary->get('name'), 'name' => $term->getName()];
} catch (\Exception $error) {
$terms['error'][] = ['vocabulary' => $vocabularies[$vocabulary], 'name' => $term->getName(), 'error' => $error->getMessage()];
}
}
return $terms;
}
示例15: alterDependencies
/**
* Overrides Drupal\configuration\Config\Configuration::alterDependencies().
*/
public static function alterDependencies(Configuration $config)
{
if ($config->getComponent() == 'permission') {
// Generate permissions for each text format. Warn the administrator that any
// of them are potentially unsafe.
foreach (filter_formats() as $format) {
$permission = filter_permission_name($format);
if (!empty($permission)) {
$data = $config->getData();
if ($permission == $data['permission']) {
$text_format = ConfigurationManagement::createConfigurationInstance('text_format.' . $format->format);
$config->addToDependencies($text_format);
break;
}
}
}
}
}