modules/acm_customer/src/Plugin/CustomerForm/Addresses.php
public function buildSummary(array $addresses = [], $show_add = TRUE) {
    $build = [];

    // Display an "Add Address" button.
    if ($show_add) {
      $build['add_address'] = [
        '#type' => 'acm_composite',
        '#field_type' => 'acm_address',
        '#default_value' => empty($addresses) ? $this->t('You have no saved addresses.') : '',
        '#form_mode' => FALSE,
        '#buttons' => [
          'add' => [
            '#type' => 'link',
            '#title' => $this->t('Add address'),
            '#url' => Url::fromRoute('acm_customer.view_page', [
              'page' => $this->getPageId(),
              'action' => 'add',
            ]),
            '#attributes' => [
              'class' => [
                'form-item__add-button',
              ],
            ],
          ],
        ],
      ];
    }

    // Build the summary for each user address.
    foreach ($addresses as $address) {
      if ($address['default_billing'] && $address['default_shipping']) {
        $address['heading'] = $this->t('Default Billing and Shipping Address');
      }
      elseif ($address['default_billing']) {
        $address['heading'] = $this->t('Default Billing Address');
      }
      elseif ($address['default_shipping']) {
        $address['heading'] = $this->t('Default Shipping Address');
      }
      else {
        $address['heading'] = '';
      }

      // Build a link for each action.
      $actions = [
        'edit' => [
          'label' => t('Edit'),
        ],
        'delete' => [
          'label' => t('Delete'),
          'options' => [
            'attributes' => [
              'class' => ['bypass-js'],
            ],
          ],
        ],
      ];

      $links = [];

      foreach ($actions as $action => $config) {
        $options = isset($config['options']) ? $config['options'] : [];
        $label = isset($config['label']) ? $config['label'] : $action;
        $link = Link::fromTextAndUrl($label, Url::fromRoute('acm_customer.view_page', [
          'page' => $this->getPageId(),
          'action' => $action,
          'id' => $address['address_id'],
        ], $options));

        $link = $link->toRenderable();
        $links[$action] = [
          '#type' => 'container',
          '#attributes' => [
            'class' => ["customer-address__{$action}-button"],
          ],
          'link' => $link,
        ];
      }

      $build[] = [
        '#theme' => 'user_address',
        '#address' => $address,
        '#links' => $links,
      ];
    }

    return $build;
  }
public function buildSummary(array $addresses = [], $show_add = TRUE) {
    $build = [];

    // Display an "Add Address" button.
    if ($show_add) {
      $build['add_address'] = [
        '#type' => 'acm_composite',
        '#field_type' => 'acm_address',
        '#default_value' => empty($addresses) ? $this->t('You have no saved addresses.') : '',
        '#form_mode' => FALSE,
        '#buttons' => [
          'add' => [
            '#type' => 'link',
            '#title' => $this->t('Add address'),
            '#url' => Url::fromRoute('acm_customer.view_page', [
              'page' => $this->getPageId(),
              'action' => 'add',
            ]),
            '#attributes' => [
              'class' => [
                'form-item__add-button',
              ],
            ],
          ],
        ],
      ];
    }

    // Build the summary for each user address.
    foreach ($addresses as $address) {
      if ($address['default_billing'] && $address['default_shipping']) {
        $address['heading'] = $this->t('Default Billing and Shipping Address');
      }
      elseif ($address['default_billing']) {
        $address['heading'] = $this->t('Default Billing Address');
      }
      elseif ($address['default_shipping']) {
        $address['heading'] = $this->t('Default Shipping Address');
      }
      else {
        $address['heading'] = '';
      }

      // Build a link for each action.
      $actions = [
        'edit' => [
          'label' => t('Edit'),
        ],
        'delete' => [
          'label' => t('Delete'),
          'options' => [
            'attributes' => [
              'class' => ['bypass-js'],
            ],
          ],
        ],
      ];

      $links = [];

      foreach ($actions as $action => $config) {
        $options = isset($config['options']) ? $config['options'] : [];
        $label = isset($config['label']) ? $config['label'] : $action;
        $link = Link::fromTextAndUrl($label, Url::fromRoute('acm_customer.view_page', [
          'page' => $this->getPageId(),
          'action' => $action,
          'id' => $address['address_id'],
        ], $options));

        $link = $link->toRenderable();
        $links[$action] = [
          '#type' => 'container',
          '#attributes' => [
            'class' => ["customer-address__{$action}-button"],
          ],
          'link' => $link,
        ];
      }

      $build[] = [
        '#theme' => 'user_address',
        '#address' => $address,
        '#links' => $links,
      ];
    }

    return $build;
  }
public function buildSummary ( array $ addresses = [ ] , $ show_add = TRUE ) { $ build = [ ] ; // Display an "Add Address" button. if ( $ show_add ) { $ build [ 'add_address' ] = [ '#type' => 'acm_composite' , '#field_type' => 'acm_address' , '#default_value' => empty ( $ addresses ) ? $ this -> t ( 'You have no saved addresses.' ) : '' , '#form_mode' => FALSE , '#buttons' => [ 'add' => [ '#type' => 'link' , '#title' => $ this -> t ( 'Add address' ) , '#url' => Url :: fromRoute ( 'acm_customer.view_page' , [ 'page' => $ this -> getPageId ( ) , 'action' => 'add' , ] ) , '#attributes' => [ 'class' => [ 'form-item__add-button' , ] , ] , ] , ] , ] ; } // Build the summary for each user address. foreach ( $ addresses as $ address ) { if ( $ address [ 'default_billing' ] && $ address [ 'default_shipping' ] ) { $ address [ 'heading' ] = $ this -> t ( 'Default Billing and Shipping Address' ) ; } elseif ( $ address [ 'default_billing' ] ) { $ address [ 'heading' ] = $ this -> t ( 'Default Billing Address' ) ; } elseif ( $ address [ 'default_shipping' ] ) { $ address [ 'heading' ] = $ this -> t ( 'Default Shipping Address' ) ; } else { $ address [ 'heading' ] = '' ; } // Build a link for each action. $ actions = [ 'edit' => [ 'label' => t ( 'Edit' ) , ] , 'delete' => [ 'label' => t ( 'Delete' ) , 'options' => [ 'attributes' => [ 'class' => [ 'bypass-js' ] , ] , ] , ] , ] ; $ links = [ ] ; foreach ( $ actions as $ action => $ config ) { $ options = isset ( $ config [ 'options' ] ) ? $ config [ 'options' ] : [ ] ; $ label = isset ( $ config [ 'label' ] ) ? $ config [ 'label' ] : $ action ; $ link = Link :: fromTextAndUrl ( $ label , Url :: fromRoute ( 'acm_customer.view_page' , [ 'page' => $ this -> getPageId ( ) , 'action' => $ action , 'id' => $ address [ 'address_id' ] , ] , $ options ) ) ; $ link = $ link -> toRenderable ( ) ; $ links [ $ action ] = [ '#type' => 'container' , '#attributes' => [ 'class' => [ "customer-address__{$action}-button" ] , ] , 'link' => $ link , ] ; } $ build [ ] = [ '#theme' => 'user_address' , '#address' => $ address , '#links' => $ links , ] ; } return $ build ; }
Builds a summary of addresses.

@param array $addresses
The addresses to build a summary for.
@param bool $show_add
TRUE to show an add address button, FALSE to not show it.

@return array
An render array.
Builds a summary of addresses .