src/TwbBundle/View/Helper/TwbBundleDropdown.php
public function renderListItems(array $aDropdownOptions)
    {
        if (!isset($aDropdownOptions['items'])) {
            throw new LogicException(__METHOD__ . ' expects "items" option');
        }

        if (!is_array($aDropdownOptions['items'])) {
            throw new LogicException('"items" option expects an array, "' . gettype($aDropdownOptions['items']) . '" given');
        }

        // Dropdown list attributes (class)
        if (empty($aDropdownOptions['list_attributes'])) {
            $aDropdownOptions['list_attributes'] = array('class' => 'dropdown-menu');
        } else {
            if (!is_array($aDropdownOptions['list_attributes'])) {
                throw new \LogicException('"list_attributes" option expects an array, "' . gettype($aDropdownOptions['list_attributes']) . '" given');
            }

            if (empty($aDropdownOptions['list_attributes']['class'])) {
                $aDropdownOptions['list_attributes']['class'] = 'dropdown-menu';
            } elseif (!preg_match('/(\s|^)dropdown-menu(\s|$)/', $aDropdownOptions['list_attributes']['class'])) {
                $aDropdownOptions['list_attributes']['class'] .= ' dropdown-menu';
            }
        }

        // Dropdown list attributes (role)
        if (empty($aDropdownOptions['list_attributes']['role'])) {
            $aDropdownOptions['list_attributes']['role'] = 'menu';
        }

        // Dropdown list attributes (name)
        if (!empty($aDropdownOptions['name'])) {
            $aDropdownOptions['list_attributes']['aria-labelledby'] = $aDropdownOptions['name'];
        }

        // Dropdown list attributes (items)
        $sItems = '';
        foreach ($aDropdownOptions['items'] as $sKey => $aItemOptions) {
            if (!is_array($aItemOptions)) {
                if (!is_scalar($aItemOptions)) {
                    throw new \LogicException('item option expects an array or a scalar value, "' . gettype($aItemOptions) . '" given');
                }
                $aItemOptions = $aItemOptions === self::TYPE_ITEM_DIVIDER
                        // Divider
                        ? array('type' => self::TYPE_ITEM_DIVIDER)
                        // Link
                        : array(
                    'label' => $aItemOptions,
                    'type' => self::TYPE_ITEM_LINK,
                    'item_attributes' => array('href' => is_string($sKey) ? $sKey : null)
                );
            } else {
                if (!isset($aItemOptions['label'])) {
                    $aItemOptions['label'] = is_string($sKey) ? $sKey : null;
                }

                if (!isset($aItemOptions['type'])) {
                    $aItemOptions['type'] = self::TYPE_ITEM_LINK;
                }
            }
            $sItems .= $this->renderItem($aItemOptions) . "\n";
        }

        return sprintf(
                static::$dropdownListFormat, $this->createAttributesString($aDropdownOptions['list_attributes']), // List attributes
                $sItems // Items
        );
    }
public function renderListItems(array $aDropdownOptions)
    {
        if (!isset($aDropdownOptions['items'])) {
            throw new LogicException(__METHOD__ . ' expects "items" option');
        }

        if (!is_array($aDropdownOptions['items'])) {
            throw new LogicException('"items" option expects an array, "' . gettype($aDropdownOptions['items']) . '" given');
        }

        // Dropdown list attributes (class)
        if (empty($aDropdownOptions['list_attributes'])) {
            $aDropdownOptions['list_attributes'] = array('class' => 'dropdown-menu');
        } else {
            if (!is_array($aDropdownOptions['list_attributes'])) {
                throw new \LogicException('"list_attributes" option expects an array, "' . gettype($aDropdownOptions['list_attributes']) . '" given');
            }

            if (empty($aDropdownOptions['list_attributes']['class'])) {
                $aDropdownOptions['list_attributes']['class'] = 'dropdown-menu';
            } elseif (!preg_match('/(\s|^)dropdown-menu(\s|$)/', $aDropdownOptions['list_attributes']['class'])) {
                $aDropdownOptions['list_attributes']['class'] .= ' dropdown-menu';
            }
        }

        // Dropdown list attributes (role)
        if (empty($aDropdownOptions['list_attributes']['role'])) {
            $aDropdownOptions['list_attributes']['role'] = 'menu';
        }

        // Dropdown list attributes (name)
        if (!empty($aDropdownOptions['name'])) {
            $aDropdownOptions['list_attributes']['aria-labelledby'] = $aDropdownOptions['name'];
        }

        // Dropdown list attributes (items)
        $sItems = '';
        foreach ($aDropdownOptions['items'] as $sKey => $aItemOptions) {
            if (!is_array($aItemOptions)) {
                if (!is_scalar($aItemOptions)) {
                    throw new \LogicException('item option expects an array or a scalar value, "' . gettype($aItemOptions) . '" given');
                }
                $aItemOptions = $aItemOptions === self::TYPE_ITEM_DIVIDER
                        // Divider
                        ? array('type' => self::TYPE_ITEM_DIVIDER)
                        // Link
                        : array(
                    'label' => $aItemOptions,
                    'type' => self::TYPE_ITEM_LINK,
                    'item_attributes' => array('href' => is_string($sKey) ? $sKey : null)
                );
            } else {
                if (!isset($aItemOptions['label'])) {
                    $aItemOptions['label'] = is_string($sKey) ? $sKey : null;
                }

                if (!isset($aItemOptions['type'])) {
                    $aItemOptions['type'] = self::TYPE_ITEM_LINK;
                }
            }
            $sItems .= $this->renderItem($aItemOptions) . "\n";
        }

        return sprintf(
                static::$dropdownListFormat, $this->createAttributesString($aDropdownOptions['list_attributes']), // List attributes
                $sItems // Items
        );
    }
Render dropdown list items markup
@param array $aDropdownOptions
@throws LogicException
@return string