View source
<?php
namespace Drupal\vefl;
use Drupal\Core\Layout\LayoutPluginManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class Vefl {
use StringTranslationTrait;
protected $layoutManager;
public function __construct(LayoutPluginManagerInterface $layout_manager) {
$this->layoutManager = $layout_manager;
}
public function getLayouts() {
static $layouts = FALSE;
if (!$layouts) {
$layouts = $this->layoutManager
->getDefinitions();
}
return $layouts;
}
public function getLayoutOptions($layouts = []) {
if (empty($layouts)) {
$layouts = $this
->getLayouts();
}
$layout_options = [];
foreach ($layouts as $key => $layout_definition) {
$optgroup = $this
->t('Other');
if (!empty($layout_definition
->getCategory())) {
$optgroup = (string) $layout_definition
->getCategory();
}
if (!isset($layout_options[$optgroup])) {
$layout_options[$optgroup] = [];
}
$layout_options[$optgroup][$key] = $layout_definition
->getLabel();
}
if (count($layout_options) < 2) {
$layout_options = reset($layout_options);
}
return $layout_options;
}
public static function getFormActions() {
$actions = [
'sort_by' => t('Sort by'),
'sort_order' => t('Sort order'),
'items_per_page' => t('Items per page'),
'offset' => t('Offset'),
'submit' => t('Submit button'),
'reset' => t('Reset button'),
];
return $actions;
}
}