Commit 2a1d8d14 authored by webchick's avatar webchick

Issue #2204129 by Wim Leers, tim.plunkett: Store the filter format on the...

Issue #2204129 by Wim Leers, tim.plunkett: Store the filter format on the editor entity during runtime.
parent 2859313a
......@@ -48,17 +48,10 @@ function ckeditor_theme() {
* Implements hook_ckeditor_css_alter().
*/
function ckeditor_ckeditor_css_alter(array &$css, Editor $editor) {
$filters = array();
if (!empty($editor->format)) {
$filters = entity_load('filter_format', $editor->format)
->filters()
->getAll();
}
// Add the filter caption CSS if the text format associated with this text
// editor uses the filter_caption filter. This is used by the included
// CKEditor DrupalImageCaption plugin.
if (isset($filters['filter_caption']) && $filters['filter_caption']->status) {
if ($editor->getFilterFormat()->filters('filter_caption')->status) {
$css[] = drupal_get_path('module', 'filter') . '/css/filter.caption.css';
}
}
......
......@@ -64,17 +64,10 @@ public function getConfig(Editor $editor) {
* {@inheritdoc}
*/
function isEnabled(Editor $editor) {
$filters = array();
if (!empty($editor->format)) {
$filters = entity_load('filter_format', $editor->format)
->filters()
->getAll();
}
// Automatically enable this plugin if the text format associated with this
// text editor uses the filter_caption filter and the DrupalImage button is
// enabled.
if (isset($filters['filter_caption']) && $filters['filter_caption']->status) {
if ($editor->getFilterFormat()->filters('filter_caption')->status) {
$enabled = FALSE;
foreach ($editor->settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
......
......@@ -286,7 +286,7 @@ protected function generateFormatTagsSetting(Editor $editor) {
*/
protected function generateAllowedContentSetting(Editor $editor) {
// When nothing is disallowed, set allowedContent to true.
$format = entity_load('filter_format', $editor->format);
$format = $editor->getFilterFormat();
$filter_types = $format->getFilterTypes();
if (!in_array(FilterInterface::TYPE_HTML_RESTRICTOR, $filter_types)) {
return TRUE;
......
......@@ -127,6 +127,9 @@ function testGetJSSettings() {
$format = entity_load('filter_format', 'filtered_html');
$format->filters('filter_html')->settings['allowed_html'] .= '<pre> <h3>';
$format->save();
// $editor is a Text Editor object that has a statically cached FilterFormat
// which is now outdated. Therefore, reload it.
$editor = entity_load('editor', $editor->id());
$expected_config['allowedContent']['pre'] = array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE);
$expected_config['allowedContent']['h3'] = array('attributes' => TRUE, 'styles' => FALSE, 'classes' => TRUE);
$expected_config['format_tags'] = 'p;h3;h4;h5;h6;pre';
......@@ -135,6 +138,9 @@ function testGetJSSettings() {
// Disable the filter_html filter: allow *all *tags.
$format->setFilterConfig('filter_html', array('status' => 0));
$format->save();
// $editor is a Text Editor object that has a statically cached FilterFormat
// which is now outdated. Therefore, reload it.
$editor = entity_load('editor', $editor->id());
$expected_config['allowedContent'] = TRUE;
$expected_config['format_tags'] = 'p;h1;h2;h3;h4;h5;h6;pre';
$this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
......@@ -168,6 +174,9 @@ function testGetJSSettings() {
),
));
$format->save();
// $editor is a Text Editor object that has a statically cached FilterFormat
// which is now outdated. Therefore, reload it.
$editor = entity_load('editor', $editor->id());
$expected_config['allowedContent'] = array(
'p' => array(
'attributes' => TRUE,
......
......@@ -10,8 +10,15 @@
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface defining a editor entity.
* Provides an interface defining a text editor entity.
*/
interface EditorInterface extends ConfigEntityInterface {
/**
* Returns the filter format this text editor is associated with.
*
* @return \Drupal\filter\FilterFormatInterface
*/
public function getFilterFormat();
}
......@@ -15,7 +15,7 @@
*
* @ConfigEntityType(
* id = "editor",
* label = @Translation("Editor"),
* label = @Translation("Text Editor"),
* entity_keys = {
* "id" = "format"
* }
......@@ -53,14 +53,21 @@ class Editor extends ConfigEntityBase implements EditorInterface {
public $image_upload = array();
/**
* Overrides Drupal\Core\Entity\Entity::id().
* The filter format this text editor is associated with.
*
* @var \Drupal\filter\FilterFormatInterface
*/
protected $filterFormat;
/**
* {@inheritdoc}
*/
public function id() {
return $this->format;
}
/**
* Overrides Drupal\Core\Entity\Entity::__construct()
* {@inheritdoc}
*/
public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
......@@ -75,4 +82,14 @@ public function __construct(array $values, $entity_type) {
$this->settings += $default_settings;
}
/**
* {@inheritdoc}
*/
public function getFilterFormat() {
if (!$this->filterFormat) {
$this->filterFormat = \Drupal::entityManager()->getStorageController('filter_format')->load($this->format);
}
return $this->filterFormat;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment