You are here

public function CatalogAdminController::orphans in Ubercart 8.4

Displays links to all products that have not been categorized.

Return value

array Renderable form array.

1 string reference to 'CatalogAdminController::orphans'
uc_catalog.routing.yml in uc_catalog/uc_catalog.routing.yml
uc_catalog/uc_catalog.routing.yml

File

uc_catalog/src/Controller/CatalogAdminController.php, line 34

Class

CatalogAdminController
Convenience methods for catalog administration.

Namespace

Drupal\uc_catalog\Controller

Code

public function orphans() {
  $build = [];
  if ($this
    ->config('taxonomy.settings')
    ->get('maintain_index_table')) {
    $vid = $this
      ->config('uc_catalog.settings')
      ->get('vocabulary');
    $product_types = uc_product_types();
    $field = FieldStorageConfig::loadByName('node', 'taxonomy_catalog');

    // @todo - figure this out.
    // $field is a config object, not an array, so this doesn't work.
    // $types = array_intersect($product_types, $field['bundles']['node']);
    $types = $product_types;

    // Temporary, to get this to work at all.
    $result = \Drupal::database()
      ->query('SELECT DISTINCT n.nid, n.title FROM {node_field_data} n LEFT JOIN (SELECT ti.nid, td.vid FROM {taxonomy_index} ti LEFT JOIN {taxonomy_term_data} td ON ti.tid = td.tid WHERE td.vid = :vid) txnome ON n.nid = txnome.nid WHERE n.type IN (:types[]) AND txnome.vid IS NULL', [
      ':vid' => $vid,
      ':types[]' => $types,
    ]);
    $rows = [];
    while ($node = $result
      ->fetchObject()) {
      $rows[] = Link::createFromRoute($node->title, 'entity.node.edit_form', [
        'node' => $node->nid,
      ], [
        'query' => [
          'destination' => 'admin/store/products/orphans',
        ],
      ])
        ->toString();
    }
    if (count($rows) > 0) {
      $build['orphans'] = [
        '#theme' => 'item_list',
        '#items' => $rows,
      ];
    }
    else {
      $build['orphans'] = [
        '#markup' => $this
          ->t('All products are currently listed in the catalog.'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      ];
    }
  }
  else {
    $build['orphans'] = [
      '#markup' => $this
        ->t('The node terms index is not being maintained, so Ubercart can not determine which products are not entered into the catalog.'),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    ];
  }
  return $build;
}