src/TwbBundle/View/Helper/TwbBundleDropdown.php
protected function renderItem($aItemOptions)
    {
        if (empty($aItemOptions['type'])) {
            throw new \LogicException(__METHOD__ . ' expects "type" option');
        }

        // Item container attributes
        if (empty($aItemOptions['attributes'])) {
            $aItemOptions['attributes'] = array();
        } elseif (!is_array($aItemOptions['attributes'])) {
            throw new \LogicException('"attributes" option expects an array, "' . gettype($aItemOptions['attributes']) . '" given');
        }

        // Item container attributes (role)
        if (empty($aItemOptions['attributes']['role'])) {
            $aItemOptions['attributes']['role'] = 'presentation';
        }

        $sItemContent = '';
        switch ($aItemOptions['type']) {
            case self::TYPE_ITEM_HEADER:
                // Define item container "header" class
                if (empty($aItemOptions['attributes']['class'])) {
                    $aItemOptions['attributes']['class'] = 'dropdown-header';
                } elseif (!preg_match('/(\s|^)dropdown-header(\s|$)/', $aItemOptions['attributes']['class'])) {
                    $aItemOptions['attributes']['class'] .= ' dropdown-header';
                }

                // Header label
                if (empty($aItemOptions['label'])) {
                    throw new \LogicException('"' . $aItemOptions['type'] . '" item expects "label" option');
                }

                if (!is_scalar($aItemOptions['label'])) {
                    throw new \LogicException('"label" option expect scalar value, "' . gettype($aItemOptions['label']) . '" given');
                } elseif (($oTranslator = $this->getTranslator())) {
                    $aItemOptions['label'] = $oTranslator->translate($aItemOptions['label'], $this->getTranslatorTextDomain());
                }

                $sItemContent = $this->getEscapeHtmlHelper()->__invoke($aItemOptions['label']);
                break;
            case self::TYPE_ITEM_DIVIDER:
                // Define item container "divider" class
                if (empty($aItemOptions['attributes']['class'])) {
                    $aItemOptions['attributes']['class'] = 'divider';
                } elseif (!preg_match('/(\s|^)divider(\s|$)/', $aItemOptions['attributes']['class'])) {
                    $aItemOptions['attributes']['class'] .= ' divider';
                }

                $sItemContent = '';
                break;

            case self::TYPE_ITEM_LINK:
                if (empty($aItemOptions['label'])) {
                    throw new \LogicException('"' . $aItemOptions['type'] . '" item expects "label" option');
                }
                if (!is_scalar($aItemOptions['label'])) {
                    throw new \LogicException('"label" option expect scalar value, "' . gettype($aItemOptions['label']) . '" given');
                } elseif (($oTranslator = $this->getTranslator())) {
                    $aItemOptions['label'] = $oTranslator->translate($aItemOptions['label'], $this->getTranslatorTextDomain());
                }

                // Item attributes (Role)
                if (empty($aItemOptions['item_attributes']['role'])) {
                    $aItemOptions['item_attributes']['role'] = 'menuitem';
                }

                // Item attributes (Tab index)
                if (!isset($aItemOptions['item_attributes']['tabindex'])) {
                    $aItemOptions['item_attributes']['tabindex'] = '-1';
                }

                // Item attributes (Href)
                if (!isset($aItemOptions['item_attributes']['href'])) {
                    $aItemOptions['item_attributes']['href'] = '#';
                }

                $aValidTagAttributes = $this->validTagAttributes;
                $this->validTagAttributes = array('href' => true);
                $sAttributeString = $this->createAttributesString($aItemOptions['item_attributes']);
                $this->validTagAttributes = $aValidTagAttributes;

                $sItemContent = sprintf(static::$dropdownItemFormats[self::TYPE_ITEM_LINK], $sAttributeString, $this->getEscapeHtmlHelper()->__invoke($aItemOptions['label']));
                break;
        }

        return sprintf(static::$dropdownItemContainerFormat, $this->createAttributesString($aItemOptions['attributes']), $sItemContent);
    }
