Skip to content
Snippets Groups Projects

Make weight configurable when placed in sidebar

1 file
+ 26
2
Compare changes
  • Side-by-side
  • Inline
@@ -21,6 +21,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class TaxonomyWidgetPlus extends WidgetBase {
/**
* The default weight of the widget when placed in the sidebar.
*/
const SIDEBAR_DEFAULT_WEIGHT = 100;
/**
* The entity type manager.
*
@@ -64,6 +69,7 @@ class TaxonomyWidgetPlus extends WidgetBase {
return [
'description_on_hover' => TRUE,
'sidebar' => TRUE,
'sidebar_weight' => self::SIDEBAR_DEFAULT_WEIGHT,
'use_scrollbar' => TRUE,
'start_collapsed' => FALSE,
'hide_parent_field' => FALSE,
@@ -98,6 +104,23 @@ class TaxonomyWidgetPlus extends WidgetBase {
'#default_value' => $this->getSetting('sidebar'),
];
$field_name = $this->fieldDefinition->getName();
$form['sidebar_weight'] = [
'#type' => 'weight',
'#title' => $this->t('Sidebar weight'),
'#description' => $this->t('Defines the position in the sidebar where the field will be placed. Default is at the end.<br>To show above the path alias use a value < @pathalias_weight and to show above author information use a value < @author_weight.',
[
'@pathalias_weight' => 30,
'@author_weight' => 90,
]),
'#default_value' => $this->getSetting('sidebar_weight') ?? self::SIDEBAR_DEFAULT_WEIGHT,
'#states' => [
'visible' => [
":input[name='fields[$field_name][settings_edit_form][settings][sidebar]']" => ['checked' => TRUE],
],
],
];
$form['use_scrollbar'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use scrollbar'),
@@ -133,7 +156,8 @@ class TaxonomyWidgetPlus extends WidgetBase {
}
if ($this->getSetting('sidebar')) {
$summary[] = $this->t('Placed in sidebar');
$weight = $this->getSetting('sidebar_weight') ?? self::SIDEBAR_DEFAULT_WEIGHT;
$summary[] = $this->t('Placed in sidebar (weight: @weight)', ['@weight' => $weight]);
}
if ($this->getSetting('use_scrollbar')) {
@@ -188,7 +212,7 @@ class TaxonomyWidgetPlus extends WidgetBase {
$sidebar = $this->getSetting('sidebar');
if ($sidebar) {
$element['#group'] = 'advanced';
$element['#weight'] = 100;
$element['#weight'] = $this->getSetting('sidebar_weight') ?? self::SIDEBAR_DEFAULT_WEIGHT;
}
$element['#element_validate'] = [
Loading