public function renderAddress(\Twig_Environment $environment, $address, $showName = true, $showEdit = false, $context = null)
    {
        $requiredAddressKeys = ['firstname', 'lastname', 'address1', 'postcode', 'city', 'country_code'];

        if (!($address instanceof AddressInterface) && (!\is_array($address) || 0 !== \count(array_diff($requiredAddressKeys, array_keys($address))))) {
            throw new \RuntimeException(sprintf(
                'sonata_address_render needs an AddressInterface instance or an array with keys (%s)',
                implode(', ', $requiredAddressKeys)
            ));
        }

        if ($address instanceof AddressInterface) {
            $addressArray = [
                'id' => $showEdit ? $address->getId() : '',
                'name' => $showName ? $address->getName() : '',
                'address' => $address->getFullAddressHtml(),
            ];
        } else {
            if ($showEdit && !\array_key_exists('id', $address)) {
                throw new \RuntimeException(
                    "sonata_address_render needs 'id' key to be set to render the edit button"
                );
            }

            if ($showName && !\array_key_exists('name', $address)) {
                $address['name'] = '';
                $showName = false;
            }

            $addressArray = [
                'id' => $showEdit ? $address['id'] : '',
                'name' => $address['name'],
                'address' => BaseAddress::formatAddress($address, '<br/>'),
            ];
        }

        return $environment->render('SonataCustomerBundle:Addresses:_address.html.twig', [
                'address' => $addressArray,
                'showName' => $showName,
                'showEdit' => $showEdit,
                'context' => $context,
            ]
        );
    }
public function renderAddress(\Twig_Environment $environment, $address, $showName = true, $showEdit = false, $context = null)
    {
        $requiredAddressKeys = ['firstname', 'lastname', 'address1', 'postcode', 'city', 'country_code'];

        if (!($address instanceof AddressInterface) && (!\is_array($address) || 0 !== \count(array_diff($requiredAddressKeys, array_keys($address))))) {
            throw new \RuntimeException(sprintf(
                'sonata_address_render needs an AddressInterface instance or an array with keys (%s)',
                implode(', ', $requiredAddressKeys)
            ));
        }

        if ($address instanceof AddressInterface) {
            $addressArray = [
                'id' => $showEdit ? $address->getId() : '',
                'name' => $showName ? $address->getName() : '',
                'address' => $address->getFullAddressHtml(),
            ];
        } else {
            if ($showEdit && !\array_key_exists('id', $address)) {
                throw new \RuntimeException(
                    "sonata_address_render needs 'id' key to be set to render the edit button"
                );
            }

            if ($showName && !\array_key_exists('name', $address)) {
                $address['name'] = '';
                $showName = false;
            }

            $addressArray = [
                'id' => $showEdit ? $address['id'] : '',
                'name' => $address['name'],
                'address' => BaseAddress::formatAddress($address, '<br/>'),
            ];
        }

        return $environment->render('SonataCustomerBundle:Addresses:_address.html.twig', [
                'address' => $addressArray,
                'showName' => $showName,
                'showEdit' => $showEdit,
                'context' => $context,
            ]
        );
    }
public function renderAddress ( \ Twig_Environment $ environment , $ address , $ showName = true , $ showEdit = false , $ context = null ) { $ requiredAddressKeys = [ 'firstname' , 'lastname' , 'address1' , 'postcode' , 'city' , 'country_code' ] ; if ( ! ( $ address instanceof AddressInterface ) && ( ! \ is_array ( $ address ) || 0 !== \ count ( array_diff ( $ requiredAddressKeys , array_keys ( $ address ) ) ) ) ) { throw new \ RuntimeException ( sprintf ( 'sonata_address_render needs an AddressInterface instance or an array with keys (%s)' , implode ( ', ' , $ requiredAddressKeys ) ) ) ; } if ( $ address instanceof AddressInterface ) { $ addressArray = [ 'id' => $ showEdit ? $ address -> getId ( ) : '' , 'name' => $ showName ? $ address -> getName ( ) : '' , 'address' => $ address -> getFullAddressHtml ( ) , ] ; } else { if ( $ showEdit && ! \ array_key_exists ( 'id' , $ address ) ) { throw new \ RuntimeException ( "sonata_address_render needs 'id' key to be set to render the edit button" ) ; } if ( $ showName && ! \ array_key_exists ( 'name' , $ address ) ) { $ address [ 'name' ] = '' ; $ showName = false ; } $ addressArray = [ 'id' => $ showEdit ? $ address [ 'id' ] : '' , 'name' => $ address [ 'name' ] , 'address' => BaseAddress :: formatAddress ( $ address , '<br/>' ) , ] ; } return $ environment -> render ( 'SonataCustomerBundle:Addresses:_address.html.twig' , [ 'address' => $ addressArray , 'showName' => $ showName , 'showEdit' => $ showEdit , 'context' => $ context , ] ) ; }
Gets the HTML of an address.

@param \Twig_Environment $environment A Twig environment
@param mixed             $address     An instance of AddressInterface or array with keys: (id, firstname, lastname, address1, postcode, city, country_code and optionally name, address2, address3)
@param bool              $showName    Display address name?
@param bool              $showEdit    Display edit button?
@param string            $context     A context for edit link

@throws InvalidParameterException

@return string
Gets the HTML of an address .