You are here

protected function AddressBookController::buildOperations in Commerce Core 8.2

Builds the operation links for the given profile.

Parameters

\Drupal\profile\Entity\ProfileInterface $profile: The profile.

\Drupal\profile\Entity\ProfileTypeInterface $profile_type: The profile type.

Return value

array A renderable array with the operation links.

1 call to AddressBookController::buildOperations()
AddressBookController::overviewPage in modules/order/src/Controller/AddressBookController.php
Builds the overview page.

File

modules/order/src/Controller/AddressBookController.php, line 362

Class

AddressBookController
Provides the address book UI.

Namespace

Drupal\commerce_order\Controller

Code

protected function buildOperations(ProfileInterface $profile, ProfileTypeInterface $profile_type) {
  $operations = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'address-book__operations',
      ],
    ],
    '#weight' => 999,
  ];
  $operations['edit'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Edit'),
    '#url' => Url::fromRoute('commerce_order.address_book.edit_form', [
      'user' => $profile
        ->getOwnerId(),
      'profile' => $profile
        ->id(),
    ]),
    '#attributes' => [
      'class' => [
        'address-book__edit-link',
      ],
    ],
    '#access' => $profile
      ->access('update'),
  ];
  if ($profile_type
    ->allowsMultiple()) {
    $operations['delete'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Delete'),
      '#url' => Url::fromRoute('commerce_order.address_book.delete_form', [
        'user' => $profile
          ->getOwnerId(),
        'profile' => $profile
          ->id(),
      ]),
      '#attributes' => [
        'class' => [
          'address-book__delete-link',
        ],
      ],
      '#access' => $profile
        ->access('delete'),
    ];
    $operations['set_default'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Set as default'),
      '#url' => Url::fromRoute('commerce_order.address_book.set_default', [
        'user' => $profile
          ->getOwnerId(),
        'profile' => $profile
          ->id(),
      ]),
      '#attributes' => [
        'class' => [
          'address-book__set-default-link',
        ],
      ],
      '#access' => $profile
        ->access('update') && !$profile
        ->isDefault(),
    ];
  }
  return $operations;
}