3 namespace Drupal\editor\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\editor\EditorInterface;
9 * Defines the configured text editor entity.
13 * label = @Translation("Text Editor"),
15 * "access" = "Drupal\editor\EditorAccessControlHandler",
28 class Editor extends ConfigEntityBase implements EditorInterface {
31 * The machine name of the text format with which this configured text editor
36 * @see getFilterFormat()
41 * The name (plugin ID) of the text editor.
48 * The structured array of text editor plugin-specific settings.
52 protected $settings = [];
55 * The structured array of image upload settings.
59 protected $image_upload = [];
62 * The filter format this text editor is associated with.
64 * @var \Drupal\filter\FilterFormatInterface
66 protected $filterFormat;
69 * @var \Drupal\Component\Plugin\PluginManagerInterface
71 protected $editorPluginManager;
76 public function id() {
83 public function __construct(array $values, $entity_type) {
84 parent::__construct($values, $entity_type);
86 $plugin = $this->editorPluginManager()->createInstance($this->editor);
87 $this->settings += $plugin->getDefaultSettings();
93 public function label() {
94 return $this->getFilterFormat()->label();
100 public function calculateDependencies() {
101 parent::calculateDependencies();
102 // Create a dependency on the associated FilterFormat.
103 $this->addDependency('config', $this->getFilterFormat()->getConfigDependencyName());
104 // @todo use EntityWithPluginCollectionInterface so configuration between
105 // config entity and dependency on provider is managed automatically.
106 $definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition();
107 $this->addDependency('module', $definition['provider']);
114 public function hasAssociatedFilterFormat() {
115 return $this->format !== NULL;
121 public function getFilterFormat() {
122 if (!$this->filterFormat) {
123 $this->filterFormat = \Drupal::entityManager()->getStorage('filter_format')->load($this->format);
125 return $this->filterFormat;
129 * Returns the editor plugin manager.
131 * @return \Drupal\Component\Plugin\PluginManagerInterface
133 protected function editorPluginManager() {
134 if (!$this->editorPluginManager) {
135 $this->editorPluginManager = \Drupal::service('plugin.manager.editor');
138 return $this->editorPluginManager;
144 public function getEditor() {
145 return $this->editor;
151 public function setEditor($editor) {
152 $this->editor = $editor;
159 public function getSettings() {
160 return $this->settings;
166 public function setSettings(array $settings) {
167 $this->settings = $settings;
174 public function getImageUploadSettings() {
175 return $this->image_upload;
181 public function setImageUploadSettings(array $image_upload_settings) {
182 $this->image_upload = $image_upload_settings;