Skip to content
Snippets Groups Projects
Commit a0a65e35 authored by Mikael Meulle's avatar Mikael Meulle Committed by christian.wiedemann
Browse files

Issue #3456072 by just_like_good_vibes: [2.0.0-beta3] Remove UiPatternsOperations form element?

parent b642cfa3
Branches
Tags
1 merge request!224Resolve #3456072 "2.0.0 beta2 remove uipatternsoperations"
Pipeline #290201 passed with warnings
......@@ -6,6 +6,7 @@ use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Element\RenderElementBase;
use Drupal\ui_patterns\SourcePluginBase;
/**
......@@ -320,29 +321,20 @@ class ComponentSlotForm extends ComponentFormBase {
*/
protected static function buildComponentDropbutton(array $elements = []): array {
$build = [
'#type' => 'container',
'#attributes' => ['class' => ['ui-patterns-dropbutton-wrapper']],
'#type' => 'dropbutton',
'#dropbutton_type' => 'small',
'#links' => [],
];
$operations = [];
// Because we are cloning the elements into title sub element we need to
// sort children first.
foreach (Element::children($elements, TRUE) as $child) {
// Clone the element as an operation.
$operations[$child] = ['title' => $elements[$child]];
$build["#links"][$child] = ['title' => $elements[$child]];
RenderElementBase::preRenderAjaxForm($build["#links"][$child]['title']);
// Flag the original element as printed so it doesn't render twice.
$elements[$child]['#printed'] = TRUE;
}
$build['operations'] = [
'#type' => 'ui_patterns_operations',
// Even though operations are run through the "links" element type, the
// theme system will render any render array passed as a link "title".
'#links' => $operations,
'#dropbutton_type' => 'small',
];
return $build + $elements;
}
......
<?php
namespace Drupal\ui_patterns\Element;
use Drupal\Core\Render\Element\Operations;
use Drupal\Core\Render\Element\RenderElementBase;
/**
* {@inheritdoc}
*
* @RenderElement("ui_patterns_operations")
*/
class UiPatternsOperations extends Operations {
/**
* {@inheritdoc}
*/
public function getInfo() {
return ['#theme' => 'links__dropbutton__operations__ui_patterns'] + parent::getInfo();
}
/**
* {@inheritdoc}
*/
public static function preRenderDropbutton($element) : array {
$element = parent::preRenderDropbutton($element);
// Attach #ajax events if title is a render array.
foreach ($element['#links'] as &$link) {
if (isset($link['title']['#ajax'])) {
$link['title'] = RenderElementBase::preRenderAjaxForm($link['title']);
}
}
return $element;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment