80 throw new \InvalidArgumentException(
81 'Only valid items may be assigned to a split Button. "' .
83 '" did not pass validation',
87 if ($primaryAction && $this->containsPrimaryAction) {
88 throw new \InvalidArgumentException(
'A splitButton may only contain one primary action', 1441706340);
91 $this->containsPrimaryAction =
true;
92 $this->items[
'primary'] = clone $item;
94 $this->items[
'options'][] = clone $item;
106 if (!isset($this->items[
'primary']) && isset($this->items[
'options'])) {
107 $primaryAction = array_shift($this->items[
'options']);
108 $this->items[
'primary'] = $primaryAction;
122 return isset($subject[
'primary'])
124 && isset($subject[
'options']);
137 'class' =>
'btn btn-sm btn-default ' .
$items[
'primary']->getClasses(),
139 if (method_exists(
$items[
'primary'],
'getName')) {
140 $attributes[
'name'] =
$items[
'primary']->getName();
142 if (method_exists(
$items[
'primary'],
'getValue')) {
143 $attributes[
'value'] =
$items[
'primary']->getValue();
146 $attributes[
'onclick'] =
$items[
'primary']->getOnClick();
148 if (method_exists(
$items[
'primary'],
'getForm') && !empty(
$items[
'primary']->getForm())) {
149 $attributes[
'form'] =
$items[
'primary']->getForm();
151 $attributesString =
'';
152 foreach ($attributes as $key => $value) {
153 $attributesString .=
' ' . htmlspecialchars($key) .
'="' . htmlspecialchars($value) .
'"';
156 <div class="btn-group t3js-splitbutton">
157 <button' . $attributesString .
'>
158 ' .
$items[
'primary']->getIcon()->render(
'inline') .
'
161 <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
162 <span class="caret"></span>
163 <span class="sr-only">Toggle Dropdown</span>
165 <ul class="dropdown-menu">';
168 foreach (
$items[
'options'] as $option) {
171 $optionAttributes = [
173 'data-name' => $option->getName(),
174 'data-value' => $option->getValue(),
175 'data-form' => $option->getForm()
178 if (!empty($option->getClasses())) {
179 $optionAttributes[
'class'] = $option->getClasses();
181 if (!empty($option->getOnClick())) {
182 $optionAttributes[
'onclick'] = $option->getOnClick();
184 $optionAttributesString =
'';
185 foreach ($optionAttributes as $key => $value) {
186 $optionAttributesString .=
' ' . htmlspecialchars($key) .
'="' . htmlspecialchars($value) .
'"';
188 $html =
'<a' . $optionAttributesString .
'>' . $option->getIcon()->render(
'inline') .
' '
189 . htmlspecialchars($option->getTitle()) .
'</a>';
192 $html = $option->render();