protected function renderItem($aItemOptions)
    {
        if (empty($aItemOptions['type'])) {
            throw new \LogicException(__METHOD__ . ' expects "type" option');
        }

        // Item container attributes
        if (empty($aItemOptions['attributes'])) {
            $aItemOptions['attributes'] = array();
        } elseif (!is_array($aItemOptions['attributes'])) {
            throw new \LogicException('"attributes" option expects an array, "' . gettype($aItemOptions['attributes']) . '" given');
        }

        // Item container attributes (role)
        if (empty($aItemOptions['attributes']['role'])) {
            $aItemOptions['attributes']['role'] = 'presentation';
        }

        $sItemContent = '';
        switch ($aItemOptions['type']) {
            case self::TYPE_ITEM_HEADER:
                // Define item container "header" class
                if (empty($aItemOptions['attributes']['class'])) {
                    $aItemOptions['attributes']['class'] = 'dropdown-header';
                } elseif (!preg_match('/(\s|^)dropdown-header(\s|$)/', $aItemOptions['attributes']['class'])) {
                    $aItemOptions['attributes']['class'] .= ' dropdown-header';
                }

                // Header label
                if (empty($aItemOptions['label'])) {
                    throw new \LogicException('"' . $aItemOptions['type'] . '" item expects "label" option');
                }

                if (!is_scalar($aItemOptions['label'])) {
                    throw new \LogicException('"label" option expect scalar value, "' . gettype($aItemOptions['label']) . '" given');
                } elseif (($oTranslator = $this->getTranslator())) {
                    $aItemOptions['label'] = $oTranslator->translate($aItemOptions['label'], $this->getTranslatorTextDomain());
                }

                $sItemContent = $this->getEscapeHtmlHelper()->__invoke($aItemOptions['label']);
                break;
            case self::TYPE_ITEM_DIVIDER:
                // Define item container "divider" class
                if (empty($aItemOptions['attributes']['class'])) {
                    $aItemOptions['attributes']['class'] = 'divider';
                } elseif (!preg_match('/(\s|^)divider(\s|$)/', $aItemOptions['attributes']['class'])) {
                    $aItemOptions['attributes']['class'] .= ' divider';
                }

                $sItemContent = '';
                break;

            case self::TYPE_ITEM_LINK:
                if (empty($aItemOptions['label'])) {
                    throw new \LogicException('"' . $aItemOptions['type'] . '" item expects "label" option');
                }
                if (!is_scalar($aItemOptions['label'])) {
                    throw new \LogicException('"label" option expect scalar value, "' . gettype($aItemOptions['label']) . '" given');
                } elseif (($oTranslator = $this->getTranslator())) {
                    $aItemOptions['label'] = $oTranslator->translate($aItemOptions['label'], $this->getTranslatorTextDomain());
                }

                // Item attributes (Role)
                if (empty($aItemOptions['item_attributes']['role'])) {
                    $aItemOptions['item_attributes']['role'] = 'menuitem';
                }

                // Item attributes (Tab index)
                if (!isset($aItemOptions['item_attributes']['tabindex'])) {
                    $aItemOptions['item_attributes']['tabindex'] = '-1';
                }

                // Item attributes (Href)
                if (!isset($aItemOptions['item_attributes']['href'])) {
                    $aItemOptions['item_attributes']['href'] = '#';
                }

                $aValidTagAttributes = $this->validTagAttributes;
                $this->validTagAttributes = array('href' => true);
                $sAttributeString = $this->createAttributesString($aItemOptions['item_attributes']);
                $this->validTagAttributes = $aValidTagAttributes;

                $sItemContent = sprintf(static::$dropdownItemFormats[self::TYPE_ITEM_LINK], $sAttributeString, $this->getEscapeHtmlHelper()->__invoke($aItemOptions['label']));
                break;
        }

        return sprintf(static::$dropdownItemContainerFormat, $this->createAttributesString($aItemOptions['attributes']), $sItemContent);
    }
