本文整理汇总了PHP中Drupal\editor\Entity\Editor类的典型用法代码示例。如果您正苦于以下问题:PHP Editor类的具体用法?PHP Editor怎么用?PHP Editor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Editor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
{
$editor_settings = $editor->getSettings();
$plugin_settings = NestedArray::getValue($editor_settings, ['plugins', 'video_embed', 'defaults', 'children']);
$settings = $plugin_settings ?: [];
$form['defaults'] = ['#title' => $this->t('Default Settings'), '#type' => 'fieldset', '#tree' => TRUE, 'children' => Video::mockInstance($settings)->settingsForm([], new FormState())];
return $form;
}
示例3: getJSSettings
/**
* {@inheritdoc}
*/
public function getJSSettings(EditorEntity $editor)
{
$js_settings = array();
$settings = $editor->getSettings();
if ($settings['stumpy_arms']) {
$js_settings['doMyArmsLookStumpy'] = TRUE;
}
return $js_settings;
}
示例4: getJSSettings
/**
* {@inheritdoc}
*/
function getJSSettings(EditorEntity $editor)
{
$js_settings = array();
$settings = $editor->getSettings();
if ($settings['ponies too']) {
$js_settings['ponyModeEnabled'] = TRUE;
}
return $js_settings;
}
示例5: settingsForm
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginConfigurableInterface::settingsForm().
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
{
// Defaults.
$config = array('styles' => '');
$settings = $editor->getSettings();
if (isset($settings['plugins']['stylescombo'])) {
$config = $settings['plugins']['stylescombo'];
}
$form['styles'] = array('#title' => t('Styles'), '#title_display' => 'invisible', '#type' => 'textarea', '#default_value' => $config['styles'], '#description' => t('A list of classes that will be provided in the "Styles" dropdown. Enter one class on each line in the format: element.class|Label. Example: h1.title|Title.<br />These styles should be available in your theme\'s CSS file.'), '#attached' => array('library' => array('ckeditor/drupal.ckeditor.stylescombo.admin')), '#element_validate' => array(array($this, 'validateStylesValue')));
return $form;
}
示例6: settingsForm
/**
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginConfigurableInterface::settingsForm().
*/
function settingsForm(array $form, array &$form_state, Editor $editor)
{
// Defaults.
$config = array('ultra_llama_mode' => FALSE);
$settings = $editor->getSettings();
if (isset($settings['plugins']['llama_contextual_and_button'])) {
$config = $settings['plugins']['llama_contextual_and_button'];
}
$form['ultra_llama_mode'] = array('#title' => t('Ultra llama mode'), '#type' => 'checkbox', '#default_value' => $config['ultra_llama_mode']);
return $form;
}
示例7: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('editor');
$this->installEntitySchema('filter_format');
$this->format = FilterFormat::create(['format' => 'test_format', 'name' => $this->randomMachineName()]);
$this->format->save();
$this->editor = Editor::create(['editor' => 'ckeditor', 'format' => 'test_format', 'settings' => ['toolbar' => ['rows' => [[['name' => 'Enabled Buttons', 'items' => ['Format']]]]]]]);
$this->editor->save();
$this->ckeditorPluginManager = $this->container->get('plugin.manager.ckeditor.plugin');
}
示例8: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
{
$settings = $editor->getSettings();
$styles = $this->getStyles();
$config = \Drupal::config('codesnippet.settings');
$default_style = $config->get('style');
$languages = $config->get('languages');
asort($languages);
$form['#attached']['library'][] = 'codesnippet/codesnippet.admin';
$form['highlight_style'] = array('#type' => 'select', '#title' => 'highlight.js Style', '#description' => $this->t('Select a style to apply to all highlighted code snippets. You can preview the styles at @link.', array('@link' => \Drupal::l('https://highlightjs.org/static/demo', Url::fromUri('https://highlightjs.org/static/demo/')))), '#options' => $styles, '#default_value' => !empty($settings['plugins']['codesnippet']['highlight_style']) ? $settings['plugins']['codesnippet']['highlight_style'] : $default_style);
$form['highlight_languages'] = array('#type' => 'checkboxes', '#title' => 'Supported Languages', '#options' => $languages, '#description' => t('Enter languages you want to have as options in the editor dialog. To add a language not in this list, please see the README.txt of this module.'), '#default_value' => $settings['plugins']['codesnippet']['highlight_languages']);
return $form;
}
示例9: isEnabled
/**
* {@inheritdoc}
*/
function isEnabled(Editor $editor)
{
// Automatically enable this plugin if the Underline button is enabled.
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
if (in_array('Strike', $group['items'])) {
return TRUE;
}
}
}
return FALSE;
}
示例10: testEntityEmbedButtonMarkup
/**
* Tests the entity embed button markup.
*/
public function testEntityEmbedButtonMarkup()
{
// Ensure that the route is not accessible with text format without the
// button configured.
$this->getEmbedDialog('plain_text', 'node');
$this->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.');
// Add an empty configuration for the plain_text editor configuration.
$editor = Editor::create(['format' => 'plain_text', 'editor' => 'ckeditor']);
$editor->save();
$this->getEmbedDialog('plain_text', 'node');
$this->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.');
// Ensure that the route is accessible with a valid embed button.
// 'Node' embed button is provided by default by the module and hence the
// request must be successful.
$this->getEmbedDialog('custom_format', 'node');
$this->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.');
// Ensure form structure of the 'select' step and submit form.
$this->assertFieldByName('attributes[data-entity-id]', '', 'Entity ID/UUID field is present.');
// Check that 'Next' is a primary button.
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Next', 'Next is a primary button');
$title = $this->node->getTitle() . ' (' . $this->node->id() . ')';
$edit = ['attributes[data-entity-id]' => $title];
$this->drupalPostAjaxForm(NULL, $edit, 'op');
/*$this->drupalPostForm(NULL, $edit, 'Next');
// Ensure form structure of the 'embed' step and submit form.
$this->assertFieldByName('attributes[data-entity-embed-display]', 'Entity Embed Display plugin field is present.');
// Check that 'Embed' is a primary button.
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Embed', 'Embed is a primary button');*/
}
示例11: testEditorImageDialogAccess
/**
* Test access to the editor image dialog.
*/
public function testEditorImageDialogAccess()
{
$url = Url::fromRoute('editor.image_dialog', ['editor' => 'plain_text']);
$session = $this->assertSession();
// With no text editor, expect a 404.
$this->drupalGet($url);
$session->statusCodeEquals(404);
// With a text editor but without image upload settings, expect a 200, but
// there should not be an input[type=file].
$editor = Editor::create(['editor' => 'ckeditor', 'format' => 'plain_text', 'settings' => ['toolbar' => ['rows' => [[['name' => 'Media', 'items' => ['DrupalImage']]]]], 'plugins' => []], 'image_upload' => ['status' => FALSE, 'scheme' => 'public', 'directory' => 'inline-images', 'max_size' => '', 'max_dimensions' => ['width' => 0, 'height' => 0]]]);
$editor->save();
$this->resetAll();
$this->drupalGet($url);
$this->assertTrue($this->cssSelect('input[type=text][name="attributes[src]"]'), 'Image uploads disabled: input[type=text][name="attributes[src]"] is present.');
$this->assertFalse($this->cssSelect('input[type=file]'), 'Image uploads disabled: input[type=file] is absent.');
$session->statusCodeEquals(200);
// With image upload settings, expect a 200, and now there should be an
// input[type=file].
$editor->setImageUploadSettings(['status' => TRUE] + $editor->getImageUploadSettings())->save();
$this->resetAll();
$this->drupalGet($url);
$this->assertFalse($this->cssSelect('input[type=text][name="attributes[src]"]'), 'Image uploads enabled: input[type=text][name="attributes[src]"] is absent.');
$this->assertTrue($this->cssSelect('input[type=file]'), 'Image uploads enabled: input[type=file] is present.');
$session->statusCodeEquals(200);
}
示例12: testExistingFormat
/**
* Tests StylesCombo settings for an existing text format.
*/
function testExistingFormat()
{
$ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
$default_settings = $ckeditor->getDefaultSettings();
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/content/formats/manage/' . $this->format);
// Ensure an Editor config entity exists, with the proper settings.
$expected_settings = $default_settings;
$editor = Editor::load($this->format);
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Case 1: Configure the Styles plugin with different labels for each style,
// and ensure the updated settings are saved.
$this->drupalGet('admin/config/content/formats/manage/' . $this->format);
$edit = ['editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\n\n"];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
$editor = Editor::load($this->format);
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Case 2: Configure the Styles plugin with same labels for each style, and
// ensure that an error is displayed and that the updated settings are not
// saved.
$this->drupalGet('admin/config/content/formats/manage/' . $this->format);
$edit = ['editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Title\n\n"];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$this->assertRaw(t('Each style must have a unique label.'));
$expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
$editor = Editor::load($this->format);
$this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
}
示例13: testManager
/**
* Tests the configurable text editor manager.
*/
public function testManager()
{
$this->editorManager = $this->container->get('plugin.manager.editor');
// Case 1: no text editor available:
// - listOptions() should return an empty list of options
// - getAttachments() should return an empty #attachments array (and not
// a JS settings structure that is empty)
$this->assertIdentical(array(), $this->editorManager->listOptions(), 'When no text editor is enabled, the manager works correctly.');
$this->assertIdentical(array(), $this->editorManager->getAttachments(array()), 'No attachments when no text editor is enabled and retrieving attachments for zero text formats.');
$this->assertIdentical(array(), $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'No attachments when no text editor is enabled and retrieving attachments for multiple text formats.');
// Enable the Text Editor Test module, which has the Unicorn Editor and
// clear the editor manager's cache so it is picked up.
$this->enableModules(array('editor_test'));
$this->editorManager = $this->container->get('plugin.manager.editor');
$this->editorManager->clearCachedDefinitions();
// Case 2: a text editor available.
$this->assertIdentical('Unicorn Editor', (string) $this->editorManager->listOptions()['unicorn'], 'When some text editor is enabled, the manager works correctly.');
// Case 3: a text editor available & associated (but associated only with
// the 'Full HTML' text format).
$unicorn_plugin = $this->editorManager->createInstance('unicorn');
$editor = Editor::create(['format' => 'full_html', 'editor' => 'unicorn']);
$editor->save();
$this->assertIdentical(array(), $this->editorManager->getAttachments(array()), 'No attachments when one text editor is enabled and retrieving attachments for zero text formats.');
$expected = array('library' => array(0 => 'editor_test/unicorn'), 'drupalSettings' => ['editor' => ['formats' => ['full_html' => ['format' => 'full_html', 'editor' => 'unicorn', 'editorSettings' => $unicorn_plugin->getJSSettings($editor), 'editorSupportsContentFiltering' => TRUE, 'isXssSafe' => FALSE]]]]);
$this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'Correct attachments when one text editor is enabled and retrieving attachments for multiple text formats.');
// Case 4: a text editor available associated, but now with its JS settings
// being altered via hook_editor_js_settings_alter().
\Drupal::state()->set('editor_test_js_settings_alter_enabled', TRUE);
$expected['drupalSettings']['editor']['formats']['full_html']['editorSettings']['ponyModeEnabled'] = FALSE;
$this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'hook_editor_js_settings_alter() works correctly.');
}
示例14: testCommentForm_2698811
/**
* Ensure comment form works with history and big_pipe modules.
*
* @see https://www.drupal.org/node/2698811
*/
public function testCommentForm_2698811()
{
$this->assertTrue($this->container->get('module_installer')->install(['comment', 'history', 'ckeditor'], TRUE), 'Installed modules.');
// Ensure an `article` node type exists.
$this->createContentType(['type' => 'article']);
$this->addDefaultCommentField('node', 'article');
// Enable CKEditor.
$format = $this->randomMachineName();
FilterFormat::create(['format' => $format, 'name' => $this->randomString(), 'weight' => 1, 'filters' => []])->save();
$settings['toolbar']['rows'] = [[['name' => 'Links', 'items' => ['DrupalLink', 'DrupalUnlink']]]];
$editor = Editor::create(['format' => $format, 'editor' => 'ckeditor']);
$editor->setSettings($settings);
$editor->save();
$admin_user = $this->drupalCreateUser(['access comments', 'post comments', 'use text format ' . $format]);
$this->drupalLogin($admin_user);
$node = $this->createNode(['type' => 'article', 'comment' => CommentItemInterface::OPEN]);
// Create some comments.
foreach (range(1, 5) as $i) {
$comment = Comment::create(['status' => CommentInterface::PUBLISHED, 'field_name' => 'comment', 'entity_type' => 'node', 'entity_id' => $node->id()]);
$comment->save();
}
$this->drupalGet($node->toUrl()->toString());
// Confirm that CKEditor loaded.
$javascript = <<<JS
(function(){
return Object.keys(CKEDITOR.instances).length > 0;
}());
JS;
$this->assertJsCondition($javascript);
}
示例15: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL)
{
// Add AJAX support.
$form['#prefix'] = '<div id="video-embed-dialog-form">';
$form['#suffix'] = '</div>';
// Ensure relevant dialog libraries are attached.
$form['#attached']['library'][] = 'editor/drupal.editor.dialog';
// Simple URL field and submit button for video URL.
$form['video_url'] = ['#type' => 'textfield', '#title' => $this->t('Video URL'), '#required' => TRUE, '#default_value' => $this->getUserInput($form_state, 'video_url')];
// If no settings are found, use the defaults configured in the filter
// formats interface.
$settings = $this->getUserInput($form_state, 'settings');
if (empty($settings) && ($editor = Editor::load($filter_format->id()))) {
$editor_settings = $editor->getSettings();
$plugin_settings = NestedArray::getValue($editor_settings, ['plugins', 'video_embed', 'defaults', 'children']);
$settings = $plugin_settings ? $plugin_settings : [];
}
// Create a settings form from the existing video formatter.
$form['settings'] = Video::mockInstance($settings)->settingsForm([], new FormState());
$form['settings']['#type'] = 'fieldset';
$form['settings']['#title'] = $this->t('Settings');
$form['actions'] = ['#type' => 'actions'];
$form['actions']['save_modal'] = ['#type' => 'submit', '#value' => $this->t('Save'), '#submit' => [], '#ajax' => ['callback' => '::ajaxSubmit', 'event' => 'click', 'wrapper' => 'video-embed-dialog-form']];
return $form;
}