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

8.0.x
webchick 2014-03-07 12:44:44 -08:00
parent 2859313ac6
commit 2a1d8d14f7
6 changed files with 40 additions and 21 deletions

View File

@ -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';
}
}

View File

@ -64,17 +64,10 @@ class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface,
* {@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) {

View File

@ -286,7 +286,7 @@ class Internal extends CKEditorPluginBase {
*/
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;

View File

@ -127,6 +127,9 @@ class CKEditorTest extends DrupalUnitTestBase {
$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 @@ class CKEditorTest extends DrupalUnitTestBase {
// 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 @@ class CKEditorTest extends DrupalUnitTestBase {
),
));
$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,

View File

@ -10,8 +10,15 @@ namespace Drupal\editor;
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();
}

View File

@ -15,7 +15,7 @@ use Drupal\editor\EditorInterface;
*
* @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 @@ class Editor extends ConfigEntityBase implements EditorInterface {
$this->settings += $default_settings;
}
/**
* {@inheritdoc}
*/
public function getFilterFormat() {
if (!$this->filterFormat) {
$this->filterFormat = \Drupal::entityManager()->getStorageController('filter_format')->load($this->format);
}
return $this->filterFormat;
}
}