protected function renderItem ( $ aItemOptions ) { if ( empty ( $ aItemOptions [ 'type' ] ) ) { throw new \ LogicException ( __METHOD__ . ' expects "type" option' ) ; } // Item container attributes
 if ( empty ( $ aItemOptions [ 'attributes' ] ) ) { $ aItemOptions [ 'attributes' ] = array ( ) ; } elseif ( ! is_array ( $ aItemOptions [ 'attributes' ] ) ) { throw new \ LogicException ( '"attributes" option expects an array, "' . gettype ( $ aItemOptions [ 'attributes' ] ) . '" given' ) ; } // Item container attributes (role)
 if ( empty ( $ aItemOptions [ 'attributes' ] [ 'role' ] ) ) { $ aItemOptions [ 'attributes' ] [ 'role' ] = 'presentation' ; } $ sItemContent = '' ; switch ( $ aItemOptions [ 'type' ] ) { case self :: TYPE_ITEM_HEADER : // Define item container "header" class
 if ( empty ( $ aItemOptions [ 'attributes' ] [ 'class' ] ) ) { $ aItemOptions [ 'attributes' ] [ 'class' ] = 'dropdown-header' ; } elseif ( ! preg_match ( '/(\s|^)dropdown-header(\s|$)/' , $ aItemOptions [ 'attributes' ] [ 'class' ] ) ) { $ aItemOptions [ 'attributes' ] [ 'class' ] .= ' dropdown-header' ; } // Header label
 if ( empty ( $ aItemOptions [ 'label' ] ) ) { throw new \ LogicException ( '"' . $ aItemOptions [ 'type' ] . '" item expects "label" option' ) ; } if ( ! is_scalar ( $ aItemOptions [ 'label' ] ) ) { throw new \ LogicException ( '"label" option expect scalar value, "' . gettype ( $ aItemOptions [ 'label' ] ) . '" given' ) ; } elseif ( ( $ oTranslator = $ this -> getTranslator ( ) ) ) { $ aItemOptions [ 'label' ] = $ oTranslator -> translate ( $ aItemOptions [ 'label' ] , $ this -> getTranslatorTextDomain ( ) ) ; } $ sItemContent = $ this -> getEscapeHtmlHelper ( ) -> __invoke ( $ aItemOptions [ 'label' ] ) ; break ; case self :: TYPE_ITEM_DIVIDER : // Define item container "divider" class
 if ( empty ( $ aItemOptions [ 'attributes' ] [ 'class' ] ) ) { $ aItemOptions [ 'attributes' ] [ 'class' ] = 'divider' ; } elseif ( ! preg_match ( '/(\s|^)divider(\s|$)/' , $ aItemOptions [ 'attributes' ] [ 'class' ] ) ) { $ aItemOptions [ 'attributes' ] [ 'class' ] .= ' divider' ; } $ sItemContent = '' ; break ; case self :: TYPE_ITEM_LINK : if ( empty ( $ aItemOptions [ 'label' ] ) ) { throw new \ LogicException ( '"' . $ aItemOptions [ 'type' ] . '" item expects "label" option' ) ; } if ( ! is_scalar ( $ aItemOptions [ 'label' ] ) ) { throw new \ LogicException ( '"label" option expect scalar value, "' . gettype ( $ aItemOptions [ 'label' ] ) . '" given' ) ; } elseif ( ( $ oTranslator = $ this -> getTranslator ( ) ) ) { $ aItemOptions [ 'label' ] = $ oTranslator -> translate ( $ aItemOptions [ 'label' ] , $ this -> getTranslatorTextDomain ( ) ) ; } // Item attributes (Role)
 if ( empty ( $ aItemOptions [ 'item_attributes' ] [ 'role' ] ) ) { $ aItemOptions [ 'item_attributes' ] [ 'role' ] = 'menuitem' ; } // Item attributes (Tab index)
 if ( ! isset ( $ aItemOptions [ 'item_attributes' ] [ 'tabindex' ] ) ) { $ aItemOptions [ 'item_attributes' ] [ 'tabindex' ] = '-1' ; } // Item attributes (Href)
 if ( ! isset ( $ aItemOptions [ 'item_attributes' ] [ 'href' ] ) ) { $ aItemOptions [ 'item_attributes' ] [ 'href' ] = '#' ; } $ aValidTagAttributes = $ this -> validTagAttributes ; $ this -> validTagAttributes = array ( 'href' => true ) ; $ sAttributeString = $ this -> createAttributesString ( $ aItemOptions [ 'item_attributes' ] ) ; $ this -> validTagAttributes = $ aValidTagAttributes ; $ sItemContent = sprintf ( static :: $ dropdownItemFormats [ self :: TYPE_ITEM_LINK ] , $ sAttributeString , $ this -> getEscapeHtmlHelper ( ) -> __invoke ( $ aItemOptions [ 'label' ] ) ) ; break ; } return sprintf ( static :: $ dropdownItemContainerFormat , $ this -> createAttributesString ( $ aItemOptions [ 'attributes' ] ) , $ sItemContent ) ; }
Render dropdown list item markup
@param array $aItemOptions
@throws LogicException
@return string
Render dropdown list item markup