class BUEditorToolbarWrapper in BUEditor 8
Same name and namespace in other branches
- 8.2 src/BUEditorToolbarWrapper.php \Drupal\bueditor\BUEditorToolbarWrapper
Defines a class that manages BUEditor toolbar data.
Hierarchy
- class \Drupal\bueditor\BUEditorToolbarWrapper
Expanded class hierarchy of BUEditorToolbarWrapper
2 files declare their use of BUEditorToolbarWrapper
- Core.php in src/
Plugin/ BUEditorPlugin/ Core.php - XPreview.php in src/
Plugin/ BUEditorPlugin/ XPreview.php
File
- src/
BUEditorToolbarWrapper.php, line 8
Namespace
Drupal\bueditorView source
class BUEditorToolbarWrapper {
/**
* Singleton instance.
*/
protected static $instance;
/**
* Toolbar items.
*
* @var array
*/
protected $toolbar;
/**
* Associative array of unique toolbar items.
*
* @var array
*/
protected $assocToolbar;
/**
* Creates the singleton with the given toolbar reference.
*/
public static function set(array &$toolbar) {
if (!static::$instance) {
static::$instance = new static();
}
return static::$instance
->_set($toolbar);
}
/**
* Sets the toolbar reference.
*/
public function _set(array &$toolbar) {
if ($this->toolbar !== $toolbar) {
$this->assocToolbar = array_combine($toolbar, $toolbar);
}
$this->toolbar =& $toolbar;
return $this;
}
/**
* Checks the existence of an item.
*/
public function has($id) {
return isset($this->assocToolbar[$id]);
}
/**
* Checks if any of the given items exists.
*/
public function hasAnyOf(array $ids) {
foreach ($ids as $id) {
if (isset($this->assocToolbar[$id])) {
return TRUE;
}
}
return FALSE;
}
/**
* Returns items that start with a string or match a regex.
*/
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;
}
/**
* Removes an item or a list of 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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BUEditorToolbarWrapper:: |
protected | property | Associative array of unique toolbar items. | |
BUEditorToolbarWrapper:: |
protected static | property | Singleton instance. | |
BUEditorToolbarWrapper:: |
protected | property | Toolbar items. | |
BUEditorToolbarWrapper:: |
public | function | Checks the existence of an item. | |
BUEditorToolbarWrapper:: |
public | function | Checks if any of the given items exists. | |
BUEditorToolbarWrapper:: |
public | function | Returns items that start with a string or match a regex. | |
BUEditorToolbarWrapper:: |
public | function | Removes an item or a list of items. | |
BUEditorToolbarWrapper:: |
public static | function | Creates the singleton with the given toolbar reference. | |
BUEditorToolbarWrapper:: |
public | function | Sets the toolbar reference. |