Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
7.69% |
1 / 13 |
CRAP | |
18.52% |
5 / 27 |
Editor | |
0.00% |
0 / 1 |
|
7.69% |
1 / 13 |
136.72 | |
18.52% |
5 / 27 |
id | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
label | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
calculateDependencies | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
hasAssociatedFilterFormat | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
getFilterFormat | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
editorPluginManager | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
getEditor | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
setEditor | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
getSettings | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
setSettings | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
getImageUploadSettings | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
setImageUploadSettings | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\editor\Entity\Editor. | |
*/ | |
namespace Drupal\editor\Entity; | |
use Drupal\Core\Config\Entity\ConfigEntityBase; | |
use Drupal\editor\EditorInterface; | |
/** | |
* Defines the configured text editor entity. | |
* | |
* @ConfigEntityType( | |
* id = "editor", | |
* label = @Translation("Text Editor"), | |
* entity_keys = { | |
* "id" = "format" | |
* }, | |
* config_export = { | |
* "format", | |
* "editor", | |
* "settings", | |
* "image_upload", | |
* } | |
* ) | |
*/ | |
class Editor extends ConfigEntityBase implements EditorInterface { | |
/** | |
* The machine name of the text format with which this configured text editor | |
* is associated. | |
* | |
* @var string | |
* | |
* @see getFilterFormat() | |
*/ | |
protected $format; | |
/** | |
* The name (plugin ID) of the text editor. | |
* | |
* @var string | |
*/ | |
protected $editor; | |
/** | |
* The structured array of text editor plugin-specific settings. | |
* | |
* @var array | |
*/ | |
protected $settings = array(); | |
/** | |
* The structured array of image upload settings. | |
* | |
* @var array | |
*/ | |
protected $image_upload = array(); | |
/** | |
* The filter format this text editor is associated with. | |
* | |
* @var \Drupal\filter\FilterFormatInterface | |
*/ | |
protected $filterFormat; | |
/** | |
* @var \Drupal\Component\Plugin\PluginManagerInterface | |
*/ | |
protected $editorPluginManager; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function id() { | |
return $this->format; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct(array $values, $entity_type) { | |
parent::__construct($values, $entity_type); | |
$plugin = $this->editorPluginManager()->createInstance($this->editor); | |
$this->settings += $plugin->getDefaultSettings(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function label() { | |
return $this->getFilterFormat()->label(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function calculateDependencies() { | |
parent::calculateDependencies(); | |
// Create a dependency on the associated FilterFormat. | |
$this->addDependency('config', $this->getFilterFormat()->getConfigDependencyName()); | |
// @todo use EntityWithPluginCollectionInterface so configuration between | |
// config entity and dependency on provider is managed automatically. | |
$definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition(); | |
$this->addDependency('module', $definition['provider']); | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function hasAssociatedFilterFormat() { | |
return $this->format !== NULL; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getFilterFormat() { | |
if (!$this->filterFormat) { | |
$this->filterFormat = \Drupal::entityManager()->getStorage('filter_format')->load($this->format); | |
} | |
return $this->filterFormat; | |
} | |
/** | |
* Returns the editor plugin manager. | |
* | |
* @return \Drupal\Component\Plugin\PluginManagerInterface | |
*/ | |
protected function editorPluginManager() { | |
if (!$this->editorPluginManager) { | |
$this->editorPluginManager = \Drupal::service('plugin.manager.editor'); | |
} | |
return $this->editorPluginManager; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getEditor() { | |
return $this->editor; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setEditor($editor) { | |
$this->editor = $editor; | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getSettings() { | |
return $this->settings; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setSettings(array $settings) { | |
$this->settings = $settings; | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getImageUploadSettings() { | |
return $this->image_upload; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setImageUploadSettings(array $image_upload_settings) { | |
$this->image_upload = $image_upload_settings; | |
return $this; | |
} | |
} |