22
33namespace Drupal \commerce_product \Entity ;
44
5- use Drupal \user \ UserInterface ;
5+ use Drupal \Core \ Entity \ EntityPublishedTrait ;
66use Drupal \Core \Entity \ContentEntityBase ;
77use Drupal \Core \Entity \EntityChangedTrait ;
88use Drupal \Core \Entity \EntityStorageInterface ;
99use Drupal \Core \Entity \EntityTypeInterface ;
1010use Drupal \Core \Field \BaseFieldDefinition ;
11+ use Drupal \user \UserInterface ;
1112
1213/**
1314 * Defines the product entity class.
5556 * "label" = "title",
5657 * "langcode" = "langcode",
5758 * "uuid" = "uuid",
58- * "status " = "status",
59+ * "published " = "status",
5960 * },
6061 * links = {
6162 * "canonical" = "/product/{commerce_product}",
7374class Product extends ContentEntityBase implements ProductInterface {
7475
7576 use EntityChangedTrait;
77+ use EntityPublishedTrait;
7678
7779 /**
7880 * {@inheritdoc}
@@ -89,21 +91,6 @@ public function setTitle($title) {
8991 return $ this ;
9092 }
9193
92- /**
93- * {@inheritdoc}
94- */
95- public function isPublished () {
96- return (bool ) $ this ->getEntityKey ('status ' );
97- }
98-
99- /**
100- * {@inheritdoc}
101- */
102- public function setPublished ($ published ) {
103- $ this ->set ('status ' , (bool ) $ published );
104- return $ this ;
105- }
106-
10794 /**
10895 * {@inheritdoc}
10996 */
@@ -347,6 +334,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
347334 */
348335 public static function baseFieldDefinitions (EntityTypeInterface $ entity_type ) {
349336 $ fields = parent ::baseFieldDefinitions ($ entity_type );
337+ $ fields += static ::publishedBaseFieldDefinitions ($ entity_type );
350338
351339 $ fields ['uid ' ] = BaseFieldDefinition::create ('entity_reference ' )
352340 ->setLabel (t ('Author ' ))
@@ -393,11 +381,14 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
393381 ->setDisplayConfigurable ('form ' , TRUE )
394382 ->setComputed (TRUE );
395383
396- $ fields ['status ' ] = BaseFieldDefinition::create ('boolean ' )
397- ->setLabel (t ('Published ' ))
398- ->setDescription (t ('Whether the product is published. ' ))
399- ->setDefaultValue (TRUE )
400- ->setTranslatable (TRUE )
384+ $ fields ['status ' ]
385+ ->setDisplayOptions ('form ' , [
386+ 'type ' => 'boolean_checkbox ' ,
387+ 'settings ' => [
388+ 'display_label ' => TRUE ,
389+ ],
390+ 'weight ' => 90 ,
391+ ])
401392 ->setDisplayConfigurable ('form ' , TRUE );
402393
403394 $ fields ['created ' ] = BaseFieldDefinition::create ('created ' )
0 commit comments