BUEditorToolbarWrapper.php in BUEditor 8
File
src/BUEditorToolbarWrapper.php
View source
<?php
namespace Drupal\bueditor;
class BUEditorToolbarWrapper {
protected static $instance;
protected $toolbar;
protected $assocToolbar;
public static function set(array &$toolbar) {
if (!static::$instance) {
static::$instance = new static();
}
return static::$instance
->_set($toolbar);
}
public function _set(array &$toolbar) {
if ($this->toolbar !== $toolbar) {
$this->assocToolbar = array_combine($toolbar, $toolbar);
}
$this->toolbar =& $toolbar;
return $this;
}
public function has($id) {
return isset($this->assocToolbar[$id]);
}
public function hasAnyOf(array $ids) {
foreach ($ids as $id) {
if (isset($this->assocToolbar[$id])) {
return TRUE;
}
}
return FALSE;
}
public function match($str, $is_regex = FALSE) {
$items = [];
if ($this->assocToolbar) {
foreach ($this->assocToolbar as $id) {
$found = $is_regex ? preg_match($str, $id) : strpos($id, $str) === 0;
if ($found) {
$items[$id] = $id;
}
}
}
return $items;
}
public function remove($id) {
$ids = is_array($id) ? $id : [
$id,
];
$this->toolbar = array_diff($this->toolbar, $ids);
foreach ($ids as $id) {
unset($this->assocToolbar[$id]);
}
return $this;
}
}