class GridStackAdmin in GridStack 8.2
Same name and namespace in other branches
- 8 src/Form/GridStackAdmin.php \Drupal\gridstack\Form\GridStackAdmin
Provides reusable admin functions or form elements.
Hierarchy
- class \Drupal\gridstack\Form\GridStackAdmin implements GridStackAdminInterface uses StringTranslationTrait
Expanded class hierarchy of GridStackAdmin
1 file declares its use of GridStackAdmin
- GridStackAdminUnitTest.php in tests/
src/ Unit/ Form/ GridStackAdminUnitTest.php
1 string reference to 'GridStackAdmin'
1 service uses GridStackAdmin
File
- src/
Form/ GridStackAdmin.php, line 15
Namespace
Drupal\gridstack\FormView source
class GridStackAdmin implements GridStackAdminInterface {
use StringTranslationTrait;
/**
* Static cache for the optionset options.
*
* @var array
*/
protected $optionsetOptions;
/**
* The blazy admin service.
*
* @var \Drupal\blazy\Form\BlazyAdminInterface
*/
protected $blazyAdmin;
/**
* The gridstack manager service.
*
* @var \Drupal\gridstack\GridStackManagerInterface
*/
protected $manager;
/**
* Constructs a GridStackAdmin object.
*
* @param \Drupal\blazy\Form\BlazyAdminInterface $blazy_admin
* The blazy admin service.
* @param \Drupal\gridstack\GridStackManagerInterface $manager
* The gridstack manager service.
*/
public function __construct(BlazyAdminInterface $blazy_admin, GridStackManagerInterface $manager) {
$this->blazyAdmin = $blazy_admin;
$this->manager = $manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('blazy.admin.extended'), $container
->get('gridstack.manager'));
}
/**
* Returns the blazy admin formatter.
*/
public function blazyAdmin() {
return $this->blazyAdmin;
}
/**
* Returns the slick manager.
*/
public function manager() {
return $this->manager;
}
/**
* Returns all settings form elements.
*
* Some settings might be required by Outlayer, such as style.
*/
public function buildSettingsForm(array &$form, $definition = []) {
$definition['namespace'] = 'gridstack';
$definition['skins'] = $this
->getSkinOptions();
$definition['style'] = !empty($definition['style']);
$definition['grid_form'] = !empty($definition['grid_form']);
$definition['optionsets'] = $this
->getOptionsetsByGroupOptions('js');
foreach ([
'background',
'caches',
'fieldable_form',
'vanilla',
] as $key) {
$definition[$key] = isset($definition[$key]) ? $definition[$key] : TRUE;
}
$definition['layouts'] = isset($definition['layouts']) ? array_merge($this
->getLayoutOptions(), $definition['layouts']) : $this
->getLayoutOptions();
$this
->openingForm($form, $definition);
$this
->mainForm($form, $definition);
$this
->closingForm($form, $definition);
}
/**
* Returns the opening form elements.
*/
public function openingForm(array &$form, &$definition = []) {
$path = drupal_get_path('module', 'gridstack');
$is_ui = $this
->manager()
->getModuleHandler()
->moduleExists('gridstack_ui');
$is_help = $this
->manager()
->getModuleHandler()
->moduleExists('help');
$route = [
'name' => 'gridstack_ui',
];
$readme = $is_ui && $is_help ? Url::fromRoute('help.page', $route)
->toString() : Url::fromUri('base:' . $path . '/README.md')
->toString();
if (!isset($form['optionset'])) {
$this->blazyAdmin
->openingForm($form, $definition);
if ($is_ui) {
$route_name = 'entity.gridstack.collection';
$form['optionset']['#description'] = $this
->t('Manage optionsets at <a href=":url" target="_blank">the optionset admin page</a>.', [
':url' => Url::fromRoute($route_name)
->toString(),
]);
}
}
if (isset($form['skin'])) {
$form['skin']['#description'] = $this
->t('Skins allow various layouts with just CSS. Some options below depend on a skin. Leave empty to DIY. Check out <a href=":url">docs to register skins</a>.', [
':url' => $readme,
]);
}
$form['gridnative'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use native CSS Grid'),
'#description' => $this
->t('<b>Experimental!</b> Check to replace any js-driven (gridstack, masonry, packery, isotope) layouts with native browser Grid layout. Check out <a href=":url">CSS Grid browser supports</a> relevant to your visitors. <br>Uncheck if any issue.', [
':url' => 'https://caniuse.com/#feat=css-grid',
]),
];
if (isset($form['background'])) {
$form['background']['#description'] = $this
->t('Only if troubled with image sizes not making the given box gapless, check this to turn the image into CSS background instead. Blazy formatter only.');
$form['background']['#weight'] = -40;
}
}
/**
* Returns the main form elements.
*/
public function mainForm(array &$form, $definition = []) {
if (!empty($definition['image_style_form'])) {
$this->blazyAdmin
->imageStyleForm($form, $definition);
}
if (!empty($definition['media_switch_form'])) {
$this->blazyAdmin
->mediaSwitchForm($form, $definition);
}
if (!empty($definition['fieldable_form'])) {
$this->blazyAdmin
->fieldableForm($form, $definition);
if (!empty($definition['links'])) {
$form['category'] = [
'#title' => $this
->t('Category'),
'#type' => 'select',
'#options' => $definition['links'],
'#description' => $this
->t('The category to display inside the box.'),
];
}
}
if (!empty($definition['stamps'])) {
$form['stamp'] = [
'#title' => $this
->t('Stamp'),
'#type' => 'select',
'#options' => $definition['stamps'],
'#description' => $this
->t('Stamp is _just a unique list, <b>Html list</b>, such as Latest news, blogs, testimonials, etc. replacing one of the other boring boxes, including rich ones. Leave empty to not use stamp.'),
'#weight' => -67,
];
$form['stamp_index'] = [
'#title' => $this
->t('Stamp index'),
'#type' => 'textfield',
'#description' => $this
->t('Which index, a stamp should be inserted into.'),
'#weight' => -66,
];
}
// Re-purpose/use the existing option Overlay for the Rich box.
if (isset($form['overlay'])) {
$form['overlay']['#title'] = $this
->t('Rich box');
$form['overlay']['#description'] = $this
->t('Replace <b>Main stage/ image</b> if a node has one. It can be any entity reference, like Block, etc. Use block_field.module for ease of block additions. How? Create a sticky (or far future created) node or two containing a Slick carousel, video, weather, time, donations, currency, ads, or anything as a block field, and put it here. Be sure different from the <b>Main stage</b>. While regular boxes are updated with new contents, these rich boxes may stay the same, and sticky (Use Views with sort by sticky or desc by creation).');
$form['overlay']['#weight'] = -65;
}
if (!empty($definition['breakpoints'])) {
$this->blazyAdmin
->breakpointsForm($form, $definition);
}
}
/**
* Returns the closing ending form elements.
*/
public function closingForm(array &$form, $definition = []) {
if (!isset($form['cache'])) {
$this->blazyAdmin
->closingForm($form, $definition);
}
if (isset($form['cache'])) {
$form['cache']['#weight'] = empty($definition['_views']) ? -40 : -22;
}
$form['#attached']['library'][] = 'gridstack/admin';
}
/**
* Returns available options for select options.
*/
public function getOptionsetsByGroupOptions($group = '') {
if (!isset($this->optionsetOptions[$group])) {
$optionsets = [];
foreach ($this->manager
->entityLoadMultiple('gridstack') as $key => $entity) {
// Exludes Boostrap/ Foundation grids which only work for LB.
if ($group && $group == 'js' && $entity
->getOption('use_framework')) {
continue;
}
$optionsets[$key] = Html::escape($entity
->label());
}
ksort($optionsets);
$this->optionsetOptions[$group] = $optionsets;
}
return $this->optionsetOptions[$group];
}
/**
* Returns available skins for select options.
*/
public function getSkinOptions() {
return $this->manager
->skinManager()
->getSkinOptions();
}
/**
* Returns default layout options for the core Image, or Views.
*/
public function getLayoutOptions() {
return [
'bottom' => $this
->t('Caption bottom'),
'center' => $this
->t('Caption center'),
'top' => $this
->t('Caption top'),
];
}
/**
* Return the field formatter settings summary.
*/
public function getSettingsSummary($definition = []) {
return $this->blazyAdmin
->getSettingsSummary($definition);
}
/**
* Returns available fields for select options.
*/
public function getFieldOptions($target_bundles = [], $allowed_field_types = [], $entity_type_id = 'media', $target_type = '') {
return $this->blazyAdmin
->getFieldOptions($target_bundles, $allowed_field_types, $entity_type_id, $target_type);
}
/**
* Returns Responsive image for select options.
*/
public function getResponsiveImageOptions() {
return $this->blazyAdmin
->getResponsiveImageOptions();
}
/**
* Returns re-usable logic, styling and assets across fields and Views.
*/
public function finalizeForm(array &$form, $definition = []) {
$this->blazyAdmin
->finalizeForm($form, $definition);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GridStackAdmin:: |
protected | property | The blazy admin service. | |
GridStackAdmin:: |
protected | property | The gridstack manager service. | |
GridStackAdmin:: |
protected | property | Static cache for the optionset options. | |
GridStackAdmin:: |
public | function | Returns the blazy admin formatter. | |
GridStackAdmin:: |
public | function | Returns all settings form elements. | |
GridStackAdmin:: |
public | function | Returns the closing ending form elements. | |
GridStackAdmin:: |
public static | function | ||
GridStackAdmin:: |
public | function | Returns re-usable logic, styling and assets across fields and Views. | |
GridStackAdmin:: |
public | function | Returns available fields for select options. | |
GridStackAdmin:: |
public | function | Returns default layout options for the core Image, or Views. | |
GridStackAdmin:: |
public | function | Returns available options for select options. | |
GridStackAdmin:: |
public | function | Returns Responsive image for select options. | |
GridStackAdmin:: |
public | function | Return the field formatter settings summary. | |
GridStackAdmin:: |
public | function | Returns available skins for select options. | |
GridStackAdmin:: |
public | function | Returns the main form elements. | |
GridStackAdmin:: |
public | function | Returns the slick manager. | |
GridStackAdmin:: |
public | function | Returns the opening form elements. | |
GridStackAdmin:: |
public | function | Constructs a GridStackAdmin object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |