/** * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { /** @var \Drupal\commerce_product\Entity\ProductTypeInterface $product_type */ $product_type = ProductType::load($entity->bundle()); $row['title']['data'] = ['#type' => 'link', '#title' => $entity->label()] + $entity->toUrl()->toRenderArray(); $row['type'] = $product_type->label(); $row['status'] = $entity->isPublished() ? $this->t('Published') : $this->t('Unpublished'); return $row + parent::buildRow($entity); }
/** * Tests deleting a product type via a form. */ public function testProductTypeDeletion() { $variation_type = $this->createEntity('commerce_product_variation_type', ['id' => 'foo', 'label' => 'foo']); $product_type = $this->createEntity('commerce_product_type', ['id' => 'foo', 'label' => 'foo', 'variationType' => $variation_type->id()]); commerce_product_add_stores_field($product_type); commerce_product_add_variations_field($product_type); $product = $this->createEntity('commerce_product', ['type' => $product_type->id(), 'title' => $this->randomMachineName()]); // @todo Make sure $product_type->delete() also does nothing if there's // a product of that type. Right now the check is done on the form level. $this->drupalGet('admin/commerce/config/product-types/' . $product_type->id() . '/delete'); $this->assertRaw(t('%type is used by 1 product on your site. You can not remove this product type until you have removed all of the %type products.', ['%type' => $product_type->label()]), 'The product type will not be deleted until all products of that type are deleted.'); $this->assertNoText(t('This action cannot be undone.'), 'The product type deletion confirmation form is not available'); $product->delete(); $this->drupalGet('admin/commerce/config/product-types/' . $product_type->id() . '/delete'); $this->assertRaw(t('Are you sure you want to delete the product type %type?', ['%type' => $product_type->label()]), 'The product type is available for deletion'); $this->assertText(t('This action cannot be undone.'), 'The product type deletion confirmation form is available'); $this->drupalPostForm(NULL, NULL, t('Delete')); $exists = (bool) ProductType::load($product_type->id()); $this->assertFalse($exists, 'The new product type has been deleted from the database.'); }