Like for the node entity it would be great to have a field to edit the name/label of the product title field.

CommentFileSizeAuthor
#3 product2.jpg647.45 KBklagler
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

klagler created an issue. See original summary.

vasike’s picture

Title: Allow to change label/name of product title field » Allow to change label/name of product variation title field
Component: User experience » Documentation
Category: Feature request » Support request
Status: Active » Needs review

1. @klagler : i think you meant Variations and not Products
2. This is already there, but you need to change a setting about this.
Generate variation titles based on attribute values.
for ex. on default type : admin/commerce/config/product-variation-types/default/edit
3. Maybe this needs to be documented : http://docs.drupalcommerce.org/v2/product/products.html

klagler’s picture

FileSize
647.45 KB

No, I mean only the label for the title field. For example to have it say "Product name" instead of title.

I know this is just a very minor issue, this label could also be altered programmatically, and there are more important things to do to get commerce ready but I think this would be good to have in a final version of commerce.

vasike’s picture

Title: Allow to change label/name of product variation title field » Allow to change label/name of product title field
Category: Support request » Feature request

got it. "retitled back"

There is a new PR about this.
https://github.com/drupalcommerce/commerce/pull/656
It seems there is also description defined for the product Title base field.
So i also included the description for this setting.
Product Type Test updated.

bojanz’s picture

Title: Allow to change label/name of product title field » Document changing the label of the product title field
Category: Feature request » Task
Status: Needs review » Active

I don't see a need to pollute the UI with a setting that won't be used by most sites.
Such settings are better served by code based alters, in this case hook_entity_base_field_info_alter().

We should add an entry to our Recipes section of the docs with an example:

use Drupal\Core\Entity\EntityTypeInterface;

/**
 * Implements hook_entity_base_field_info_alter().
 */
function mymodule_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
  if ($entity_type->id() == 'commerce_product') {
    // Change the title field label.
    $fields['title']->setLabel(t('Product name'));
  }
}
shabana.navas’s picture

Status: Active » Needs review

Added documentation to recipes section and created PR: https://github.com/drupalcommerce/commerce-docs/pull/73.

mglaman’s picture

Status: Needs review » Fixed

Merged into docs, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jeffam’s picture

hook_entity_base_field_info_alter() as mentioned in #5 didn't work for me, although I have my hooks in a custom install profiles `.profile` rather than a custom module.

What did work, in case this helps anyone else, was the following, adapted from https://drupal.stackexchange.com/a/253282

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\Entity\BaseFieldOverride;

/**
 * Implements hook_entity_bundle_field_info().
 */
function mymodule_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
  $fields = [];

  // Change the title field label.
  if ($entity_type->id() == 'commerce_product' && $bundle == 'default' && !empty($base_field_definitions['title'])) {
    // Create a base field override with custom title.
    $field = BaseFieldOverride::createFromBaseFieldDefinition($base_field_definitions['title'], $bundle);
    $field->setLabel(t('Product name'));

    $fields['title'] = $field;
  }

  return $fields;
}