You are here

public function ProductFeaturesController::featuresOverview in Ubercart 8.4

Displays the product features tab on a product node edit form.

1 string reference to 'ProductFeaturesController::featuresOverview'
uc_product.routing.yml in uc_product/uc_product.routing.yml
uc_product/uc_product.routing.yml

File

uc_product/src/Controller/ProductFeaturesController.php, line 18

Class

ProductFeaturesController
Controller routines for product feature routes.

Namespace

Drupal\uc_product\Controller

Code

public function featuresOverview(NodeInterface $node) {
  $header = [
    $this
      ->t('Type'),
    $this
      ->t('Description'),
    $this
      ->t('Operations'),
  ];
  $rows = [];
  $features = uc_product_feature_load_multiple($node
    ->id());
  foreach ($features as $feature) {
    $operations = [
      'edit' => [
        'title' => $this
          ->t('Edit'),
        'url' => Url::fromRoute('uc_product.feature_edit', [
          'node' => $node
            ->id(),
          'fid' => $feature->fid,
          'pfid' => $feature->pfid,
        ]),
      ],
      'delete' => [
        'title' => $this
          ->t('Delete'),
        'url' => Url::fromRoute('uc_product.feature_delete', [
          'node' => $node
            ->id(),
          'fid' => $feature->fid,
          'pfid' => $feature->pfid,
        ]),
      ],
    ];
    $rows[] = [
      [
        'data' => uc_product_feature_data($feature->fid, 'title'),
      ],
      [
        'data' => [
          '#markup' => $feature->description,
        ],
      ],
      [
        'data' => [
          '#type' => 'operations',
          '#links' => $operations,
        ],
      ],
    ];
  }
  $build['features'] = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => [
      'class' => [
        'uc-product-features',
      ],
    ],
    '#empty' => $this
      ->t('No features found for this product.'),
  ];
  $build['add_form'] = $this
    ->formBuilder()
    ->getForm('Drupal\\uc_product\\Form\\ProductFeatureAddForm', $node);
  return $build;
}