norberttech/aceeditor-bundle

将出色的JavaScript ace编辑器集成到Symfony表单的捆绑包。

安装次数: 234,583

依赖关系: 0

建议者: 0

安全: 0

星标: 27

关注者: 6

分支: 36

开放性问题: 13

类型:symfony-bundle

5.0.0 2024-01-02 17:57 UTC

README

Tests

此捆绑包通过自动注册 ace_editor 表单类型,为Symfony表单组件提供Ace编辑器的集成。

兼容性

请查看下表以检查您的PHP和symfony版本是否受支持。

对于旧版不受支持的版本,请查看 发行版 页面。

安装

要使用此捆绑包与最新的Symfony版本,请使用 Composer 安装。

composer require norberttech/aceeditor-bundle ^5.0

如果您正在使用 symfony/flex,则捆绑包将自动为您注册,否则您需要自己注册捆绑包。

// app/config/bundles.php

return [
    // ...
    AceEditorBundle\AceEditorBundle::class => ['all' => true],
    // ...
];

使用

use AceEditorBundle\Form\Extension\AceEditor\Type\AceEditorType;

/** @var $builder \Symfony\Component\Form\FormBuilderInterface */
$builder->add('description', AceEditorType::class, [
    'wrapper_attr' => [], // aceeditor wrapper html attributes.
    'width' => '100%',
    'height' => 250,
    'font_size' => 12,
    'mode' => 'ace/mode/html', // every single default mode must have ace/mode/* prefix
    'theme' => 'ace/theme/monokai', // every single default theme must have ace/theme/* prefix
    'tab_size' => null,
    'read_only' => null,
    'use_soft_tabs' => null,
    'use_wrap_mode' => null,
    'show_print_margin' => null,
    'show_invisibles' => null,
    'highlight_active_line' => null,
    'options_enable_basic_autocompletion' => true,
    'options_enable_live_autocompletion' => true,
    'options_enable_snippets' => false
    'keyboard_handler' => null
]);

上述代码将创建一个文本区域元素,该元素将被Ace编辑器实例替换。每次在Ace编辑器中更改时,文本区域值都会更新。

配置

此部分是可选的,您不需要配置任何内容,表单类型仍然可以完美地工作。

默认配置

# app/config/config.yml

ace_editor:
    base_path: "vendor/ace" # notice! this is starting from your project's public web root, typically: `%kernel.project_dir%/public`!
    autoinclude: true
    debug: false # sources not minified, based on kernel.debug but it can force it
    noconflict: true # uses ace.require instead of require

您还可以直接从与 https://github.com/ajaxorg/ace-builds 相同目录布局的位置包含Ace编辑器,您需要做的是设置 base_path 选项。

ace_editor:
    base_path: "http://rawgithub.com/ajaxorg/ace-builds/master"

Ace编辑器资源

除非您进行了某些配置,否则此捆绑包期望Ace编辑器文件位于 public/vendor/ace。您可以从中下载任何Ace编辑器构建版本 上游存储库,并将其内容放入相应的文件夹中。

ACE_VERSION=1.32.3 # replace with whatever ace version you need

cd <YOUR_PROJECT_ROOT>/public
mkdir vendor && cd vendor
wget https://github.com/ajaxorg/ace-builds/archive/v${ACE_VERSION}.tar.gz
tar -xvf v${ACE_VERSION}.tar.gz
mv ace-${ACE_VERSION} ace
rm v${ACE_VERSION}.tar.gz