You are here

function commerce_backoffice_product_variation_types_overview in Commerce Backoffice 7

Menu callback: display an overview of available types.

1 string reference to 'commerce_backoffice_product_variation_types_overview'
commerce_backoffice_product_menu in ./commerce_backoffice_product.module
Implements hook_menu().

File

includes/commerce_backoffice_product.product_variation_types.inc, line 14
Product variation specific copy of commerce_product_ui/includes/commerce_product_ui.types.inc and commerce_product_ui/includes/commerce_product_ui.forms.inc.

Code

function commerce_backoffice_product_variation_types_overview() {
  drupal_add_css(drupal_get_path('module', 'commerce_product') . '/theme/commerce_product.admin.css');
  $header = array(
    t('Name'),
    t('Operations'),
  );
  $rows = array();

  // Loop through all defined product variation types.
  foreach (commerce_product_types() as $type => $product_type) {

    // Build the operation links for the current product variation type.
    $links = menu_contextual_links('commerce-product-type', 'admin/commerce/config/product-variation-types', array(
      strtr($type, array(
        '_' => '-',
      )),
    ));
    $description = check_plain($product_type['name']);
    $description .= ' <small>' . t('(Machine name: @type)', array(
      '@type' => $product_type['type'],
    )) . '</small>';

    // Add the product variation type's row to the table's rows array.
    $rows[] = array(
      $description,
      theme('links', array(
        'links' => $links,
        'attributes' => array(
          'class' => 'links inline operations',
        ),
      )),
    );
  }

  // If no product variation types are defined...
  if (empty($rows)) {

    // Add a standard empty row with a link to add a new product variation type.
    $rows[] = array(
      array(
        'data' => t('There are no product variation types yet. <a href="@link">Add product variation type</a>.', array(
          '@link' => url('admin/commerce/config/product-variation-types/add'),
        )),
        'colspan' => 2,
      ),
    );
  }
  $build = array();
  $args = array(
    '!display_type' => l(t('product display type'), 'admin/structure/types'),
  );
  $build['help'] = array(
    '#markup' => '<p>' . t('Each product display must have one or more product variations,
                            which is why each !display_type has a matching product variation type.', $args) . '</p>' . '<p>' . t('Different product variation types have different fields, used for
                            storing images, attributes such as color and size, as well as any other information.') . '</p>',
  );
  $build['type_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  return $build;
}