You are here

public function ProductController::classOverview in Ubercart 8.4

Displays a list of product classes.

1 string reference to 'ProductController::classOverview'
uc_product.routing.yml in uc_product/uc_product.routing.yml
uc_product/uc_product.routing.yml

File

uc_product/src/Controller/ProductController.php, line 16

Class

ProductController
Controller routines for product routes.

Namespace

Drupal\uc_product\Controller

Code

public function classOverview() {

  /** @var \Drupal\node\NodeTypeInterface[] $classes */
  $classes = $this
    ->entityTypeManager()
    ->getStorage('node_type')
    ->loadByProperties([
    'third_party_settings.uc_product.product' => TRUE,
  ]);
  $header = [
    $this
      ->t('Class ID'),
    $this
      ->t('Name'),
    $this
      ->t('Description'),
    $this
      ->t('Operations'),
  ];
  $rows = [];
  foreach ($classes as $class) {
    $links = [];
    $links['edit'] = [
      'title' => $this
        ->t('Edit'),
      'url' => Url::fromRoute('entity.node_type.edit_form', [
        'node_type' => $class
          ->id(),
      ]),
      'query' => [
        'destination' => 'admin/store/products/classes',
      ],
    ];
    if (!$class
      ->isLocked()) {
      $links['delete'] = [
        'title' => $this
          ->t('Delete'),
        'url' => Url::fromRoute('entity.node_type.delete_form', [
          'node_type' => $class
            ->id(),
        ]),
        'query' => [
          'destination' => 'admin/store/products/classes',
        ],
      ];
    }
    $rows[] = [
      $class
        ->id(),
      $class
        ->label(),
      [
        'data' => [
          '#markup' => $class
            ->getDescription(),
        ],
      ],
      [
        'data' => [
          '#type' => 'operations',
          '#links' => $links,
        ],
      ],
    ];
  }
  return [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No product classes have been defined yet.'),
  ];
}