当前位置: 首页>>代码示例>>PHP>>正文


PHP Editor::getFilterFormat方法代码示例

本文整理汇总了PHP中Drupal\editor\Entity\Editor::getFilterFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Editor::getFilterFormat方法的具体用法?PHP Editor::getFilterFormat怎么用?PHP Editor::getFilterFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\editor\Entity\Editor的用法示例。


在下文中一共展示了Editor::getFilterFormat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:DrupalImageCaption.php

示例2: buildForm

 /**
  * {@inheritdoc}
  *
  * @param \Drupal\editor\Entity\Editor $editor
  *   The text editor to which this dialog corresponds.
  */
 public function buildForm(array $form, FormStateInterface $form_state, Editor $editor = NULL)
 {
     // This form is special, in that the default values do not come from the
     // server side, but from the client side, from a text editor. We must cache
     // this data in form state, because when the form is rebuilt, we will be
     // receiving values from the form, instead of the values from the text
     // editor. If we don't cache it, this data will be lost.
     if (isset($form_state->getUserInput()['editor_object'])) {
         // By convention, the data that the text editor sends to any dialog is in
         // the 'editor_object' key. And the image dialog for text editors expects
         // that data to be the attributes for an <img> element.
         $image_element = $form_state->getUserInput()['editor_object'];
         $form_state->set('image_element', $image_element);
         $form_state->setCached(TRUE);
     } else {
         // Retrieve the image element's attributes from form state.
         $image_element = $form_state->get('image_element') ?: [];
     }
     $form['#tree'] = TRUE;
     $form['#attached']['library'][] = 'editor/drupal.editor.dialog';
     $form['#prefix'] = '<div id="editor-image-dialog-form">';
     $form['#suffix'] = '</div>';
     // Construct strings to use in the upload validators.
     $image_upload = $editor->getImageUploadSettings();
     if (!empty($image_upload['max_dimensions']['width']) || !empty($image_upload['max_dimensions']['height'])) {
         $max_dimensions = $image_upload['max_dimensions']['width'] . 'x' . $image_upload['max_dimensions']['height'];
     } else {
         $max_dimensions = 0;
     }
     $max_filesize = min(Bytes::toInt($image_upload['max_size']), file_upload_max_size());
     $existing_file = isset($image_element['data-entity-uuid']) ? \Drupal::entityManager()->loadEntityByUuid('file', $image_element['data-entity-uuid']) : NULL;
     $fid = $existing_file ? $existing_file->id() : NULL;
     $form['fid'] = array('#title' => $this->t('Image'), '#type' => 'managed_file', '#upload_location' => $image_upload['scheme'] . '://' . $image_upload['directory'], '#default_value' => $fid ? array($fid) : NULL, '#upload_validators' => array('file_validate_extensions' => array('gif png jpg jpeg'), 'file_validate_size' => array($max_filesize), 'file_validate_image_resolution' => array($max_dimensions)), '#required' => TRUE);
     $form['attributes']['src'] = array('#title' => $this->t('URL'), '#type' => 'textfield', '#default_value' => isset($image_element['src']) ? $image_element['src'] : '', '#maxlength' => 2048, '#required' => TRUE);
     // If the editor has image uploads enabled, show a managed_file form item,
     // otherwise show a (file URL) text form item.
     if ($image_upload['status']) {
         $form['attributes']['src']['#access'] = FALSE;
         $form['attributes']['src']['#required'] = FALSE;
     } else {
         $form['fid']['#access'] = FALSE;
         $form['fid']['#required'] = FALSE;
     }
     // The alt attribute is *required*, but we allow users to opt-in to empty
     // alt attributes for the very rare edge cases where that is valid by
     // specifying two double quotes as the alternative text in the dialog.
     // However, that *is* stored as an empty alt attribute, so if we're editing
     // an existing image (which means the src attribute is set) and its alt
     // attribute is empty, then we show that as two double quotes in the dialog.
     // @see https://www.drupal.org/node/2307647
     $alt = isset($image_element['alt']) ? $image_element['alt'] : '';
     if ($alt === '' && !empty($image_element['src'])) {
         $alt = '""';
     }
     $form['attributes']['alt'] = array('#title' => $this->t('Alternative text'), '#placeholder' => $this->t('Short description for the visually impaired'), '#type' => 'textfield', '#required' => TRUE, '#required_error' => $this->t('Alternative text is required.<br />(Only in rare cases should this be left empty. To create empty alternative text, enter <code>""</code> — two double quotes without any content).'), '#default_value' => $alt, '#maxlength' => 2048);
     // When Drupal core's filter_align is being used, the text editor may
     // offer the ability to change the alignment.
     if (isset($image_element['data-align']) && $editor->getFilterFormat()->filters('filter_align')->status) {
         $form['align'] = array('#title' => $this->t('Align'), '#type' => 'radios', '#options' => array('none' => $this->t('None'), 'left' => $this->t('Left'), 'center' => $this->t('Center'), 'right' => $this->t('Right')), '#default_value' => $image_element['data-align'] === '' ? 'none' : $image_element['data-align'], '#wrapper_attributes' => array('class' => array('container-inline')), '#attributes' => array('class' => array('container-inline')), '#parents' => array('attributes', 'data-align'));
     }
     // When Drupal core's filter_caption is being used, the text editor may
     // offer the ability to in-place edit the image's caption: show a toggle.
     if (isset($image_element['hasCaption']) && $editor->getFilterFormat()->filters('filter_caption')->status) {
         $form['caption'] = array('#title' => $this->t('Caption'), '#type' => 'checkbox', '#default_value' => $image_element['hasCaption'] === 'true', '#parents' => array('attributes', 'hasCaption'));
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['save_modal'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#submit' => array(), '#ajax' => array('callback' => '::submitForm', 'event' => 'click'));
     return $form;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:75,代码来源:EditorImageDialog.php

示例3: generateACFSettings

 /**
  * Builds the ACF part of the CKEditor JS settings.
  *
  * This ensures that CKEditor obeys the HTML restrictions defined by Drupal's
  * filter system, by enabling CKEditor's Advanced Content Filter (ACF)
  * functionality: http://ckeditor.com/blog/CKEditor-4.1-RC-Released.
  *
  * @see getConfig()
  *
  * @param \Drupal\editor\Entity\Editor $editor
  *   A configured text editor object.
  *
  * @return array
  *   An array with two values:
  *   - the first value is the "allowedContent" setting: a well-formatted array
  *     or TRUE. The latter indicates that anything is allowed.
  *   - the second value is the "disallowedContent" setting: a well-formatted
  *     array or FALSE. The latter indicates that nothing is disallowed.
  */
 protected function generateACFSettings(Editor $editor)
 {
     // When no text format is associated yet, assume nothing is disallowed, so
     // set allowedContent to true.
     if (!$editor->hasAssociatedFilterFormat()) {
         return TRUE;
     }
     $format = $editor->getFilterFormat();
     $filter_types = $format->getFilterTypes();
     // When nothing is disallowed, set allowedContent to true.
     if (!in_array(FilterInterface::TYPE_HTML_RESTRICTOR, $filter_types)) {
         return array(TRUE, FALSE);
     } else {
         $get_attribute_values = function ($attribute_values, $allowed_values) {
             $values = array_keys(array_filter($attribute_values, function ($value) use($allowed_values) {
                 if ($allowed_values) {
                     return $value !== FALSE;
                 } else {
                     return $value === FALSE;
                 }
             }));
             if (count($values)) {
                 return implode(',', $values);
             } else {
                 return NULL;
             }
         };
         $html_restrictions = $format->getHtmlRestrictions();
         // When all HTML is allowed, also set allowedContent to true and
         // disallowedContent to false.
         if ($html_restrictions === FALSE) {
             return array(TRUE, FALSE);
         }
         $allowed = array();
         $disallowed = array();
         if (isset($html_restrictions['forbidden_tags'])) {
             foreach ($html_restrictions['forbidden_tags'] as $tag) {
                 $disallowed[$tag] = TRUE;
             }
         }
         foreach ($html_restrictions['allowed'] as $tag => $attributes) {
             // Tell CKEditor the tag is allowed, but no attributes.
             if ($attributes === FALSE) {
                 $allowed[$tag] = array('attributes' => FALSE, 'styles' => FALSE, 'classes' => FALSE);
             } elseif ($attributes === TRUE) {
                 $allowed[$tag] = array('attributes' => TRUE, 'styles' => TRUE, 'classes' => TRUE);
                 // We've just marked that any value for the "style" and "class"
                 // attributes is allowed. However, that may not be the case: the "*"
                 // tag may still apply restrictions.
                 // Since CKEditor's ACF follows the following principle:
                 //     Once validated, an element or its property cannot be
                 //     invalidated by another rule.
                 // That means that the most permissive setting wins. Which means that
                 // it will still be allowed by CKEditor to e.g. define any style, no
                 // matter what the "*" tag's restrictions may be. If there's a setting
                 // for either the "style" or "class" attribute, it cannot possibly be
                 // more permissive than what was set above. Hence: inherit from the
                 // "*" tag where possible.
                 if (isset($html_restrictions['allowed']['*'])) {
                     $wildcard = $html_restrictions['allowed']['*'];
                     if (isset($wildcard['style'])) {
                         if (!is_array($wildcard['style'])) {
                             $allowed[$tag]['styles'] = $wildcard['style'];
                         } else {
                             $allowed_styles = $get_attribute_values($wildcard['style'], TRUE);
                             if (isset($allowed_styles)) {
                                 $allowed[$tag]['styles'] = $allowed_styles;
                             } else {
                                 unset($allowed[$tag]['styles']);
                             }
                         }
                     }
                     if (isset($wildcard['class'])) {
                         if (!is_array($wildcard['class'])) {
                             $allowed[$tag]['classes'] = $wildcard['class'];
                         } else {
                             $allowed_classes = $get_attribute_values($wildcard['class'], TRUE);
                             if (isset($allowed_classes)) {
                                 $allowed[$tag]['classes'] = $allowed_classes;
                             } else {
                                 unset($allowed[$tag]['classes']);
//.........这里部分代码省略.........
开发者ID:dmyerson,项目名称:d8ecs,代码行数:101,代码来源:Internal.php

示例4: getMediumId

 /**
  * Returns the selected Medium Editor id for an account from editor settings.
  */
 public static function getMediumId(Editor $editor, AccountInterface $account)
 {
     $settings = $editor->getSettings();
     if (!empty($settings['roles_editors'])) {
         // Filter roles in two steps. May avoid a db hit by filter_get_roles_by_format().
         if ($roles_editors = array_intersect_key($settings['roles_editors'], array_flip($account->getRoles()))) {
             if ($roles_editors = array_intersect_key($roles_editors, filter_get_roles_by_format($editor->getFilterFormat()))) {
                 return reset($roles_editors);
             }
         }
     }
     return $settings['default_editor'];
 }
开发者ID:digideskio,项目名称:medium-editor-d8,代码行数:16,代码来源:MediumEditor.php


注:本文中的Drupal\editor\Entity\Editor::getFilterFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。