本文整理汇总了PHP中Drupal\editor\Entity\Editor::hasAssociatedFilterFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Editor::hasAssociatedFilterFormat方法的具体用法?PHP Editor::hasAssociatedFilterFormat怎么用?PHP Editor::hasAssociatedFilterFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\editor\Entity\Editor
的用法示例。
在下文中一共展示了Editor::hasAssociatedFilterFormat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isEnabled
/**
* {@inheritdoc}
*/
function isEnabled(Editor $editor)
{
if (!$editor->hasAssociatedFilterFormat()) {
return FALSE;
}
// Automatically enable this plugin if the text format associated with this
// text editor uses the filter_align or filter_caption filter and the
// DrupalImage button is enabled.
$format = $editor->getFilterFormat();
if ($format->filters('filter_align')->status || $format->filters('filter_caption')->status) {
$enabled = FALSE;
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
foreach ($group['items'] as $button) {
if ($button === 'DrupalImage') {
$enabled = TRUE;
}
}
}
}
return $enabled;
}
return FALSE;
}
示例2: generateACFSettings
/**
* Builds the ACF part of the CKEditor JS settings.
*
* This ensures that CKEditor obeys the HTML restrictions defined by Drupal's
* filter system, by enabling CKEditor's Advanced Content Filter (ACF)
* functionality: http://ckeditor.com/blog/CKEditor-4.1-RC-Released.
*
* @see getConfig()
*
* @param \Drupal\editor\Entity\Editor $editor
* A configured text editor object.
*
* @return array
* An array with two values:
* - the first value is the "allowedContent" setting: a well-formatted array
* or TRUE. The latter indicates that anything is allowed.
* - the second value is the "disallowedContent" setting: a well-formatted
* array or FALSE. The latter indicates that nothing is disallowed.
*/
protected function generateACFSettings(Editor $editor)
{
// When no text format is associated yet, assume nothing is disallowed, so
// set allowedContent to true.
if (!$editor->hasAssociatedFilterFormat()) {
return TRUE;
}
$format = $editor->getFilterFormat();
$filter_types = $format->getFilterTypes();
// When nothing is disallowed, set allowedContent to true.
if (!in_array(FilterInterface::TYPE_HTML_RESTRICTOR, $filter_types)) {
return array(TRUE, FALSE);
} else {
$get_attribute_values = function ($attribute_values, $allowed_values) {
$values = array_keys(array_filter($attribute_values, function ($value) use($allowed_values) {
if ($allowed_values) {
return $value !== FALSE;
} else {
return $value === FALSE;
}
}));
if (count($values)) {
return implode(',', $values);
} else {
return NULL;
}
};
$html_restrictions = $format->getHtmlRestrictions();
// When all HTML is allowed, also set allowedContent to true and
// disallowedContent to false.
if ($html_restrictions === FALSE) {
return array(TRUE, FALSE);
}
$allowed = array();
$disallowed = array();
if (isset($html_restrictions['forbidden_tags'])) {
foreach ($html_restrictions['forbidden_tags'] as $tag) {
$disallowed[$tag] = TRUE;
}
}
foreach ($html_restrictions['allowed'] as $tag => $attributes) {
// Tell CKEditor the tag is allowed, but no attributes.
if ($attributes === FALSE) {
$allowed[$tag] = array('attributes' => FALSE, 'styles' => FALSE, 'classes' => FALSE);
} elseif ($attributes === TRUE) {
$allowed[$tag] = array('attributes' => TRUE, 'styles' => TRUE, 'classes' => TRUE);
// We've just marked that any value for the "style" and "class"
// attributes is allowed. However, that may not be the case: the "*"
// tag may still apply restrictions.
// Since CKEditor's ACF follows the following principle:
// Once validated, an element or its property cannot be
// invalidated by another rule.
// That means that the most permissive setting wins. Which means that
// it will still be allowed by CKEditor to e.g. define any style, no
// matter what the "*" tag's restrictions may be. If there's a setting
// for either the "style" or "class" attribute, it cannot possibly be
// more permissive than what was set above. Hence: inherit from the
// "*" tag where possible.
if (isset($html_restrictions['allowed']['*'])) {
$wildcard = $html_restrictions['allowed']['*'];
if (isset($wildcard['style'])) {
if (!is_array($wildcard['style'])) {
$allowed[$tag]['styles'] = $wildcard['style'];
} else {
$allowed_styles = $get_attribute_values($wildcard['style'], TRUE);
if (isset($allowed_styles)) {
$allowed[$tag]['styles'] = $allowed_styles;
} else {
unset($allowed[$tag]['styles']);
}
}
}
if (isset($wildcard['class'])) {
if (!is_array($wildcard['class'])) {
$allowed[$tag]['classes'] = $wildcard['class'];
} else {
$allowed_classes = $get_attribute_values($wildcard['class'], TRUE);
if (isset($allowed_classes)) {
$allowed[$tag]['classes'] = $allowed_classes;
} else {
unset($allowed[$tag]['classes']);
//.........这里部分代码省略.........
示例3: isEnabled
/**
* {@inheritdoc}
*/
public function isEnabled(Editor $editor)
{
$enabled = FALSE;
if (!$editor->hasAssociatedFilterFormat()) {
return $enabled;
}
$editor_settings = $editor->getSettings();
$plugin_settings = !empty($editor_settings['plugins']['embridgeimage']['embridge_image_upload']) ? $editor_settings['plugins']['embridgeimage']['embridge_image_upload'] : [];
if (!empty($plugin_settings['enabled']) && $plugin_settings['enabled']) {
$enabled = TRUE;
}
return $enabled;
}