Skip to content

Commit

Permalink
Merge pull request #68 from craftcms/feature/convert-redactor
Browse files Browse the repository at this point in the history
Redactor field conversion
  • Loading branch information
brandonkelly authored Apr 16, 2023
2 parents 4901d08 + d967b19 commit bfcd260
Show file tree
Hide file tree
Showing 3 changed files with 935 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Added the “Heading Levels” CKEditor config setting.
- Added the `ckeditor/convert` command, for converting Redactor fields/configs to CKEditor. ([#68](https://github.com/craftcms/ckeditor/pull/68))
- “Config Options” settings can now be entered as JSON, with autocompletion and automatic JavaScript-to-JSON reformatting on paste. ([#66](https://github.com/craftcms/ckeditor/pull/66), [#67](https://github.com/craftcms/ckeditor/pull/67))
- The `placeholder` config option now gets translated, when the config options are defined as JSON.
- Fixed a bug where editor toolbars would overlap the control panel header when scrolling.
Expand Down
74 changes: 74 additions & 0 deletions src/CkeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,80 @@ public function attributeLabels(): array
];
}

/**
* @since 3.1.0
*/
public function hasButton(string $button): bool
{
return in_array($button, $this->toolbar, true);
}

/**
* @since 3.1.0
*/
public function getButtonPos(string $button): int|false
{
return array_search($button, $this->toolbar);
}

/**
* @since 3.1.0
*/
public function addButton(string $button): void
{
if ($button === '|' || !$this->hasButton($button)) {
$this->toolbar[] = $button;
}
}

/**
* @since 3.1.0
*/
public function addButtonAt(string $button, int $pos): void
{
if ($button === '|' || !$this->hasButton($button)) {
array_splice($this->toolbar, $pos, 0, [$button]);
}
}

/**
* @since 3.1.0
*/
public function addButtonBefore(string $button, string $after): void
{
$afterPos = $this->getButtonPos($after);
if ($afterPos !== false) {
$this->addButtonAt($button, $afterPos);
} else {
$this->addButton($button);
}
}

/**
* @since 3.1.0
*/
public function addButtonAfter(string $button, string $after): void
{
$afterPos = $this->getButtonPos($after);
if ($afterPos !== false) {
$this->addButtonAt($button, $afterPos + 1);
} else {
$this->addButton($button);
}
}

/**
* @since 3.1.0
*/
public function removeButton(string $button): void
{
$pos = $this->getButtonPos($button);
if ($pos !== false) {
array_splice($this->toolbar, $pos, 1);
$this->toolbar = array_values($this->toolbar);
}
}

/**
* @since 3.1.0
*/
Expand Down
Loading

0 comments on commit bfcd260

Please sign in to comment.