| @@ -1,0 +1,56 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace AcyMailing\Types; | |
| 4 | + | |
| 5 | +use AcyMailing\Helpers\TabHelper; | |
| 6 | +use AcyMailing\Core\AcymObject; | |
| 7 | + | |
| 8 | +class DtextType extends AcymObject | |
| 9 | +{ | |
| 10 | + public function display(array $options = []): void | |
| 11 | + { | |
| 12 | + $options['withButton'] = $options['withButton'] ?? true; | |
| 13 | + $options['context'] = $options['context'] ?? ''; | |
| 14 | + | |
| 15 | + if ($options['withButton']) { | |
| 16 | + $this->displayButton($options); | |
| 17 | + } | |
| 18 | + | |
| 19 | + $data = [ | |
| 20 | + 'plugins' => $this->getIntegrations(), | |
| 21 | + 'options' => $options, | |
| 22 | + 'tabHelper' => new TabHelper(), | |
| 23 | + ]; | |
| 24 | + | |
| 25 | + include acym_getPartial('dtext', 'picker'); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public function displayButton(array $options = []): void | |
| 29 | + { | |
| 30 | + $data = [ | |
| 31 | + 'class' => $options['class'] ?? '', | |
| 32 | + 'editor' => $options['editor'] ?? '', | |
| 33 | + 'selection' => $options['selection'] ?? '', | |
| 34 | + 'icon' => $options['icon'] ?? 'acymicon-plus-circle', | |
| 35 | + 'text' => $options['text'] ?? '', | |
| 36 | + ]; | |
| 37 | + | |
| 38 | + include acym_getPartial('dtext', 'button'); | |
| 39 | + } | |
| 40 | + | |
| 41 | + private function getIntegrations(): array | |
| 42 | + { | |
| 43 | + $integrations = acym_trigger('dynamicText', [null]); | |
| 44 | + usort( | |
| 45 | + $integrations, | |
| 46 | + function ($a, $b) { | |
| 47 | + $nameA = isset($a->name) && is_string($a->name) ? strtolower($a->name) : ''; | |
| 48 | + $nameB = isset($b->name) && is_string($b->name) ? strtolower($b->name) : ''; | |
| 49 | + | |
| 50 | + return $nameA > $nameB ? 1 : -1; | |
| 51 | + } | |
| 52 | + ); | |
| 53 | + | |
| 54 | + return empty($integrations) ? [] : $integrations; | |
| 55 | + } | |
| 56 | +} | |